From e0f7ec5197c526949ee7a6c1eb2f47db394b101d Mon Sep 17 00:00:00 2001 From: Robert Niederreiter Date: Fri, 4 Nov 2016 15:49:44 +0100 Subject: [PATCH] document new findings, remove build logger, some cleanup --- recipes/cffi/__init__.py | 28 +++++++++++-- recipes/cryptography/__init__.py | 63 ++++++++++------------------- recipes/host_setuptools/__init__.py | 5 ++- recipes/pycrypto/__init__.py | 1 - toolchain.py | 23 ----------- 5 files changed, 50 insertions(+), 70 deletions(-) diff --git a/recipes/cffi/__init__.py b/recipes/cffi/__init__.py index a0d04e1..ea44290 100644 --- a/recipes/cffi/__init__.py +++ b/recipes/cffi/__init__.py @@ -24,7 +24,7 @@ class CffiRecipe(CythonRecipe): return env def install(self): - arch = list(self.filtered_archs)[0] + arch = [arch for arch in self.filtered_archs if arch.arch == 'x86_64'][0] build_dir = self.get_build_dir(arch.arch) os.chdir(build_dir) # manually create expected directory in build directory @@ -32,13 +32,35 @@ class CffiRecipe(CythonRecipe): if not os.path.exists(scripts_dir): os.makedirs(scripts_dir) hostpython = sh.Command(self.ctx.hostpython) + + # install cffi in hostpython + # + # XXX: installs, module import works, but FFI fails to instanciate: + # + # myhost:kivy-ios user$ ./dist/hostpython/bin/python + # Could not find platform dependent libraries + # Consider setting $PYTHONHOME to [:] + # Python 2.7.1 (r271:86832, Nov 4 2016, 10:41:44) + # [GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin + # Type "help", "copyright", "credits" or "license" for more information. + # >>> import cffi + # >>> cffi.api.FFI() + # Traceback (most recent call last): + # File "", line 1, in + # File "/.../kivy-ios/dist/hostpython/lib/python2.7/site-packages/cffi/api.py", line 56, in __init__ + # import _cffi_backend as backend + # ImportError: dynamic module does not define init function (init_cffi_backend) + r = self.get_recipe('hostlibffi', self.ctx) + build_env = r.get_recipe_env(arch) + args = [hostpython, "setup.py", "install"] + shprint(*args, _env=build_env) + + # install cffi in root site packages build_env = arch.get_env() dest_dir = join(self.ctx.dist_dir, "root", "python") pythonpath = join(dest_dir, 'lib', 'python2.7', 'site-packages') build_env['PYTHONPATH'] = pythonpath args = [hostpython, "setup.py", "install", "--prefix", dest_dir] shprint(*args, _env=build_env) - args = [hostpython, "setup.py", "install"] - shprint(*args, _env=build_env) recipe = CffiRecipe() diff --git a/recipes/cryptography/__init__.py b/recipes/cryptography/__init__.py index 798a1c2..4c30919 100644 --- a/recipes/cryptography/__init__.py +++ b/recipes/cryptography/__init__.py @@ -16,49 +16,30 @@ class CryptographyRecipe(CythonRecipe): cythonize = False def get_recipe_env(self, arch): - #env['LN_FLAGS'] = "-lboost_thread-mt" - #env['PKG_CONFIG_PATH'] = join(self.ctx.dist_dir, "include", arch.arch, "libffi") - #env['PKG_CONFIG_PATH'] += ":" + join(self.ctx.dist_dir, "include", arch.arch, "openssl") - """ - libffi_include = dict() - libffi_include['arm64'] = 'build_iphoneos-arm64' - libffi_include['armv7'] = 'build_iphoneos-armv7' - libffi_include['i386'] = 'build_iphonesimulator-i386' - libffi_include['x86_64'] = 'build_iphonesimulator-x86_64' - include_path = join( - self.ctx.build_dir, 'libffi', arch.arch, - 'libffi-3.2.1', libffi_include[arch.arch]) - env['PKG_CONFIG_PATH'] = include_path - env["CC"] += " -I{}".format(include_path) - env["CC"] += " -I{}".format( - join(self.ctx.dist_dir, "include", arch.arch, "libffi")) - # env["CFLAGS"] - #env["CFLAGS"] += " -I{}".format( - # join(self.ctx.dist_dir, "include", arch.arch, "openssl", "openssl")) - """ - #dest_dir = join(self.ctx.dist_dir, "root", "python") - #pythonpath = join(dest_dir, "lib", "python2.7", "site-packages") - #env["PYTHONPATH"] = pythonpath - #env["CC"] += " -I{}".format( - # join(self.ctx.dist_dir, "include", arch.arch, "libffi")) - #env["LDFLAGS"] += "-L{}".format( - # join(self.ctx.dist_dir, "hostlibffi", "usr", "local", "lib")) - #env["CFLAGS"] += "-I{}".format( - # join(self.ctx.dist_dir, "hostlibffi", "usr", "local", "include")) env = super(CryptographyRecipe, self).get_recipe_env(arch) - r = self.get_recipe('openssl', self.ctx) - openssl_dir = r.get_build_dir(arch.arch) - env['PYTHON_ROOT'] = join(self.ctx.dist_dir, 'root', 'python') - env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7' + \ - ' -I' + join(openssl_dir, 'include') - # Set linker to use the correct gcc - env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions' - env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \ - ' -L' + openssl_dir + \ - ' -lpython2.7' + \ - ' -lssl' + r.version + \ - ' -lcrypto' + r.version + env["CC"] += " -I{}".format( + join(self.ctx.dist_dir, "include", arch.arch, "libffi")) + env["CFLAGS"] += " -I{}".format( + join(self.ctx.dist_dir, "include", arch.arch, "openssl", "openssl")) return env + def install(self): + arch = list(self.filtered_archs)[0] + build_dir = self.get_build_dir(arch.arch) + os.chdir(build_dir) + # manually create expected directory in build directory + scripts_dir = join("build", "scripts-2.7") + if not os.path.exists(scripts_dir): + os.makedirs(scripts_dir) + hostpython = sh.Command(self.ctx.hostpython) + build_env = arch.get_env() + dest_dir = join(self.ctx.dist_dir, "root", "python") + pythonpath = join(dest_dir, 'lib', 'python2.7', 'site-packages') + build_env['PYTHONPATH'] = pythonpath + args = [hostpython, "setup.py", "install", "--prefix", dest_dir] + shprint(*args, _env=build_env) + #args = [hostpython, "setup.py", "install"] + #shprint(*args, _env=build_env) + recipe = CryptographyRecipe() diff --git a/recipes/host_setuptools/__init__.py b/recipes/host_setuptools/__init__.py index 1cb5e16..0fe64d6 100644 --- a/recipes/host_setuptools/__init__.py +++ b/recipes/host_setuptools/__init__.py @@ -18,7 +18,6 @@ class HostSetuptools(Recipe): # LINKED SETUPTOOLS CAN CAUSE TROUBLES, UNCOMMENT RETURN IF INSTALLING # PYTHON PACKAGE FAILS. UNPACKED SETUPTOOLS RESULT IN BDIST_EGG COMMAND # NOT FOUND - return # Extract setuptools egg and remove .pth files. Otherwise subsequent # python package installations using setuptools will raise exceptions. # Setuptools version 28.3.0 @@ -32,7 +31,9 @@ class HostSetuptools(Recipe): shprint(unzip, setuptools_egg_path) os.remove(setuptools_egg_path) os.remove('setuptools.pth') - os.remove('easy-install.pth') + # XXX: setuptools egg is referenced in easy-install.pth, check removal + # after unpacking setuptools if necessary + #os.remove('easy-install.pth') shutil.rmtree('EGG-INFO') recipe = HostSetuptools() diff --git a/recipes/pycrypto/__init__.py b/recipes/pycrypto/__init__.py index cf341c2..4b8f49f 100644 --- a/recipes/pycrypto/__init__.py +++ b/recipes/pycrypto/__init__.py @@ -16,7 +16,6 @@ class PycryptoRecipe(CythonRecipe): def build_arch(self, arch): build_env = arch.get_env() - build_logger.log(**build_env) self.apply_patch('hash_SHA2_template.c.patch', target_dir=self.build_dir + '/src') configure = sh.Command(join(self.build_dir, "configure")) shprint(configure, diff --git a/toolchain.py b/toolchain.py index efdebe7..345d6f4 100755 --- a/toolchain.py +++ b/toolchain.py @@ -32,29 +32,7 @@ import sh IS_PY3 = sys.version_info[0] >= 3 -build_log_path = join(__file__[:__file__.rfind('/toolchain.py')], 'build.log') - - -class BuildLogger(object): - - def __init__(self, filename=build_log_path): - self.filename = filename - - def log(self, *args, **kw): - msg = '' - for arg in args: - msg += str(arg) + '\n' - for k, v in kw.items(): - msg += '{}={}\n'.format(k, str(v)) - with open(self.filename, 'a') as f: - f.write(msg) - - -build_logger = BuildLogger() - - def shprint(command, *args, **kwargs): - build_logger.log(*(command,) + args, **kwargs) kwargs["_iter"] = True kwargs["_out_bufsize"] = 1 kwargs["_err_to_out"] = True @@ -607,7 +585,6 @@ class Recipe(object): for library in self.libraries: static_fn = join(self.ctx.dist_dir, "lib", basename(library)) libraries.append(static_fn) - build_logger.log(*['Recipe().dist_libraries'] + libraries) return libraries def get_build_dir(self, arch):