2015-02-02 05:21:44 +01:00
|
|
|
from toolchain import Recipe, shprint
|
|
|
|
from os.path import join
|
|
|
|
import sh
|
2015-02-09 23:34:02 +01:00
|
|
|
import os
|
2019-02-07 10:00:23 +01:00
|
|
|
import logging
|
2015-02-02 05:21:44 +01:00
|
|
|
|
2020-04-25 18:28:16 +02:00
|
|
|
|
2019-02-07 10:00:23 +01:00
|
|
|
logger = logging.getLogger(__name__)
|
2015-02-02 05:21:44 +01:00
|
|
|
|
2020-04-25 18:28:16 +02:00
|
|
|
|
2018-11-02 11:44:25 +01:00
|
|
|
class Python2Recipe(Recipe):
|
2015-02-02 05:21:44 +01:00
|
|
|
version = "2.7.1"
|
|
|
|
url = "https://www.python.org/ftp/python/{version}/Python-{version}.tar.bz2"
|
2018-11-02 11:44:25 +01:00
|
|
|
depends = ["hostpython2", "libffi"]
|
2015-08-14 12:18:15 +02:00
|
|
|
optional_depends = ["openssl"]
|
2015-02-03 18:42:17 +01:00
|
|
|
library = "libpython2.7.a"
|
2015-02-23 11:34:36 +01:00
|
|
|
pbx_libraries = ["libz", "libbz2", "libsqlite3"]
|
2015-02-02 05:21:44 +01:00
|
|
|
|
2015-02-25 13:37:26 +01:00
|
|
|
def init_with_ctx(self, ctx):
|
2018-11-02 11:44:25 +01:00
|
|
|
super(Python2Recipe, self).init_with_ctx(ctx)
|
2019-01-12 19:28:52 +01:00
|
|
|
self.set_python(self, "2.7")
|
2018-11-02 11:44:25 +01:00
|
|
|
ctx.python_ver_dir = "python2.7"
|
2019-01-05 00:15:08 +01:00
|
|
|
ctx.python_prefix = join(ctx.dist_dir, "root", "python2")
|
2018-11-02 11:44:25 +01:00
|
|
|
ctx.site_packages_dir = join(
|
|
|
|
ctx.python_prefix, "lib", ctx.python_ver_dir, "site-packages")
|
2015-02-25 13:37:26 +01:00
|
|
|
|
2015-02-02 05:21:44 +01:00
|
|
|
def prebuild_arch(self, arch):
|
|
|
|
# common to all archs
|
2020-04-25 18:28:16 +02:00
|
|
|
if self.has_marker("patched"):
|
2015-02-02 05:21:44 +01:00
|
|
|
return
|
|
|
|
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")
|
|
|
|
self.copy_file("_scproxy.py", "Lib/_scproxy.py")
|
2015-02-03 00:19:53 +01:00
|
|
|
self.apply_patch("xcompile.patch")
|
|
|
|
self.apply_patch("setuppath.patch")
|
|
|
|
self.append_file("ModulesSetup.mobile", "Modules/Setup.local")
|
2017-05-14 20:39:16 +02:00
|
|
|
self.apply_patch("ipv6.patch")
|
2015-08-07 19:14:44 +02:00
|
|
|
if "openssl.build_all" in self.ctx.state:
|
2020-04-25 18:28:16 +02:00
|
|
|
self.append_file("ModulesSetup.openssl", "Modules/Setup.local")
|
2017-10-09 11:28:22 +02:00
|
|
|
self.apply_patch("posixmodule.patch")
|
2015-02-02 05:21:44 +01:00
|
|
|
|
|
|
|
self.set_marker("patched")
|
|
|
|
|
|
|
|
def build_arch(self, arch):
|
2015-02-03 18:42:17 +01:00
|
|
|
build_env = arch.get_env()
|
2015-02-02 05:21:44 +01:00
|
|
|
configure = sh.Command(join(self.build_dir, "configure"))
|
|
|
|
shprint(configure,
|
|
|
|
"CC={}".format(build_env["CC"]),
|
|
|
|
"LD={}".format(build_env["LD"]),
|
|
|
|
"CFLAGS={}".format(build_env["CFLAGS"]),
|
2015-04-28 18:19:50 +02:00
|
|
|
"LDFLAGS={} -undefined dynamic_lookup".format(build_env["LDFLAGS"]),
|
2015-02-02 05:21:44 +01:00
|
|
|
"--without-pymalloc",
|
|
|
|
"--disable-toolbox-glue",
|
|
|
|
"--host={}-apple-darwin".format(arch),
|
|
|
|
"--prefix=/python",
|
2015-02-11 16:28:57 +01:00
|
|
|
"--with-system-ffi",
|
2015-02-02 05:21:44 +01:00
|
|
|
"--without-doc-strings",
|
2017-05-14 20:39:16 +02:00
|
|
|
"--enable-ipv6",
|
2015-02-02 05:21:44 +01:00
|
|
|
_env=build_env)
|
2015-02-03 18:42:17 +01:00
|
|
|
|
|
|
|
self._patch_pyconfig()
|
2015-02-02 05:21:44 +01:00
|
|
|
self.apply_patch("ctypes_duplicate.patch")
|
2015-02-11 16:28:57 +01:00
|
|
|
self.apply_patch("ctypes_duplicate_longdouble.patch")
|
2015-02-02 05:21:44 +01:00
|
|
|
|
2017-05-02 08:10:11 +02:00
|
|
|
shprint(sh.make, self.ctx.concurrent_make,
|
2015-02-02 05:21:44 +01:00
|
|
|
"CROSS_COMPILE_TARGET=yes",
|
|
|
|
"HOSTPYTHON={}".format(self.ctx.hostpython),
|
|
|
|
"HOSTPGEN={}".format(self.ctx.hostpgen))
|
|
|
|
|
2015-02-09 23:34:02 +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"]
|
2017-05-02 08:10:11 +02:00
|
|
|
shprint(sh.make, self.ctx.concurrent_make,
|
2015-02-09 23:34:02 +01:00
|
|
|
"-C", build_dir,
|
|
|
|
"install",
|
|
|
|
"CROSS_COMPILE_TARGET=yes",
|
|
|
|
"HOSTPYTHON={}".format(self.ctx.hostpython),
|
2019-01-04 21:55:57 +01:00
|
|
|
"prefix={}".format(join(self.ctx.dist_dir, "root", "python2")),
|
2015-02-09 23:34:02 +01:00
|
|
|
_env=build_env)
|
2015-02-24 00:01:32 +01:00
|
|
|
self.reduce_python()
|
2015-02-09 23:34:02 +01:00
|
|
|
|
2015-02-03 18:42:17 +01:00
|
|
|
def _patch_pyconfig(self):
|
|
|
|
# patch pyconfig to remove some functionnalities
|
|
|
|
# (to have uniform build accross all platfors)
|
|
|
|
# this was before in a patch itself, but because the different
|
|
|
|
# architecture can lead to different pyconfig.h, we would need one patch
|
|
|
|
# per arch. Instead, express here the line we don't want / we want.
|
|
|
|
pyconfig = join(self.build_dir, "pyconfig.h")
|
2020-04-25 18:28:16 +02:00
|
|
|
|
2015-02-03 18:42:17 +01:00
|
|
|
def _remove_line(lines, pattern):
|
|
|
|
for line in lines[:]:
|
|
|
|
if pattern in line:
|
|
|
|
lines.remove(line)
|
2017-04-29 17:51:42 +02:00
|
|
|
with open(pyconfig, "r") as fd:
|
2015-02-03 18:42:17 +01:00
|
|
|
lines = fd.readlines()
|
|
|
|
_remove_line(lines, "#define HAVE_BIND_TEXTDOMAIN_CODESET 1")
|
|
|
|
_remove_line(lines, "#define HAVE_FINITE 1")
|
|
|
|
_remove_line(lines, "#define HAVE_FSEEK64 1")
|
|
|
|
_remove_line(lines, "#define HAVE_FTELL64 1")
|
|
|
|
_remove_line(lines, "#define HAVE_GAMMA 1")
|
|
|
|
_remove_line(lines, "#define HAVE_GETHOSTBYNAME_R 1")
|
|
|
|
_remove_line(lines, "#define HAVE_GETHOSTBYNAME_R_6_ARG 1")
|
|
|
|
_remove_line(lines, "#define HAVE_GETRESGID 1")
|
|
|
|
_remove_line(lines, "#define HAVE_GETRESUID 1")
|
|
|
|
_remove_line(lines, "#define HAVE_GETSPENT 1")
|
|
|
|
_remove_line(lines, "#define HAVE_GETSPNAM 1")
|
|
|
|
_remove_line(lines, "#define HAVE_MREMAP 1")
|
|
|
|
_remove_line(lines, "#define HAVE_PLOCK 1")
|
|
|
|
_remove_line(lines, "#define HAVE_SEM_TIMEDWAIT 1")
|
|
|
|
_remove_line(lines, "#define HAVE_SETRESGID 1")
|
|
|
|
_remove_line(lines, "#define HAVE_SETRESUID 1")
|
|
|
|
_remove_line(lines, "#define HAVE_TMPNAM_R 1")
|
|
|
|
_remove_line(lines, "#define HAVE__GETPTY 1")
|
|
|
|
lines.append("#define HAVE_GETHOSTBYNAME 1\n")
|
2017-04-29 17:51:42 +02:00
|
|
|
with open(pyconfig, "w") as fd:
|
2015-02-03 18:42:17 +01:00
|
|
|
fd.writelines(lines)
|
|
|
|
|
2015-02-24 00:01:32 +01:00
|
|
|
def reduce_python(self):
|
2019-02-07 10:00:23 +01:00
|
|
|
logger.info("Reduce python")
|
2015-02-24 00:01:32 +01:00
|
|
|
oldpwd = os.getcwd()
|
|
|
|
try:
|
2019-02-07 10:00:23 +01:00
|
|
|
logger.info("Remove files unlikely to be used")
|
2019-01-04 21:55:57 +01:00
|
|
|
os.chdir(join(self.ctx.dist_dir, "root", "python2"))
|
2015-02-24 12:52:26 +01:00
|
|
|
sh.rm("-rf", "share")
|
|
|
|
sh.rm("-rf", "bin")
|
2019-01-04 21:55:57 +01:00
|
|
|
os.chdir(join(self.ctx.dist_dir, "root", "python2", "lib"))
|
2015-02-24 00:01:32 +01:00
|
|
|
sh.rm("-rf", "pkgconfig")
|
|
|
|
sh.rm("libpython2.7.a")
|
2019-01-04 21:55:57 +01:00
|
|
|
os.chdir(join(self.ctx.dist_dir, "root", "python2", "lib", "python2.7"))
|
2015-02-24 00:01:32 +01:00
|
|
|
sh.find(".", "-iname", "*.pyc", "-exec", "rm", "{}", ";")
|
|
|
|
sh.find(".", "-iname", "*.py", "-exec", "rm", "{}", ";")
|
|
|
|
sh.rm("-rf", "wsgiref", "bsddb", "curses", "idlelib", "hotshot")
|
|
|
|
sh.rm("-rf", sh.glob("lib*"))
|
|
|
|
|
|
|
|
# now create the zip.
|
2019-02-07 10:00:23 +01:00
|
|
|
logger.info("Create a python27.zip")
|
2015-02-24 00:01:32 +01:00
|
|
|
sh.rm("config/libpython2.7.a")
|
|
|
|
sh.rm("config/python.o")
|
|
|
|
sh.rm("config/config.c.in")
|
|
|
|
sh.rm("config/makesetup")
|
2015-04-30 19:51:01 +02:00
|
|
|
sh.rm("config/install-sh")
|
2015-02-24 00:01:32 +01:00
|
|
|
sh.mv("config", "..")
|
|
|
|
sh.mv("site-packages", "..")
|
|
|
|
sh.zip("-r", "../python27.zip", sh.glob("*"))
|
|
|
|
sh.rm("-rf", sh.glob("*"))
|
|
|
|
sh.mv("../config", ".")
|
|
|
|
sh.mv("../site-packages", ".")
|
|
|
|
finally:
|
|
|
|
os.chdir(oldpwd)
|
|
|
|
|
2015-02-02 05:21:44 +01:00
|
|
|
|
2018-11-02 11:44:25 +01:00
|
|
|
recipe = Python2Recipe()
|