2015-02-11 12:53:05 +01:00
|
|
|
from toolchain import Recipe, shprint, ensure_dir
|
|
|
|
from os.path import join, exists
|
|
|
|
import os
|
2015-02-03 00:19:53 +01:00
|
|
|
import sh
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
|
2018-11-02 11:44:25 +01:00
|
|
|
class Hostpython2Recipe(Recipe):
|
2015-02-03 00:19:53 +01:00
|
|
|
version = "2.7.1"
|
|
|
|
url = "https://www.python.org/ftp/python/{version}/Python-{version}.tar.bz2"
|
2016-10-14 10:31:18 +02:00
|
|
|
depends = ["hostlibffi"]
|
|
|
|
optional_depends = ["openssl"]
|
2015-10-27 18:29:22 +01:00
|
|
|
archs = ["x86_64"]
|
2015-02-03 00:19:53 +01:00
|
|
|
|
2015-02-11 12:53:05 +01:00
|
|
|
def init_with_ctx(self, ctx):
|
2018-11-02 11:44:25 +01:00
|
|
|
super(Hostpython2Recipe, self).init_with_ctx(ctx)
|
2019-01-12 19:28:52 +01:00
|
|
|
self.set_hostpython(self, "2.7")
|
2018-11-02 11:44:25 +01:00
|
|
|
self.ctx.so_suffix = ".so"
|
2018-12-18 04:35:42 +01:00
|
|
|
self.ctx.hostpython = join(self.ctx.dist_dir, "hostpython2", "bin", "python")
|
|
|
|
self.ctx.hostpgen = join(self.ctx.dist_dir, "hostpython2", "bin", "pgen")
|
2015-02-03 00:19:53 +01:00
|
|
|
print("Global: hostpython located at {}".format(self.ctx.hostpython))
|
|
|
|
print("Global: hostpgen located at {}".format(self.ctx.hostpgen))
|
|
|
|
|
|
|
|
def prebuild_arch(self, arch):
|
2016-10-14 10:31:18 +02:00
|
|
|
if self.has_marker("patched"):
|
2015-02-03 00:19:53 +01:00
|
|
|
return
|
2015-02-25 12:53:26 +01:00
|
|
|
self.copy_file("_scproxy.py", "Lib/_scproxy.py")
|
2015-02-03 00:19:53 +01:00
|
|
|
self.apply_patch("ssize-t-max.patch")
|
|
|
|
self.apply_patch("dynload.patch")
|
|
|
|
self.apply_patch("static-_sqlite3.patch")
|
|
|
|
self.copy_file("ModulesSetup", "Modules/Setup.local")
|
2016-10-14 10:31:18 +02:00
|
|
|
if "openssl.build_all" in self.ctx.state:
|
|
|
|
self.append_file("ModulesSetup.openssl", "Modules/Setup.local")
|
2015-02-03 00:19:53 +01:00
|
|
|
self.set_marker("patched")
|
|
|
|
|
2015-02-09 11:58:01 +01:00
|
|
|
def postbuild_arch(self, arch):
|
|
|
|
makefile_fn = join(self.build_dir, "Makefile")
|
|
|
|
with open(makefile_fn) as fd:
|
|
|
|
lines = fd.readlines()
|
|
|
|
for index, line in enumerate(lines):
|
|
|
|
if "-bundle" not in line:
|
|
|
|
continue
|
|
|
|
parts = line.split(" ")
|
|
|
|
parts.remove("-bundle")
|
|
|
|
if "-bundle_loader" in parts:
|
|
|
|
i = parts.index("-bundle_loader")
|
|
|
|
parts.pop(i)
|
|
|
|
parts.pop(i)
|
|
|
|
lines[index] = " ".join(parts)
|
|
|
|
with open(makefile_fn, "w") as fd:
|
|
|
|
fd.writelines(lines)
|
|
|
|
|
2015-10-27 18:29:22 +01:00
|
|
|
def build_x86_64(self):
|
2015-02-03 00:19:53 +01:00
|
|
|
sdk_path = sh.xcrun("--sdk", "macosx", "--show-sdk-path").strip()
|
|
|
|
build_env = self.ctx.env.copy()
|
2016-04-17 06:08:58 +02:00
|
|
|
ccache = (build_env["CCACHE"] + ' ') if 'CCACHE' in build_env else ''
|
|
|
|
build_env["CC"] = ccache + "clang -Qunused-arguments -fcolor-diagnostics"
|
2015-02-23 22:30:50 +01:00
|
|
|
build_env["LDFLAGS"] = " ".join([
|
2015-11-01 21:27:21 +01:00
|
|
|
"-lsqlite3",
|
|
|
|
"-lffi",
|
|
|
|
"-L{}".format(join(self.ctx.dist_dir, "hostlibffi", "usr", "local", "lib"))
|
|
|
|
])
|
2015-02-23 22:30:50 +01:00
|
|
|
build_env["CFLAGS"] = " ".join([
|
|
|
|
"--sysroot={}".format(sdk_path),
|
2017-10-09 11:28:22 +02:00
|
|
|
"-arch x86_64",
|
|
|
|
"-mmacosx-version-min=10.12",
|
2015-10-27 18:29:22 +01:00
|
|
|
"-I{}".format(join(self.ctx.dist_dir, "hostlibffi", "usr", "local", "include"))
|
2015-02-23 22:30:50 +01:00
|
|
|
])
|
2016-10-14 10:31:18 +02:00
|
|
|
|
|
|
|
if "openssl.build_all" in self.ctx.state:
|
2018-10-28 13:18:54 +01:00
|
|
|
build_env["LDFLAGS"] += " -L{}".format(join(self.ctx.dist_dir, "lib"))
|
2016-10-14 10:31:18 +02:00
|
|
|
build_env["CFLAGS"] += " -I{}".format(join(self.ctx.dist_dir, "include",
|
|
|
|
"x86_64", "openssl"))
|
|
|
|
|
2015-02-03 00:19:53 +01:00
|
|
|
configure = sh.Command(join(self.build_dir, "configure"))
|
2015-02-11 12:53:05 +01:00
|
|
|
shprint(configure,
|
2018-12-18 04:35:42 +01:00
|
|
|
"--prefix={}".format(join(self.ctx.dist_dir, "hostpython2")),
|
2015-02-23 22:30:50 +01:00
|
|
|
"--disable-toolbox-glue",
|
|
|
|
"--without-gcc",
|
2015-02-11 12:53:05 +01:00
|
|
|
_env=build_env)
|
2017-05-02 08:10:11 +02:00
|
|
|
shprint(sh.make, "-C", self.build_dir, self.ctx.concurrent_make, "python", "Parser/pgen",
|
2015-02-03 00:19:53 +01:00
|
|
|
_env=build_env)
|
2018-12-18 04:35:42 +01:00
|
|
|
shutil.move("python", "hostpython2")
|
2015-02-03 00:19:53 +01:00
|
|
|
shutil.move("Parser/pgen", "Parser/hostpgen")
|
|
|
|
|
2015-02-11 12:53:05 +01:00
|
|
|
def install(self):
|
|
|
|
arch = list(self.filtered_archs)[0]
|
|
|
|
build_env = arch.get_env()
|
|
|
|
build_dir = self.get_build_dir(arch.arch)
|
|
|
|
build_env["PATH"] = os.environ["PATH"]
|
2016-07-11 21:43:44 +02:00
|
|
|
# Compiling sometimes looks for Python-ast.py in the 'Python' i.s.o.
|
|
|
|
# the 'hostpython' folder. Create a symlink to fix. See issue #201
|
2016-07-04 12:00:39 +02:00
|
|
|
shprint(sh.ln, "-s",
|
2018-12-18 04:35:42 +01:00
|
|
|
join(build_dir, "hostpython2"),
|
2016-07-04 12:00:39 +02:00
|
|
|
join(build_dir, "Python"))
|
2017-05-02 08:10:11 +02:00
|
|
|
shprint(sh.make, self.ctx.concurrent_make,
|
2015-02-11 12:53:05 +01:00
|
|
|
"-C", build_dir,
|
|
|
|
"bininstall", "inclinstall",
|
|
|
|
_env=build_env)
|
2018-12-18 04:35:42 +01:00
|
|
|
pylib_dir = join(self.ctx.dist_dir, "hostpython2", "lib", "python2.7")
|
2015-02-11 12:53:05 +01:00
|
|
|
if exists(pylib_dir):
|
|
|
|
shutil.rmtree(pylib_dir)
|
|
|
|
shutil.copytree(
|
|
|
|
join(build_dir, "Lib"),
|
|
|
|
pylib_dir)
|
|
|
|
ensure_dir(join(pylib_dir, "config"))
|
|
|
|
shutil.copy(
|
|
|
|
join(build_dir, "Makefile"),
|
|
|
|
join(pylib_dir, "config", "Makefile"))
|
|
|
|
shutil.copy(
|
|
|
|
join(build_dir, "Parser", "pgen"),
|
2018-12-18 04:35:42 +01:00
|
|
|
join(self.ctx.dist_dir, "hostpython2", "bin", "pgen"))
|
2015-02-11 12:53:05 +01:00
|
|
|
|
|
|
|
|
2018-11-02 11:44:25 +01:00
|
|
|
recipe = Hostpython2Recipe()
|