From 38230677fb6662ccb159c98862d47b9e36f96511 Mon Sep 17 00:00:00 2001 From: Robert Niederreiter Date: Wed, 2 Nov 2016 14:34:21 +0100 Subject: [PATCH] build logger experiments --- recipes/cryptography/__init__.py | 53 +++++++++++++++++++++++++++++--- recipes/pycrypto/__init__.py | 10 +++++- toolchain.py | 21 ++++++++----- 3 files changed, 70 insertions(+), 14 deletions(-) diff --git a/recipes/cryptography/__init__.py b/recipes/cryptography/__init__.py index fa3813d..a34d4ed 100644 --- a/recipes/cryptography/__init__.py +++ b/recipes/cryptography/__init__.py @@ -1,5 +1,7 @@ from os.path import join from toolchain import CythonRecipe +from toolchain import shprint +import sh class CryptographyRecipe(CythonRecipe): @@ -13,10 +15,51 @@ class CryptographyRecipe(CythonRecipe): depends = ["host_setuptools", "cffi", "six", "idna", "pyasn1", "enum34"] cythonize = False - #def get_recipe_env(self, arch): - # env = super(CryptographyRecipe, self).get_recipe_env(arch) - # env["CC"] += " -I{}".format( - # join(self.ctx.dist_dir, "include", arch.arch, "libffi")) - # return env + def get_recipe_env(self, arch): + env = super(CryptographyRecipe, self).get_recipe_env(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")) + return env + + def install(self): + print 'INSTALL #####################################' + super(CryptographyRecipe, self).install() + + def build_arch(self, arch): + print 'BUILD_ARCH ###################################' + build_env = self.get_recipe_env(arch) + print 'ENV #################' + for k, v in sorted(build_env.items()): + print k + ': ' + v + hostpython = sh.Command(self.ctx.hostpython) + shprint(hostpython, "setup.py", "build_ext", "-g", "-v", _env=build_env) + self.biglink() recipe = CryptographyRecipe() diff --git a/recipes/pycrypto/__init__.py b/recipes/pycrypto/__init__.py index 4b8f49f..d6bee69 100644 --- a/recipes/pycrypto/__init__.py +++ b/recipes/pycrypto/__init__.py @@ -1,6 +1,6 @@ '''Recipe for pycrypto on ios ''' -from toolchain import CythonRecipe, shprint +from toolchain import CythonRecipe, shprint, build_logger from os.path import join, exists import sh import os @@ -15,7 +15,9 @@ class PycryptoRecipe(CythonRecipe): def build_arch(self, arch): + build_logger.log('PycryptoRecipe.build_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, @@ -32,13 +34,19 @@ class PycryptoRecipe(CythonRecipe): super(PycryptoRecipe, self).build_arch(arch) def install(self): + build_logger.log('PycryptoRecipe.install()') arch = list(self.filtered_archs)[0] + build_logger.log('arch:\n ', arch) build_dir = self.get_build_dir(arch.arch) + build_logger.log('build_dir:\n ', arch) os.chdir(build_dir) hostpython = sh.Command(self.ctx.hostpython) + build_logger.log('hostpython:\n ', hostpython) build_env = arch.get_env() dest_dir = join(self.ctx.dist_dir, "root", "python") + build_logger.log('dest_dir:\n ', dest_dir) build_env['PYTHONPATH'] = join(dest_dir, 'lib', 'python2.7', 'site-packages') + build_logger.log('build_env', **build_env) shprint(hostpython, "setup.py", "install", "--prefix", dest_dir, _env=build_env) recipe = PycryptoRecipe() diff --git a/toolchain.py b/toolchain.py index a58b839..efdebe7 100755 --- a/toolchain.py +++ b/toolchain.py @@ -32,24 +32,29 @@ import sh IS_PY3 = sys.version_info[0] >= 3 -class CommandLogger(object): +build_log_path = join(__file__[:__file__.rfind('/toolchain.py')], 'build.log') - def __init__(self, filename='build.log'): + +class BuildLogger(object): + + def __init__(self, filename=build_log_path): self.filename = filename def log(self, *args, **kw): - msg = ', '.join([str(arg) for arg in args]) - for k, v in kw: - msg += '\n{}={}'.format(k, str(v)) + 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) -command_logger = CommandLogger() +build_logger = BuildLogger() def shprint(command, *args, **kwargs): - command_logger.log(*(command,) + args, **kwargs) + build_logger.log(*(command,) + args, **kwargs) kwargs["_iter"] = True kwargs["_out_bufsize"] = 1 kwargs["_err_to_out"] = True @@ -602,7 +607,7 @@ class Recipe(object): for library in self.libraries: static_fn = join(self.ctx.dist_dir, "lib", basename(library)) libraries.append(static_fn) - command_logger.log(*['Recipe().dist_libraries'] + libraries) + build_logger.log(*['Recipe().dist_libraries'] + libraries) return libraries def get_build_dir(self, arch):