Left: | ||
Right: |
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 updater_disabled = "--disable-updater" in contents | |
34 if updater_disabled and mode == "devbuild": | |
35 raise Exception("'%s' seems to set --disable-updater, please don't." % path) | |
36 elif not updater_disabled and mode == "release": | |
37 raise Exception( | |
38 "'%s' doesn't seem to set --disable-updater, please do." % path) | |
39 | |
40 def find_mozconfig(mode): | |
René Jeschke
2015/05/19 09:57:54
Nit: 'find_mozconfig' does not really 'search' for
Felix Dahlke
2015/05/19 15:54:35
Well, it looks for an appropriate mozconfig and co
| |
41 mozconfig_path = os.path.join(BASE_DIR, ".mozconfig-" + mode) | |
42 check_mozconfig(mozconfig_path, mode) | |
43 return mozconfig_path | |
44 | |
45 def build(mode): | |
46 mach_environment = os.environ.copy() | |
47 mach_environment["MOZCONFIG"] = find_mozconfig(mode) | |
48 subprocess.check_call([MACH_PATH, "clobber"], env=mach_environment) | |
49 subprocess.check_call([MACH_PATH, "build"], env=mach_environment) | |
50 subprocess.check_call([MACH_PATH, "package"], env=mach_environment) | |
51 | |
52 [manifest_path] = glob.glob(os.path.join( | |
53 DIST_PATH, "fennec-*.en-US.android-arm.json")) | |
54 with open(manifest_path) as manifest_file: | |
55 manifest = json.load(manifest_file) | |
56 | |
57 apk_path = os.path.join(DIST_PATH, "gecko-unsigned-unaligned.apk") | |
58 if mode == "release": | |
59 target_apk_name = "adblockbrowser-%s-arm.apk" % manifest["moz_app_version"] | |
60 else: | |
61 target_apk_name = "adblockbrowser-%s.%s-arm.apk" % ( | |
62 manifest["moz_app_version"], manifest["buildid"]) | |
63 target_apk_path = os.path.join(DIST_PATH, target_apk_name) | |
64 shutil.copyfile(apk_path, target_apk_path) | |
65 return target_apk_path | |
66 | |
67 def sign(apk_path, key_store, key_name): | |
68 temp_apk_path = tempfile.NamedTemporaryFile().name | |
69 shutil.copyfile(apk_path, temp_apk_path) | |
70 try: | |
71 subprocess.check_call(["jarsigner", "-verbose", "-sigalg", "SHA1withRSA", | |
72 "-digestalg", "SHA1", "-keystore", key_store, | |
73 temp_apk_path, key_name]) | |
74 os.remove(apk_path) | |
75 subprocess.check_call(["zipalign", "-v", "4", temp_apk_path, apk_path]) | |
76 finally: | |
77 os.remove(temp_apk_path) | |
78 | |
79 if __name__ == "__main__": | |
80 if len(sys.argv) < 4: | |
81 print_usage() | |
82 sys.exit(1) | |
83 | |
84 mode, key_store, key_name = sys.argv[1:] | |
85 if mode not in ("devbuild", "release"): | |
86 print_usage() | |
87 sys.exit(2) | |
88 | |
89 subprocess.call([ENSURE_DEPENDENCIES_PATH]) | |
René Jeschke
2015/05/19 09:57:54
Shouldn't we use 'check_call' here, too? Or is a '
Felix Dahlke
2015/05/19 15:54:35
Yes you're right. I did this by design, but for a
| |
90 apk_path = build(mode) | |
91 sign(apk_path, key_store, key_name) | |
OLD | NEW |