xmake.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package("python2")
  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")
  8. add_versions("2.7.15", "b9d8157fe2ca58f84d29a814bedf1d304d2277ad02f0930acd22e2ce7367b77e")
  9. else
  10. add_urls("https://gitlab.com/xmake-mirror/python-releases/raw/master/python-$(version).win32.zip")
  11. add_versions("2.7.15", "f34e2555c4fde5d7d746e6a0bbfc9151435f3f5c3eaddfc046ec0993b7cc9660")
  12. end
  13. else
  14. set_urls("https://www.python.org/ftp/python/$(version)/Python-$(version).tgz")
  15. add_versions("2.7.15", "18617d1f15a380a919d517630a9cd85ce17ea602f9bbdc58ddc672df4b0239db")
  16. end
  17. if is_host("macosx", "linux") then
  18. add_deps("openssl")
  19. end
  20. on_load(function (package)
  21. if is_host("windows") then
  22. package:addenv("PATH", path.join("share", package:name(), package:version_str()))
  23. else
  24. package:addenv("PATH", path.join("share", package:name(), package:version_str(), "bin"))
  25. end
  26. end)
  27. on_install("@windows", function (package)
  28. local installdir = package:installdir("share", package:name(), package:version_str())
  29. os.cp("*", installdir)
  30. os.cp("python.exe", path.join(installdir, "python2.exe"))
  31. end)
  32. on_install("@macosx", "@linux", function (package)
  33. -- init configs
  34. local configs = {"--enable-ipv6", "--without-ensurepip"}
  35. table.insert(configs, "--datadir=" .. package:installdir("share"))
  36. table.insert(configs, "--datarootdir=" .. package:installdir("share"))
  37. -- add openssl libs path for detecting
  38. io.gsub("setup.py", "/usr/local/ssl", package:dep("openssl"):installdir())
  39. -- allow python modules to use ctypes.find_library to find xmake's stuff
  40. if is_host("macosx") then
  41. io.gsub("Lib/ctypes/macholib/dyld.py", "DEFAULT_LIBRARY_FALLBACK = [", format("DEFAULT_LIBRARY_FALLBACK = [ '%s/lib',", package:installdir()))
  42. end
  43. -- unset these so that installing pip and setuptools puts them where we want
  44. -- and not into some other Python the user has installed.
  45. import("package.tools.autoconf").configure(package, configs, {envs = {PYTHONHOME = "", PYTHONPATH = ""}})
  46. os.vrunv("make", {"install", "-j4", "PYTHONAPPSDIR=" .. package:installdir()})
  47. -- install resources
  48. local resources =
  49. {
  50. setuptools =
  51. {
  52. url = "https://files.pythonhosted.org/packages/c2/f7/c7b501b783e5a74cf1768bc174ee4fb0a8a6ee5af6afa92274ff964703e0/setuptools-40.8.0.zip",
  53. sha256 = "6e4eec90337e849ade7103723b9a99631c1f0d19990d6e8412dc42f5ae8b304d"
  54. },
  55. pip =
  56. {
  57. url = "https://files.pythonhosted.org/packages/36/fa/51ca4d57392e2f69397cd6e5af23da2a8d37884a605f9e3f2d3bfdc48397/pip-19.0.3.tar.gz",
  58. sha256 = "6e6f197a1abfb45118dbb878b5c859a0edbdd33fd250100bc015b67fded4b9f2"
  59. },
  60. wheel =
  61. {
  62. url = "https://files.pythonhosted.org/packages/b7/cf/1ea0f5b3ce55cacde1e84cdde6cee1ebaff51bd9a3e6c7ba4082199af6f6/wheel-0.33.1.tar.gz",
  63. sha256 = "66a8fd76f28977bb664b098372daef2b27f60dc4d1688cfab7b37a09448f0e9d"
  64. }
  65. }
  66. import("net.http")
  67. import("utils.archive")
  68. for name, resource in pairs(resources) do
  69. local resourcefile = path.join(package:cachedir(), path.filename(resource.url))
  70. local resourcedir = resourcefile .. ".dir"
  71. http.download(resource.url, resourcefile)
  72. assert(resource.sha256 == hash.sha256(resourcefile), "resource(%s): unmatched checksum!", name)
  73. assert(archive.extract(resourcefile, resourcedir), "resource(%s): extract failed!", name)
  74. os.cd(resourcedir)
  75. os.vrun("python2 setup.py install")
  76. os.cd("-")
  77. end
  78. end)
  79. on_test(function (package)
  80. os.vrun("python2 --version")
  81. end)