From 2e347b2b33e6e51660cb6bd2a766e077aafef220 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 21 Aug 2019 14:27:24 +0200 Subject: [PATCH] Do not generate the pom file in kiwix-build. Now we generate the pom file in kiwix-lib side, we don't need to generate it ourselves. --- kiwixbuild/dependencies/kiwix_lib.py | 2 +- .../upload_kiwix_lib_android_to_bintray.py | 70 ++++--------------- travis/compile_all.py | 16 +++-- 3 files changed, 22 insertions(+), 66 deletions(-) diff --git a/kiwixbuild/dependencies/kiwix_lib.py b/kiwixbuild/dependencies/kiwix_lib.py index 6492568..deea079 100644 --- a/kiwixbuild/dependencies/kiwix_lib.py +++ b/kiwixbuild/dependencies/kiwix_lib.py @@ -45,7 +45,7 @@ class KiwixlibApp(Dependency): class Builder(GradleBuilder): dependencies = ["kiwix-lib"] - gradle_target = "assembleRelease" + gradle_target = "assembleRelease writePom" @classmethod def get_dependencies(cls, platformInfo, allDeps): diff --git a/scripts/upload_kiwix_lib_android_to_bintray.py b/scripts/upload_kiwix_lib_android_to_bintray.py index e31824d..d8f20ff 100755 --- a/scripts/upload_kiwix_lib_android_to_bintray.py +++ b/scripts/upload_kiwix_lib_android_to_bintray.py @@ -1,47 +1,11 @@ #!/usr/bin/env python3 -import requests -from requests.auth import HTTPBasicAuth import os, sys import json +import requests bintray_auth = (os.environ['BINTRAY_USER'], os.environ['BINTRAY_PASS']) - -def generate_pom_file(version): - template = """ - - 4.0.0 - org.kiwix.kiwixlib - kiwixlib - {version} - aar - kiwixlib - kiwixlib - https://github.com/kiwix/kiwix-lib - - - GPLv3 - https://www.gnu.org/licenses/gpl-3.0.en.html - - - - - kiwix - kiwix - contact@kiwix.org - - - - https://github.com/kiwix/kiwix-lib.git - https://github.com/kiwix/kiwix-lib.git - https://github.com/kiwix/kiwix-lib - -""" - return template.format(version=version) - - def create_version(version): url = "https://api.bintray.com/packages/kiwix/kiwix/kiwixlib/versions" payload = { @@ -68,7 +32,7 @@ def create_version(version): return False -def upload_archive(version, filename, artefact): +def upload(version, filepath, artefact): url_template = "https://api.bintray.com/content/kiwix/kiwix/kiwixlib/{version}/org/kiwix/kiwixlib/kiwixlib/{version}/{artefact}" parameters = { 'publish': 1, @@ -77,7 +41,7 @@ def upload_archive(version, filename, artefact): # Upload the main artefact url = url_template.format(version=version, artefact=artefact) - with open(filename, 'rb') as f: + with open(filepath, 'rb') as f: r = requests.put(url, data=f, auth=bintray_auth, params=parameters) rcode = r.status_code @@ -86,36 +50,26 @@ def upload_archive(version, filename, artefact): print("ERROR: Fail to upload artefact") return False - # Upload the pom file - pom_artefact = os.path.splitext(artefact)[0] + ".pom" - url = url_template.format(version=version, artefact=pom_artefact) - data = generate_pom_file(version) - r = requests.put(url, data=data, auth=bintray_auth, params=parameters) - - rcode = r.status_code - rcode_family = rcode // 100 - if rcode_family not in (2, 3): - print("ERROR: Fail to upload pom artefact") - return False - return True if __name__ == "__main__": try: - info_file = sys.argv[1] + info_file = sys.argv[1] except IndexError: - print("Usage {} infofile".format(sys.argv[0])) - sys.exit(-1) + print("Usage {} infofile".format(sys.argv[0])) + sys.exit(-1) print("Use info file {}".format(info_file)) with open(info_file) as f: options = json.load(f) if not create_version(options['version']): - sys.exit("Cannot create version") + sys.exit("Cannot create version") - filepath = os.path.join(os.path.dirname(sys.argv[1]), options['filename']) - if not upload_archive(options['version'], filepath, options['artefact']): - sys.exit("Cannot upload artefact") + basedir = os.path.dirname(sys.argv[1]) + for file_ in options['files']: + path = os.path.join(basedir, file_) + if not upload(options['version'], path, file_): + sys.exit("Cannot upload file {}".format(file_)) diff --git a/travis/compile_all.py b/travis/compile_all.py index c327afe..e86b964 100755 --- a/travis/compile_all.py +++ b/travis/compile_all.py @@ -484,17 +484,19 @@ elif PLATFORM == 'android' and 'kiwix-lib-app' in TARGETS: if extra_postfix: postfix = "{}-{}".format(postfix, extra_postfix) - arr_name = "kiwixlib-{}.aar".format(postfix) + basename = "kiwixlib-{}".format(postfix) - source_release_dir = HOME/'BUILD_android'/'kiwix-lib-app'/'kiwixLibAndroid'/'build'/'outputs'/'aar' - shutil.copy(str(source_release_dir/'kiwixLibAndroid-release.aar'), - str(BINTRAY_ARCHIVES_DIR/arr_name)) + output_release_dir = HOME/'BUILD_android'/'kiwix-lib-app'/'kiwixLibAndroid'/'build'/'outputs' + shutil.copy(str(output_release_dir/'aar'/'kiwixLibAndroid-release.aar'), + str(BINTRAY_ARCHIVES_DIR/basename+'.aar')) + shutil.copy(str(output_release_dir/'pom.xml'), + str(BINTRAY_ARCHIVES_DIR/basename+'.pom')) - json_filename = '{}_bintray_info.json'.format(arr_name) + + json_filename = '{}_bintray_info.json'.format(basename) data = { 'version': postfix, - 'filename': arr_name, - 'artefact': arr_name + 'files': [basename+ext for ext in ('.aar', '.pom')] } with open(str(BINTRAY_ARCHIVES_DIR/json_filename), 'w') as f: json.dump(data, f)