From 3a1cd6ddb22cd79a76e7e571fe5ab26abf712b9d Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Thu, 27 Jun 2019 14:49:47 +0200 Subject: [PATCH] Build the kiwix-lib android "application" in kiwix-build. This is not a real application as it is dependency for kiwix-android. But it a app in the sens that it is packaged for android build system. --- kiwixbuild/dependencies/kiwix_lib.py | 61 +++++++++++++++++++++++++++- kiwixbuild/platforms/android.py | 2 +- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/kiwixbuild/dependencies/kiwix_lib.py b/kiwixbuild/dependencies/kiwix_lib.py index ea3f8ef..9304748 100644 --- a/kiwixbuild/dependencies/kiwix_lib.py +++ b/kiwixbuild/dependencies/kiwix_lib.py @@ -1,8 +1,12 @@ +import shutil, os + from .base import ( Dependency, GitClone, - MesonBuilder) -from kiwixbuild._global import neutralEnv + MesonBuilder, + GradleBuilder) +from kiwixbuild.utils import pj, copy_tree +from kiwixbuild._global import option, get_target_step, neutralEnv class Kiwixlib(Dependency): name = "kiwix-lib" @@ -28,3 +32,56 @@ class Kiwixlib(Dependency): if self.buildEnv.platformInfo.build == 'android': return 'shared' return super().library_type + + +class KiwixlibApp(Dependency): + name = "kiwix-lib-app" + + Source = Kiwixlib.Source + + class Builder(GradleBuilder): + dependencies = ["kiwix-lib"] + gradle_target = "assembleRelease" + + @classmethod + def get_dependencies(cls, platformInfo, allDeps): + if not allDeps: + return super().get_dependencies(platformInfo, allDeps) + else: + deps = [('android_{}'.format(arch), 'kiwix-lib') + for arch in option('android_arch')] + return deps + + 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')) + +# The ICU dat file should be embedded with the kiwix-lib application +# but for now it is package with kiwix-android app and use there. +# We must fix this at a time (before we update the icu version). +# 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 diff --git a/kiwixbuild/platforms/android.py b/kiwixbuild/platforms/android.py index 0441a1a..b9f2fb8 100644 --- a/kiwixbuild/platforms/android.py +++ b/kiwixbuild/platforms/android.py @@ -131,7 +131,7 @@ class Android(MetaPlatformInfo): return ['android_{}'.format(arch) for arch in option('android_arch')] def add_targets(self, targetName, targets): - if targetName not in ('kiwix-android', 'kiwix-android-custom'): + if targetName not in ('kiwix-android', 'kiwix-android-custom', 'kiwix-lib-app'): return super().add_targets(targetName, targets) else: return AndroidPlatformInfo.add_targets(self, targetName, targets)