def _get_zim_size(self): try: zim_size = option('zim_file_size') except AttributeError: with open(pj(self.source_path, option('android_custom_app'), 'info.json')) as f: app_info = json.load(f) zim_size = os.path.getsize(pj(self.custom_build_path, app_info['zim_file'])) return zim_size
def _install(self, context): copy_tree( pj(self.source_path, "bin"), pj(self.install_path, "bin"), post_copy_function = add_execution_right) copy_tree( pj(self.source_path, "lib"), pj(self.install_path, "lib"))
def _install(self, context): context.try_skip(self.build_path) command = "cp {ctpp2c}* {install_dir}".format( ctpp2c=pj(self.build_path, 'ctpp2c'), install_dir=pj(self.buildEnv.install_dir, 'bin')) run_command(command, self.build_path, context, buildEnv=self.buildEnv)
def _gen_crossfile(self, name): crossfile = pj(self.buildEnv.build_dir, name) template_file = pj(TEMPLATES_DIR, name) with open(template_file, 'r') as f: template = f.read() content = template.format(**self.get_cross_config()) with open(crossfile, 'w') as outfile: outfile.write(content) return crossfile
def get_env(self): env = super().get_env() env['PKG_CONFIG_LIBDIR'] = pj(self.root_path, 'lib', 'pkgconfig') env['QEMU_LD_PREFIX'] = pj(self.root_path, "arm-linux-gnueabihf", "libc") env['QEMU_SET_ENV'] = "LD_LIBRARY_PATH={}".format( ':'.join([ pj(self.root_path, self.arch_full, "lib"), env['LD_LIBRARY_PATH'] ])) return env
def set_env(self, env): env['PKG_CONFIG_LIBDIR'] = pj(self.root_path, 'lib', 'pkgconfig') env['CFLAGS'] = " -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 "+env['CFLAGS'] env['CXXFLAGS'] = " -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 "+env['CXXFLAGS'] env['QEMU_LD_PREFIX'] = pj(self.root_path, "arm-linux-gnueabihf", "libc") env['QEMU_SET_ENV'] = "LD_LIBRARY_PATH={}".format( ':'.join([ pj(self.root_path, self.arch_full, "lib"), env['LD_LIBRARY_PATH'] ]))
def _configure(self, context): # Copy kiwix-android in build dir. kiwix_android_source = get_target_step('kiwix-android', 'source') if not os.path.exists(self.build_path): shutil.copytree(kiwix_android_source.source_path, self.build_path) # Copy kiwix-lib application in build dir try: shutil.rmtree(pj(self.build_path, 'kiwixlib', 'src', 'main')) except FileNotFoundError: pass shutil.copytree(pj(self.buildEnv.install_dir, 'kiwix-lib'), pj(self.build_path, 'kiwixlib', 'src', 'main')) os.makedirs(pj(self.build_path, 'app', 'src', 'main', 'assets', 'icu'), exist_ok=True) shutil.copy2( pj(self.buildEnv.install_dir, 'share', 'icu', '58.2', 'icudt58l.dat'), pj(self.build_path, 'app', 'src', 'main', 'assets', 'icu', 'icudt58l.dat')) # Generate custom directory try: shutil.rmtree(pj(self.build_path, 'custom')) except FileNotFoundError: pass os.makedirs(pj(self.build_path, 'custom')) command = "./gen-custom-android-directory.py {custom_name} --output-dir {custom_dir}" command = command.format(custom_name=self.target.custom_name, custom_dir=pj(self.build_path, 'custom', self.target.custom_name)) self.buildEnv.run_command(command, self.source_path, context)
def get_env(self): env = super().get_env() static_platform = self.get_platform('native_static') static_buildEnv = static_platform.buildEnv static_install_dir = static_buildEnv.install_dir env['PATH'] = ':'.join([pj(static_install_dir, 'bin')] + [env['PATH']]) pkgconfig_path = pj(static_install_dir, static_buildEnv.libprefix, 'pkgconfig') env['PKG_CONFIG_PATH'] = ':'.join( [env['PKG_CONFIG_PATH'], pkgconfig_path]) return env
def make_option(self): if self.buildEnv.platformInfo.build == 'win32': return "--makefile win32/Makefile.gcc PREFIX={host}- SHARED_MODE={static} INCLUDE_PATH={include_path} LIBRARY_PATH={library_path} BINARY_PATH={binary_path}".format( host='i686-w64-mingw32', static="0" if self.buildEnv.platformInfo.static else "1", include_path=pj(self.buildEnv.install_dir, 'include'), library_path=pj(self.buildEnv.install_dir, self.buildEnv.libprefix), binary_path=pj(self.buildEnv.install_dir, 'bin'), ) return ""
def set_env(self, env): root_path = pj(self.ndk_builder.install_path, 'sysroot') env['PKG_CONFIG_LIBDIR'] = pj(root_path, 'lib', 'pkgconfig') env['CFLAGS'] = '-fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 --sysroot={} '.format(root_path) + env['CFLAGS'] env['CXXFLAGS'] = '-fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 --sysroot={} '.format(root_path) + env['CXXFLAGS'] env['LDFLAGS'] = '--sysroot={} '.format(root_path) + env['LDFLAGS'] #env['CFLAGS'] = ' -fPIC -D_FILE_OFFSET_BITS=64 -O3 '+env['CFLAGS'] #env['CXXFLAGS'] = (' -D__OPTIMIZE__ -fno-strict-aliasing ' # ' -DU_HAVE_NL_LANGINFO_CODESET=0 ' # '-DU_STATIC_IMPLEMENTATION -O3 ' # '-DU_HAVE_STD_STRING -DU_TIMEZONE=0 ')+env['CXXFLAGS'] env['NDK_DEBUG'] = '0'
def set_env(self, env): super().set_env(env) static_platform = self.get_platform('native_static') static_buildEnv = static_platform.buildEnv static_install_dir = static_buildEnv.install_dir env['CPPFLAGS'] = " ".join( ['-I' + pj(static_install_dir, 'include'), env['CPPFLAGS']]) env['PATH'] = ':'.join([pj(static_install_dir, 'bin')] + [env['PATH']]) pkgconfig_path = pj(static_install_dir, static_buildEnv.libprefix, 'pkgconfig') env['PKG_CONFIG_PATH'] = ':'.join( [env['PKG_CONFIG_PATH'], pkgconfig_path])
def _download_zim(self, context): zim_url = option('zim_file_url') if zim_url is None: raise SkipCommand() with open(pj(self.source_path, option('android_custom_app'), 'info.json')) as f: app_info = json.load(f) zim_url = app_info.get('zim_url', zim_url) out_filename = urlparse(zim_url).path out_filename = os.path.basename(out_filename) zim_file = Remotefile(out_filename, '', zim_url) self.buildEnv.download(zim_file) shutil.copy(pj(self.buildEnv.archive_dir, out_filename), pj(self.custom_build_path, app_info['zim_file']))
def _configure(self, context): try: shutil.rmtree(self.build_path) except FileNotFoundError: pass if not os.path.exists(self.build_path): shutil.copytree(pj(self.source_path, 'android-kiwix-lib-publisher'), self.build_path, symlinks=True) for arch in option('android_arch'): try: kiwix_builder = get_target_step('kiwix-lib', 'android_{}'.format(arch)) except KeyError: pass else: copy_tree(pj(kiwix_builder.buildEnv.install_dir, 'kiwix-lib'), pj(self.build_path, 'kiwixLibAndroid', 'src', 'main'))
def command(self, name, function, *args): print(" {} {} : ".format(name, self.name), end="", flush=True) log = pj(self._log_dir, 'cmd_{}_{}.log'.format(name, self.name)) context = Context(name, log, True) try: start_time = time.time() ret = function(*args, context=context) context._finalise() duration = time.time() - start_time print(colorize("OK"), "({:.1f}s)".format(duration)) return ret except WarningMessage as e: print(e) except SkipCommand as e: print(e) except subprocess.CalledProcessError: print(colorize("ERROR")) try: with open(log, 'r') as f: print(f.read()) except: pass raise StopBuild() except: print(colorize("ERROR")) raise
def get_cross_config(self): return { 'root_path': self.root_path, 'binaries': self.binaries, 'exec_wrapper_def': '', 'extra_libs': [ '-fembed-bitcode', '-isysroot', self.root_path, '-arch', self.arch, '-miphoneos-version-min=9.0', '-stdlib=libc++' ], 'extra_cflags': [ '-fembed-bitcode', '-isysroot', self.root_path, '-arch', self.arch, '-miphoneos-version-min=9.0', '-stdlib=libc++', '-I{}'.format(pj(self.buildEnv.install_dir, 'include')) ], 'host_machine': { 'system': 'Darwin', 'lsystem': 'darwin', 'cpu_family': self.arch, 'cpu': self.cpu, 'endian': '', 'abi': '' }, }
def _patch(self, context): context.try_skip(self.source_path) for p in self.patches: with open(pj(SCRIPT_DIR, 'patches', p), 'r') as patch_input: run_command("patch -p1", self.source_path, context, input=patch_input.read())
def _extract(self, context): context.try_skip(self.extract_path) if os.path.exists(self.extract_path): shutil.rmtree(self.extract_path) extract_archive(pj(neutralEnv('archive_dir'), self.archive.name), neutralEnv('source_dir'), topdir=self.archive_top_dir, name=self.source_dir)
def binaries(self): install_path = self.install_path binaries = { k: pj(install_path, 'bin', v) for k, v in self.binaries_name.items() } binaries['PKGCONFIG'] = 'pkg-config' return binaries
def all_configure_option(self): option = self.configure_option_template.format( dep_options=self.configure_option, static_option=self.static_configure_option if self.buildEnv.platformInfo.static else self.dynamic_configure_option, env_option=self.buildEnv.platformInfo.configure_option if not self.target.force_native_build else "", install_dir=self.buildEnv.install_dir, libdir=pj(self.buildEnv.install_dir, self.buildEnv.libprefix) ) return option
def _merge_libs(self, context): lib_dirs = [] for arch in option('ios_arch'): plt = PlatformInfo.get_platform('iOS_{}'.format(arch)) lib_dirs.append(pj(plt.buildEnv.install_dir, 'lib')) libs = [] for f in os.listdir(lib_dirs[0]): if os.path.islink(pj(lib_dirs[0], f)): continue if f.endswith('.a') or f.endswith('.dylib'): libs.append(f) os.makedirs(pj(self.buildEnv.install_dir, 'lib'), exist_ok=True) command_tmp = "lipo -create {input} -output {output}" for l in libs: command = command_tmp.format( input=" ".join(pj(d, l) for d in lib_dirs), output=pj(self.buildEnv.install_dir, 'lib', l)) run_command(command, self.buildEnv.install_dir, context)
def _configure(self, context): context.try_skip(self.build_path) command = "{configure_script} {configure_option}" command = command.format(configure_script=pj(self.source_path, self.configure_script), configure_option=self.all_configure_option) env = self.buildEnv.get_env(cross_comp_flags=True, cross_compilers=True, cross_path=True) self.set_configure_env(env) run_command(command, self.build_path, context, env=env)
def set_comp_flags(self, env): super().set_comp_flags(env) root_path = pj(self.install_path, 'sysroot') march = '-march={}'.format(self.march) if hasattr(self, 'march') else '' env['CFLAGS'] = '-fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 --sysroot={} {} '.format( root_path, march) + env['CFLAGS'] env['CXXFLAGS'] = '-fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 --sysroot={} {} '.format( root_path, march) + env['CXXFLAGS'] env['LDFLAGS'] = '--sysroot={} {} '.format(root_path, march) + env['LDFLAGS']
def binaries(self, install_path): binaries = ((k,'{}-{}'.format(self.arch_full, v)) for k, v in (('CC', 'gcc'), ('CXX', 'g++'), ('AR', 'ar'), ('STRIP', 'strip'), ('WINDRES', 'windres'), ('RANLIB', 'ranlib'), ('LD', 'ld')) ) return {k:pj(install_path, 'bin', v) for k,v in binaries}
def gradle_option(self): template = ("-i -P customDir={customDir}" " -P zim_file_size={zim_size}" " -P version_code={version_code}" " -P version_name={version_name}" " -P content_version_code={content_version_code}") return template.format( customDir=pj(self.build_path, 'custom'), zim_size=self._get_zim_size(), version_code=os.environ['VERSION_CODE'], version_name=os.environ['VERSION_NAME'], content_version_code=os.environ['CONTENT_VERSION_CODE'])
def _configure(self, context): # Copy kiwix-android in build dir. kiwix_android_source = get_target_step('kiwix-android', 'source') if not os.path.exists(self.build_path): shutil.copytree(kiwix_android_source.source_path, self.build_path) # Copy kiwix-lib application in build dir try: shutil.rmtree(pj(self.build_path, 'kiwixlib', 'src', 'main')) except FileNotFoundError: pass for arch in option('android_arch'): try: kiwix_builder = get_target_step('kiwix-lib', 'android_{}'.format(arch)) except KeyError: pass else: copy_tree(pj(kiwix_builder.buildEnv.install_dir, 'kiwix-lib'), pj(self.build_path, 'kiwixlib', 'src', 'main')) os.makedirs( pj(self.build_path, 'app', 'src', 'main', 'assets', 'icu'), exist_ok=True) for arch in option('android_arch'): try: kiwix_builder = get_target_step('kiwix-lib', 'android_{}'.format(arch)) except KeyError: pass else: shutil.copy2(pj(kiwix_builder.buildEnv.install_dir, 'share', 'icu', '58.2', 'icudt58l.dat'), pj(self.build_path, 'app', 'src', 'main', 'assets', 'icu', 'icudt58l.dat')) break # Generate custom directory try: shutil.rmtree(pj(self.build_path, 'custom')) except FileNotFoundError: pass os.makedirs(pj(self.build_path, 'custom')) command = "./gen-custom-android-directory.py {custom_name} --output-dir {custom_dir}" command = command.format( custom_name=option('android_custom_app'), custom_dir=pj(self.build_path, 'custom', option('android_custom_app')) ) run_command(command, self.source_path, context, buildEnv=self.buildEnv)
def _configure(self, context): if not os.path.exists(self.build_path): shutil.copytree(self.source_path, self.build_path, symlinks=True) try: shutil.rmtree(pj(self.build_path, 'kiwixlib', 'src', 'main')) except FileNotFoundError: pass for arch in option('android_arch'): try: kiwix_builder = get_target_step('kiwix-lib', 'android_{}'.format(arch)) except KeyError: pass else: copy_tree( pj(kiwix_builder.buildEnv.install_dir, 'kiwix-lib'), pj(self.build_path, 'kiwixlib', 'src', 'main')) os.makedirs(pj(self.build_path, 'app', 'src', 'main', 'assets', 'icu'), exist_ok=True) for arch in option('android_arch'): try: kiwix_builder = get_target_step('kiwix-lib', 'android_{}'.format(arch)) except KeyError: pass else: shutil.copy2( pj(kiwix_builder.buildEnv.install_dir, 'share', 'icu', '58.2', 'icudt58l.dat'), pj(self.build_path, 'app', 'src', 'main', 'assets', 'icu', 'icudt58l.dat')) break
def _compile(self, context): platformInfo = self.buildEnv.platformInfo if platformInfo.build == 'native': return super()._compile(context) context.try_skip(self.build_path) command = "make -j4 {make_target} {make_option}".format( make_target=self.make_target, make_option=self.make_option ) libmagic_native_builder = get_target_step('libmagic', 'native_static') env = Defaultdict(str, os.environ) env['PATH'] = ':'.join([pj(libmagic_native_builder.build_path, 'src'), env['PATH']]) run_command(command, self.build_path, context, buildEnv=self.buildEnv, env=env)
def get_cross_config(self): extra_libs = ['-llog'] extra_cflags = ['-I{}'.format(pj(self.buildEnv.install_dir, 'include'))] if hasattr(self, 'march'): extra_libs.append('-march={}'.format(self.march)) extra_cflags.append('-march={}'.format(self.march)) return { 'exec_wrapper_def': '', 'install_path': self.install_path, 'binaries': self.binaries(), 'root_path': pj(self.install_path, 'sysroot'), 'extra_libs': extra_libs, 'extra_cflags': extra_cflags, 'host_machine': { 'system': 'Android', 'lsystem': 'android', 'cpu_family': self.arch, 'cpu': self.cpu, 'endian': 'little', 'abi': self.abi }, }
def get_cross_config(self): install_path = self.ndk_builder.install_path return { 'exec_wrapper_def': '', 'install_path': install_path, 'binaries': self.binaries(install_path), 'root_path': pj(install_path, 'sysroot'), 'extra_libs': ['-llog'], 'extra_cflags': ['-I{}'.format(pj(self.buildEnv.install_dir, 'include'))], 'host_machine': { 'system': 'Android', 'lsystem': 'android', 'cpu_family': self.arch, 'cpu': self.cpu, 'endian': 'little', 'abi': self.abi }, }
def binaries(self): binaries = ((k,'{}-{}'.format(self.arch_full, v)) for k, v in (('CC', 'gcc'), ('CXX', 'g++'), ('AR', 'ar'), ('STRIP', 'strip'), ('WINDRES', 'windres'), ('RANLIB', 'ranlib'), ('LD', 'ld')) ) binaries = {k:pj(self.root_path, 'bin', v) for k,v in binaries} binaries['PKGCONFIG'] = 'pkg-config' return binaries