Fix compilation of kiwix-custom-app.

This is forgotten dependency. Not updated when we moved to multi-arch
build.
Now, it is fixed.
This commit is contained in:
Matthieu Gautier 2018-07-19 16:19:23 +02:00
parent 3283bbe565
commit 5c83ba9d10
2 changed files with 29 additions and 21 deletions

View File

@ -6,16 +6,12 @@ from .base import (
GitClone, GitClone,
GradleBuilder) GradleBuilder)
from kiwixbuild.utils import Remotefile, pj, SkipCommand from kiwixbuild.utils import Remotefile, pj, copy_tree, SkipCommand, run_command
from kiwixbuild._global import option, get_target_step from kiwixbuild._global import option, get_target_step
class KiwixCustomApp(Dependency): class KiwixCustomApp(Dependency):
name = "kiwix-android-custom" name = "kiwix-android-custom"
def __init__(self, buildEnv):
super().__init__(buildEnv)
self.custom_name = option('android_custom_app')
class Source(GitClone): class Source(GitClone):
git_remote = "https://github.com/kiwix/kiwix-android-custom" git_remote = "https://github.com/kiwix/kiwix-android-custom"
git_dir = "kiwix-android-custom" git_dir = "kiwix-android-custom"
@ -25,7 +21,7 @@ class KiwixCustomApp(Dependency):
@property @property
def gradle_target(self): def gradle_target(self):
return "assemble{}".format(self.target.custom_name) return "assemble{}".format(option('android_custom_app'))
@property @property
def gradle_option(self): def gradle_option(self):
@ -43,17 +39,17 @@ class KiwixCustomApp(Dependency):
@property @property
def build_path(self): def build_path(self):
return pj(self.buildEnv.build_dir, "{}_{}".format(self.target.full_name, self.target.custom_name)) return pj(self.buildEnv.build_dir, "{}_{}".format(self.target.full_name(), option('android_custom_app')))
@property @property
def custom_build_path(self): def custom_build_path(self):
return pj(self.build_path, 'custom', self.target.custom_name) return pj(self.build_path, 'custom', option('android_custom_app'))
def _get_zim_size(self): def _get_zim_size(self):
try: try:
zim_size = option('zim_file_size') zim_size = option('zim_file_size')
except AttributeError: except AttributeError:
with open(pj(self.source_path, self.target.custom_name, 'info.json')) as f: with open(pj(self.source_path, option('android_custom_app'), 'info.json')) as f:
app_info = json.load(f) app_info = json.load(f)
zim_size = os.path.getsize(pj(self.custom_build_path, app_info['zim_file'])) zim_size = os.path.getsize(pj(self.custom_build_path, app_info['zim_file']))
return zim_size return zim_size
@ -67,7 +63,7 @@ class KiwixCustomApp(Dependency):
zim_url = option('zim_file_url') zim_url = option('zim_file_url')
if zim_url is None: if zim_url is None:
raise SkipCommand() raise SkipCommand()
with open(pj(self.source_path, self.target.custom_name, 'info.json')) as f: with open(pj(self.source_path, option('android_custom_app'), 'info.json')) as f:
app_info = json.load(f) app_info = json.load(f)
zim_url = app_info.get('zim_url', zim_url) zim_url = app_info.get('zim_url', zim_url)
out_filename = urlparse(zim_url).path out_filename = urlparse(zim_url).path
@ -88,16 +84,28 @@ class KiwixCustomApp(Dependency):
shutil.rmtree(pj(self.build_path, 'kiwixlib', 'src', 'main')) shutil.rmtree(pj(self.build_path, 'kiwixlib', 'src', 'main'))
except FileNotFoundError: except FileNotFoundError:
pass pass
shutil.copytree(pj(self.buildEnv.install_dir, 'kiwix-lib'), for arch in option('android_arch'):
pj(self.build_path, 'kiwixlib', 'src', 'main')) 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( os.makedirs(
pj(self.build_path, 'app', 'src', 'main', 'assets', 'icu'), pj(self.build_path, 'app', 'src', 'main', 'assets', 'icu'),
exist_ok=True) exist_ok=True)
shutil.copy2(pj(self.buildEnv.install_dir, 'share', 'icu', '58.2', for arch in option('android_arch'):
'icudt58l.dat'), try:
pj(self.build_path, 'app', 'src', 'main', 'assets', kiwix_builder = get_target_step('kiwix-lib', 'android_{}'.format(arch))
'icu', 'icudt58l.dat')) 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 # Generate custom directory
try: try:
shutil.rmtree(pj(self.build_path, 'custom')) shutil.rmtree(pj(self.build_path, 'custom'))
@ -106,7 +114,7 @@ class KiwixCustomApp(Dependency):
os.makedirs(pj(self.build_path, 'custom')) os.makedirs(pj(self.build_path, 'custom'))
command = "./gen-custom-android-directory.py {custom_name} --output-dir {custom_dir}" command = "./gen-custom-android-directory.py {custom_name} --output-dir {custom_dir}"
command = command.format( command = command.format(
custom_name=self.target.custom_name, custom_name=option('android_custom_app'),
custom_dir=pj(self.build_path, 'custom', self.target.custom_name) custom_dir=pj(self.build_path, 'custom', option('android_custom_app'))
) )
self.buildEnv.run_command(command, self.source_path, context) run_command(command, self.source_path, context, buildEnv=self.buildEnv)

View File

@ -125,7 +125,7 @@ class Android(MetaPlatformInfo):
return ['android_{}'.format(arch) for arch in option('android_arch')] return ['android_{}'.format(arch) for arch in option('android_arch')]
def add_targets(self, targetName, targets): def add_targets(self, targetName, targets):
if targetName != 'kiwix-android': if targetName not in ('kiwix-android', 'kiwix-android-custom'):
return super().add_targets(targetName, targets) return super().add_targets(targetName, targets)
else: else:
return AndroidPlatformInfo.add_targets(self, targetName, targets) return AndroidPlatformInfo.add_targets(self, targetName, targets)