예제 #1
0
 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
예제 #2
0
 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"))
예제 #3
0
 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)
예제 #4
0
파일: base.py 프로젝트: serg585/kiwix-build
 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
예제 #5
0
 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
예제 #6
0
 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']
     ]))
예제 #7
0
        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)
예제 #8
0
 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
예제 #9
0
 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 ""
예제 #10
0
 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'
예제 #11
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])
예제 #12
0
 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']))
예제 #13
0
 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'))
예제 #14
0
 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
예제 #15
0
파일: ios.py 프로젝트: refeed/kiwix-build
 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': ''
         },
     }
예제 #16
0
 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())
예제 #17
0
 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)
예제 #18
0
 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
예제 #19
0
 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
예제 #20
0
 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)
예제 #21
0
 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)
예제 #22
0
 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']
예제 #23
0
 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}
예제 #24
0
 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'])
예제 #25
0
        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)
예제 #26
0
 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
예제 #27
0
 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)
예제 #28
0
 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
         },
     }
예제 #29
0
 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
         },
     }
예제 #30
0
 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