OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 |
| 3 import glob |
| 4 import json |
| 5 import os |
| 6 import shutil |
| 7 import subprocess |
| 8 import sys |
| 9 import tempfile |
| 10 |
| 11 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 12 ENSURE_DEPENDENCIES_PATH = os.path.join(BASE_DIR, "ensure_dependencies.py") |
| 13 MACH_PATH = os.path.join(BASE_DIR, "mach") |
| 14 DIST_PATH = os.path.join(BASE_DIR, "obj-arm-linux-androideabi", "dist") |
| 15 |
| 16 def print_usage(): |
| 17 print "Usage: %s devbuild|release KEY_STORE KEY_NAME" % \ |
| 18 os.path.basename(sys.argv[0]) |
| 19 |
| 20 def check_mozconfig(path, mode): |
| 21 if not os.path.exists(path): |
| 22 raise Exception("'%s' doesn't exist, please create it." % path) |
| 23 |
| 24 with open(path) as file: |
| 25 contents = file.read() |
| 26 updater_disabled = "--disable-updater" in contents |
| 27 |
| 28 if updater_disabled and mode == "devbuild": |
| 29 raise Exception("'%s' seems to set --disable-updater, please don't." % path) |
| 30 elif not updater_disabled and mode == "release": |
| 31 raise Exception( |
| 32 "'%s' doesn't seem to set --disable-updater, please do." % path) |
| 33 |
| 34 def find_mozconfig(mode): |
| 35 mozconfig_path = os.path.join(BASE_DIR, ".mozconfig-" + mode) |
| 36 check_mozconfig(mozconfig_path, mode) |
| 37 return mozconfig_path |
| 38 |
| 39 def build(mode): |
| 40 mach_environment = os.environ.copy() |
| 41 mach_environment["MOZCONFIG"] = find_mozconfig(mode) |
| 42 subprocess.check_call([MACH_PATH, "clobber"], env=mach_environment) |
| 43 subprocess.check_call([MACH_PATH, "build"], env=mach_environment) |
| 44 subprocess.check_call([MACH_PATH, "package"], env=mach_environment) |
| 45 |
| 46 [manifest_path] = glob.glob(os.path.join( |
| 47 DIST_PATH, "fennec-*.en-US.android-arm.json")) |
| 48 with open(manifest_path) as manifest_file: |
| 49 manifest = json.load(manifest_file) |
| 50 |
| 51 apk_path = os.path.join(DIST_PATH, "gecko-unsigned-unaligned.apk") |
| 52 if mode == "release": |
| 53 target_apk_name = "adblockbrowser-%s-arm.apk" % manifest["moz_app_version"] |
| 54 else: |
| 55 target_apk_name = "adblockbrowser-%s.%s-arm.apk" % ( |
| 56 manifest["moz_app_version"], manifest["buildid"]) |
| 57 target_apk_path = os.path.join(DIST_PATH, target_apk_name) |
| 58 shutil.copyfile(apk_path, target_apk_path) |
| 59 return target_apk_path |
| 60 |
| 61 def sign(apk_path, key_store, key_name): |
| 62 temp_apk_path = tempfile.NamedTemporaryFile().name |
| 63 shutil.copyfile(apk_path, temp_apk_path) |
| 64 try: |
| 65 subprocess.check_call(["jarsigner", "-verbose", "-sigalg", "SHA1withRSA", |
| 66 "-digestalg", "SHA1", "-keystore", key_store, |
| 67 temp_apk_path, key_name]) |
| 68 os.remove(apk_path) |
| 69 subprocess.check_call(["zipalign", "-v", "4", temp_apk_path, apk_path]) |
| 70 finally: |
| 71 os.remove(temp_apk_path) |
| 72 |
| 73 if __name__ == "__main__": |
| 74 if len(sys.argv) < 4: |
| 75 print_usage() |
| 76 sys.exit(1) |
| 77 |
| 78 mode, key_store, key_name = sys.argv[1:] |
| 79 if mode not in ("devbuild", "release"): |
| 80 print_usage() |
| 81 sys.exit(2) |
| 82 |
| 83 subprocess.call([ENSURE_DEPENDENCIES_PATH]) |
| 84 apk_path = build(mode) |
| 85 sign(apk_path, key_store, key_name) |
OLD | NEW |