OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 import glob | 3 import glob |
4 import json | 4 import json |
5 import os | 5 import os |
6 import shutil | 6 import shutil |
7 import string | 7 import string |
8 import subprocess | 8 import subprocess |
9 import sys | 9 import sys |
10 import tempfile | 10 import tempfile |
11 | 11 |
12 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | 12 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
13 ENSURE_DEPENDENCIES_PATH = os.path.join(BASE_DIR, "ensure_dependencies.py") | 13 ENSURE_DEPENDENCIES_PATH = os.path.join(BASE_DIR, "ensure_dependencies.py") |
14 MULTI_L10N_PATH = os.path.join(BASE_DIR, "mozharness", "scripts", | 14 MULTI_L10N_PATH = os.path.join(BASE_DIR, "mozharness", "scripts", |
15 "multil10n.py") | 15 "multil10n.py") |
16 DIST_PATH = os.path.join(BASE_DIR, "adblockbrowser", | 16 DIST_PATH = os.path.join(BASE_DIR, "adblockbrowser", |
17 "obj-arm-linux-androideabi", "dist") | 17 "obj-arm-linux-androideabi", "dist") |
18 | 18 |
19 def print_usage(): | 19 def print_usage(): |
20 print >>sys.stderr, string.Template("""\ | 20 print >>sys.stderr, string.Template("""\ |
21 Usage: $name build devbuild|release | 21 Usage: $name build devbuild|release standalone|store |
22 $name sign APK_PATH | 22 $name sign APK_PATH |
23 $name build-and-sign devbuild|release\ | 23 $name build-and-sign devbuild|release standalone|store\ |
24 """).substitute({"name": os.path.basename(sys.argv[0])}) | 24 """).substitute({"name": os.path.basename(sys.argv[0])}) |
25 | 25 |
26 def check_mozconfig(path, mode): | 26 def check_mozconfig(path, distribution_mode): |
27 if not os.path.exists(path): | 27 if not os.path.exists(path): |
28 raise Exception("'%s' doesn't exist, please create it." % path) | 28 raise Exception("'%s' doesn't exist, please create it." % path) |
29 | 29 |
30 with open(path) as file: | 30 with open(path) as file: |
31 contents = file.read() | 31 contents = file.read() |
32 | 32 |
33 # This check can be removed once https://issues.adblockplus.org/ticket/2490 is | 33 # This check can be removed once https://issues.adblockplus.org/ticket/2490 is |
34 # done. | 34 # done. |
35 if "--disable-crashreporter" not in contents: | 35 if "--disable-crashreporter" not in contents: |
36 raise Exception( | 36 raise Exception( |
37 "'%s' doesn't seem to set --disable-crashreporter, please do." % path) | 37 "'%s' doesn't seem to set --disable-crashreporter, please do." % path) |
38 | 38 |
39 if "export MOZILLA_OFFICIAL=1" not in contents: | 39 if "export MOZILLA_OFFICIAL=1" not in contents: |
40 raise Exception( | 40 raise Exception( |
41 "'%s' doesn't seem to export MOZILLA_OFFICIAL=1, please do." % path) | 41 "'%s' doesn't seem to export MOZILLA_OFFICIAL=1, please do." % path) |
42 | 42 |
43 updater_disabled = "--disable-updater" in contents | 43 updater_disabled = "--disable-updater" in contents |
44 if updater_disabled and mode == "devbuild": | 44 if updater_disabled and distribution_mode == "standalone": |
45 raise Exception("'%s' seems to set --disable-updater, please don't." % path) | 45 raise Exception("'%s' seems to set --disable-updater, please don't." % path) |
46 elif not updater_disabled and mode == "release": | 46 elif not updater_disabled and distribution_mode == "store": |
47 raise Exception( | 47 raise Exception( |
48 "'%s' doesn't seem to set --disable-updater, please do." % path) | 48 "'%s' doesn't seem to set --disable-updater, please do." % path) |
49 | 49 |
50 def find_mozconfig(mode): | 50 def find_mozconfig(mode): |
51 mozconfig_path = os.path.join(BASE_DIR, "mozconfig-" + mode) | 51 mozconfig_path = os.path.join(BASE_DIR, "mozconfig-" + mode) |
52 check_mozconfig(mozconfig_path, mode) | 52 check_mozconfig(mozconfig_path, mode) |
53 return mozconfig_path | 53 return mozconfig_path |
54 | 54 |
55 def build(mode, sdk_path, ndk_path): | 55 def build(build_mode, distribution_mode, sdk_path, ndk_path): |
56 mozharness_environment = os.environ.copy() | 56 mozharness_environment = os.environ.copy() |
57 mozharness_environment["MOZCONFIG"] = find_mozconfig(mode) | 57 mozharness_environment["MOZCONFIG"] = find_mozconfig(distribution_mode) |
58 mozharness_environment["ANDROID_SDK_PATH"] = sdk_path | 58 mozharness_environment["ANDROID_SDK_PATH"] = sdk_path |
59 mozharness_environment["ANDROID_NDK_PATH"] = ndk_path | 59 mozharness_environment["ANDROID_NDK_PATH"] = ndk_path |
60 | 60 |
61 subprocess.check_call([MULTI_L10N_PATH, "--cfg", "adblockbrowser-cfg.py"], | 61 subprocess.check_call([MULTI_L10N_PATH, "--cfg", "adblockbrowser-cfg.py"], |
62 env=mozharness_environment) | 62 env=mozharness_environment) |
63 | 63 |
64 [manifest_path] = glob.glob(os.path.join( | 64 [manifest_path] = glob.glob(os.path.join( |
65 DIST_PATH, "fennec-*.multi.android-arm.json")) | 65 DIST_PATH, "fennec-*.multi.android-arm.json")) |
66 with open(manifest_path) as manifest_file: | 66 with open(manifest_path) as manifest_file: |
67 manifest = json.load(manifest_file) | 67 manifest = json.load(manifest_file) |
68 | 68 |
69 apk_path = os.path.join(DIST_PATH, "gecko-unsigned-unaligned.apk") | 69 apk_path = os.path.join(DIST_PATH, "gecko-unsigned-unaligned.apk") |
70 if mode == "release": | 70 if build_mode == "release": |
71 target_apk_name = "adblockbrowser-%s-arm.apk" % manifest["moz_app_version"] | 71 target_apk_name = "adblockbrowser-%s-arm.apk" % manifest["moz_app_version"] |
72 else: | 72 else: |
73 target_apk_name = "adblockbrowser-%s.%s-arm.apk" % ( | 73 target_apk_name = "adblockbrowser-%s.%s-arm.apk" % ( |
74 manifest["moz_app_version"], manifest["buildid"]) | 74 manifest["moz_app_version"], manifest["buildid"]) |
75 target_apk_path = os.path.join(DIST_PATH, target_apk_name) | 75 target_apk_path = os.path.join(DIST_PATH, target_apk_name) |
76 shutil.copyfile(apk_path, target_apk_path) | 76 shutil.copyfile(apk_path, target_apk_path) |
77 return target_apk_path | 77 return target_apk_path |
78 | 78 |
79 def sign(apk_path, key_store, key_name): | 79 def sign(apk_path, key_store, key_name): |
80 temp_apk_path = tempfile.NamedTemporaryFile().name | 80 temp_apk_path = tempfile.NamedTemporaryFile().name |
(...skipping 17 matching lines...) Expand all Loading... |
98 do_sign = mode in ("sign", "build-and-sign") | 98 do_sign = mode in ("sign", "build-and-sign") |
99 if not do_build and not do_sign: | 99 if not do_build and not do_sign: |
100 print_usage() | 100 print_usage() |
101 sys.exit(2) | 101 sys.exit(2) |
102 | 102 |
103 if do_build: | 103 if do_build: |
104 build_mode = sys.argv[2] | 104 build_mode = sys.argv[2] |
105 if build_mode not in ("devbuild", "release"): | 105 if build_mode not in ("devbuild", "release"): |
106 print_usage() | 106 print_usage() |
107 sys.exit(3) | 107 sys.exit(3) |
| 108 distribution_mode = len(sys.argv) > 3 and sys.argv[3] or "" |
| 109 if distribution_mode not in ("standalone", "store"): |
| 110 print_usage() |
| 111 sys.exit(4) |
108 | 112 |
109 if do_sign: | 113 if do_sign: |
110 apk_path = sys.argv[2] | 114 apk_path = sys.argv[2] |
111 | 115 |
112 subprocess.check_call([ENSURE_DEPENDENCIES_PATH]) | 116 subprocess.check_call([ENSURE_DEPENDENCIES_PATH]) |
113 import config | 117 import config |
114 | 118 |
115 if do_build: | 119 if do_build: |
116 apk_path = build(build_mode, config.ANDROID_SDK_PATH, | 120 apk_path = build(build_mode, distribution_mode, config.ANDROID_SDK_PATH, |
117 config.ANDROID_NDK_PATH) | 121 config.ANDROID_NDK_PATH) |
118 if do_sign: | 122 if do_sign: |
119 sign(apk_path, config.ANDROID_KEYSTORE_PATH, config.ANDROID_KEY_NAME) | 123 sign(apk_path, config.ANDROID_KEYSTORE_PATH, config.ANDROID_KEY_NAME) |
120 else: | 124 else: |
121 print apk_path | 125 print apk_path |
OLD | NEW |