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 >>sys.stderr, "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 | |
27 # This check can be removed once https://issues.adblockplus.org/ticket/2490 is | |
28 # done. | |
29 if "--disable-crashreporter" not in contents: | |
30 raise Exception( | |
31 "'%s' doesn't seem to set --disable-crashreporter, please do." % path) | |
32 | |
33 if "export MOZILLA_OFFICIAL=1" not in contents: | |
34 raise Exception( | |
35 "'%s' doesn't seem to export MOZILLA_OFFICIAL=1, please do." % path) | |
36 | |
37 updater_disabled = "--disable-updater" in contents | |
38 if updater_disabled and mode == "devbuild": | |
39 raise Exception("'%s' seems to set --disable-updater, please don't." % path) | |
40 elif not updater_disabled and mode == "release": | |
41 raise Exception( | |
42 "'%s' doesn't seem to set --disable-updater, please do." % path) | |
43 | |
44 def find_mozconfig(mode): | |
45 mozconfig_path = os.path.join(BASE_DIR, ".mozconfig-" + mode) | |
46 check_mozconfig(mozconfig_path, mode) | |
47 return mozconfig_path | |
48 | |
49 def build(mode): | |
50 mach_environment = os.environ.copy() | |
51 mach_environment["MOZCONFIG"] = find_mozconfig(mode) | |
52 subprocess.check_call([MACH_PATH, "clobber"], env=mach_environment) | |
53 subprocess.check_call([MACH_PATH, "build"], env=mach_environment) | |
54 subprocess.check_call([MACH_PATH, "package"], env=mach_environment) | |
55 | |
56 [manifest_path] = glob.glob(os.path.join( | |
57 DIST_PATH, "fennec-*.en-US.android-arm.json")) | |
58 with open(manifest_path) as manifest_file: | |
59 manifest = json.load(manifest_file) | |
60 | |
61 apk_path = os.path.join(DIST_PATH, "gecko-unsigned-unaligned.apk") | |
62 if mode == "release": | |
63 target_apk_name = "adblockbrowser-%s-arm.apk" % manifest["moz_app_version"] | |
64 else: | |
65 target_apk_name = "adblockbrowser-%s.%s-arm.apk" % ( | |
66 manifest["moz_app_version"], manifest["buildid"]) | |
67 target_apk_path = os.path.join(DIST_PATH, target_apk_name) | |
68 shutil.copyfile(apk_path, target_apk_path) | |
69 return target_apk_path | |
70 | |
71 def sign(apk_path, key_store, key_name): | |
72 temp_apk_path = tempfile.NamedTemporaryFile().name | |
73 shutil.copyfile(apk_path, temp_apk_path) | |
74 try: | |
75 subprocess.check_call(["jarsigner", "-verbose", "-sigalg", "SHA1withRSA", | |
76 "-digestalg", "SHA1", "-keystore", key_store, | |
77 temp_apk_path, key_name]) | |
78 os.remove(apk_path) | |
79 subprocess.check_call(["zipalign", "-v", "4", temp_apk_path, apk_path]) | |
80 finally: | |
81 os.remove(temp_apk_path) | |
82 | |
83 if __name__ == "__main__": | |
84 if len(sys.argv) < 4: | |
85 print_usage() | |
86 sys.exit(1) | |
87 | |
88 mode, key_store, key_name = sys.argv[1:] | |
89 if mode not in ("devbuild", "release"): | |
90 print_usage() | |
91 sys.exit(2) | |
92 | |
93 subprocess.check_call([ENSURE_DEPENDENCIES_PATH]) | |
94 apk_path = build(mode) | |
95 sign(apk_path, key_store, key_name) | |
OLD | NEW |