Add support to build kiwix android custom app.

The custom app to build must be specified as an option when running
kiwix-build.
In the same way, the zim file to download must be specified in the
`info.json` (`zim_url` key) or given as option.
This commit is contained in:
Matthieu Gautier 2017-05-02 17:29:28 +02:00
parent a86d0b143b
commit f044fd15bf
2 changed files with 91 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import shutil,os
import shutil, os, json
from urllib.parse import urlparse
from dependency_utils import (
Dependency,
@ -362,3 +363,78 @@ class KiwixAndroid(Dependency):
except FileNotFoundError:
pass
shutil.copytree(pj(self.buildEnv.install_dir, 'kiwix-lib'), pj(self.build_path, 'kiwixlib', 'src', 'main'))
class KiwixCustomApp(Dependency):
name = "kiwix-android-custom"
dependencies = ["kiwix-android", "kiwix-lib"]
def __init__(self, buildEnv):
super().__init__(buildEnv)
self.custom_name = buildEnv.options.android_custom_app
class Source(GitClone):
git_remote = "https://github.com/kiwix/kiwix-android-custom"
git_dir = "kiwix-android-custom"
class Builder(GradleBuilder):
@property
def gradle_target(self):
return "assemble{}".format(self.target.custom_name)
@property
def gradle_option(self):
return "-i -P customDir={}".format(pj(self.build_path, 'custom'))
@property
def build_path(self):
return pj(self.buildEnv.build_dir, "{}_{}".format(self.target.full_name, self.target.custom_name))
@property
def custom_build_path(self):
return pj(self.build_path, 'custom', self.target.custom_name)
def build(self):
self.command('configure', self._configure)
self.command('download_zim', self._download_zim)
self.command('compile', self._compile)
def _download_zim(self, context):
zim_url = self.buildEnv.options.zim_file_url
if zim_url is None:
raise SkipCommand()
with open(pj(self.source_path, self.target.custom_name, '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):
# Copy kiwix-android in build dir.
kiwix_android_dep = self.buildEnv.targetsDict['kiwix-android']
if not os.path.exists(self.build_path):
shutil.copytree(kiwix_android_dep.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'))
# 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)

View File

@ -933,7 +933,20 @@ def parse_args():
parser.add_argument('--clean-at-end', action='store_true',
help="Clean all intermediate files after the (successfull) build")
return parser.parse_args()
subgroup = parser.add_argument_group('custom app',
description="Android custom app specific options")
subgroup.add_argument('--android-custom-app',
help="The custom android app to build")
subgroup.add_argument('--zim-file-url',
help="The url of the zim file to download")
options = parser.parse_args()
if options.targets == 'kiwix-android-custom':
if not options.android_custom_app or not options.zim_file_url:
print("You need to specify ANDROID_CUSTOM_APP and ZIM_FILE_URL if "
"want to build a kiwix-android-custom target")
sys.exit(1)
return options
if __name__ == "__main__":