xmake.lua 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package("python")
  2. set_kind("binary")
  3. set_homepage("https://www.python.org/")
  4. set_description("The python programming language.")
  5. if is_host("windows") then
  6. if os.arch() == "x64" then
  7. add_urls("https://gitlab.com/xmake-mirror/python-releases/raw/master/python-$(version).amd64.zip", {alias = "py2"})
  8. add_versions("py2:2.7.15", "b9d8157fe2ca58f84d29a814bedf1d304d2277ad02f0930acd22e2ce7367b77e")
  9. else
  10. add_urls("https://gitlab.com/xmake-mirror/python-releases/raw/master/python-$(version).win32.zip", {alias = "py2"})
  11. add_versions("py2:2.7.15", "f34e2555c4fde5d7d746e6a0bbfc9151435f3f5c3eaddfc046ec0993b7cc9660")
  12. end
  13. if winos.version():gt("winxp") then
  14. if os.arch() == "x64" then
  15. add_urls("https://www.python.org/ftp/python/$(version)/python-$(version)-embed-amd64.zip", {alias = "py3"})
  16. add_versions("py3:3.7.0", "0cc08f3c74c0112abc2adafd16a534cde12fe7c7aafb42e936d59fd3ab08fcdb")
  17. else
  18. add_urls("https://www.python.org/ftp/python/$(version)/python-$(version)-embed-win32.zip", {alias = "py3"})
  19. add_versions("py3:3.7.0", "9596b23a8db1f945c2e26fe0dc1743e33f3700b4b708c68ea202cf2ac761a736")
  20. end
  21. else
  22. if os.arch() == "x64" then
  23. add_urls("https://gitlab.com/xmake-mirror/python-releases/raw/master/python-$(version).amd64.zip", {alias = "py3"})
  24. add_versions("py3:3.3.4", "a83bf90b28f8b44b99c3524a34ab18f21a59999e07c107da19b031869fb42af1")
  25. else
  26. add_urls("https://gitlab.com/xmake-mirror/python-releases/raw/master/python-$(version).win32.zip", {alias = "py3"})
  27. add_versions("py3:3.3.4", "c9843d585e30da1c7c85663543b2f6a1f68621e02d288abc5b5e54361d93ccd6")
  28. end
  29. end
  30. else
  31. set_urls("https://www.python.org/ftp/python/$(version)/Python-$(version).tgz",
  32. "https://github.com/xmake-mirror/cpython/releases/download/v$(version)/Python-$(version).tgz")
  33. add_versions("2.7.15", "18617d1f15a380a919d517630a9cd85ce17ea602f9bbdc58ddc672df4b0239db")
  34. add_versions("3.7.0", "85bb9feb6863e04fb1700b018d9d42d1caac178559ffa453d7e6a436e259fd0d")
  35. end
  36. if is_host("macosx", "linux") then
  37. add_deps("openssl", {host = true})
  38. end
  39. on_load(function (package)
  40. package:data_set("install_resources", function()
  41. -- imports
  42. import("net.http")
  43. import("utils.archive")
  44. import("lib.detect.find_file")
  45. -- set python environments
  46. local version = package:version()
  47. local envs = {PYTHONPATH = package:installdir("lib", "python" .. version:major() .. "." .. version:minor(), "site-packages")}
  48. package:addenv("PYTHONPATH", envs.PYTHONPATH)
  49. -- install resources
  50. local resources =
  51. {
  52. setuptools =
  53. {
  54. url = "https://files.pythonhosted.org/packages/c2/f7/c7b501b783e5a74cf1768bc174ee4fb0a8a6ee5af6afa92274ff964703e0/setuptools-40.8.0.zip",
  55. sha256 = "6e4eec90337e849ade7103723b9a99631c1f0d19990d6e8412dc42f5ae8b304d"
  56. },
  57. pip =
  58. {
  59. url = "https://files.pythonhosted.org/packages/36/fa/51ca4d57392e2f69397cd6e5af23da2a8d37884a605f9e3f2d3bfdc48397/pip-19.0.3.tar.gz",
  60. sha256 = "6e6f197a1abfb45118dbb878b5c859a0edbdd33fd250100bc015b67fded4b9f2"
  61. },
  62. wheel =
  63. {
  64. url = "https://files.pythonhosted.org/packages/b7/cf/1ea0f5b3ce55cacde1e84cdde6cee1ebaff51bd9a3e6c7ba4082199af6f6/wheel-0.33.1.tar.gz",
  65. sha256 = "66a8fd76f28977bb664b098372daef2b27f60dc4d1688cfab7b37a09448f0e9d"
  66. }
  67. }
  68. local python = path.join(package:installdir("bin"), "python" .. (is_host("windows") and ".exe" or ""))
  69. for name, resource in pairs(resources) do
  70. local resourcefile = path.join(os.curdir(), path.filename(resource.url))
  71. local resourcedir = resourcefile .. ".dir"
  72. http.download(resource.url, resourcefile)
  73. assert(resource.sha256 == hash.sha256(resourcefile), "resource(%s): unmatched checksum!", name)
  74. assert(archive.extract(resourcefile, resourcedir), "resource(%s): extract failed!", name)
  75. local setupfile = assert(find_file("setup.py", path.join(resourcedir, "*")), "resource(%s): setup.py not found!", name)
  76. local oldir = os.cd(path.directory(setupfile))
  77. os.vrunv(python, {"setup.py", "install", "--prefix=" .. package:installdir()}, {envs = envs})
  78. os.cd(oldir)
  79. end
  80. end)
  81. end)
  82. on_install("@windows", function (package)
  83. if package:version():ge("3.0") then
  84. os.cp("python.exe", path.join(package:installdir("bin"), "python3.exe"))
  85. else
  86. os.cp("python.exe", path.join(package:installdir("bin"), "python2.exe"))
  87. end
  88. os.mv("*.exe", package:installdir("bin"))
  89. os.mv("*.dll", package:installdir("bin"))
  90. os.cp("*", package:installdir())
  91. package:data("install_resources")()
  92. end)
  93. on_install("@macosx", "@linux", function (package)
  94. -- init configs
  95. local configs = {"--enable-ipv6", "--without-ensurepip"}
  96. table.insert(configs, "--datadir=" .. package:installdir("share"))
  97. table.insert(configs, "--datarootdir=" .. package:installdir("share"))
  98. -- add openssl libs path for detecting
  99. local openssl_dir = package:dep("openssl"):installdir()
  100. if package:version():ge("3.0") then
  101. table.insert(configs, "--with-openssl=" .. openssl_dir)
  102. else
  103. io.gsub("setup.py", "/usr/local/ssl", openssl_dir)
  104. end
  105. -- allow python modules to use ctypes.find_library to find xmake's stuff
  106. if is_host("macosx") then
  107. io.gsub("Lib/ctypes/macholib/dyld.py", "DEFAULT_LIBRARY_FALLBACK = %[", format("DEFAULT_LIBRARY_FALLBACK = [ '%s/lib',", package:installdir()))
  108. end
  109. -- unset these so that installing pip and setuptools puts them where we want
  110. -- and not into some other Python the user has installed.
  111. import("package.tools.autoconf").configure(package, configs, {envs = {PYTHONHOME = "", PYTHONPATH = ""}})
  112. os.vrunv("make", {"install", "-j4", "PYTHONAPPSDIR=" .. package:installdir()})
  113. if package:version():ge("3.0") then
  114. os.cp(path.join(package:installdir("bin"), "python3"), path.join(package:installdir("bin"), "python"))
  115. os.cp(path.join(package:installdir("bin"), "python3-config"), path.join(package:installdir("bin"), "python-config"))
  116. end
  117. package:data("install_resources")()
  118. end)
  119. on_test(function (package)
  120. os.vrun("python --version")
  121. os.vrun("python -c \"import pip\"")
  122. os.vrun("python -c \"import setuptools\"")
  123. os.vrun("python -c \"import wheel\"")
  124. end)