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 re | 6 import re |
7 import shutil | 7 import shutil |
8 import string | 8 import string |
9 import subprocess | 9 import subprocess |
10 import sys | 10 import sys |
11 import tempfile | 11 import tempfile |
12 | 12 |
13 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | 13 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
14 ENSURE_DEPENDENCIES_PATH = os.path.join(BASE_DIR, "ensure_dependencies.py") | 14 ENSURE_DEPENDENCIES_PATH = os.path.join(BASE_DIR, "ensure_dependencies.py") |
| 15 GENERATED_MOZCONFIG_PATH = os.path.join(BASE_DIR, "generated", "mozconfig") |
| 16 MOZCONFIG_COMMON_PATH = os.path.join(BASE_DIR, "mozconfig-common") |
| 17 MOZCONFIG_ARM_PATH = os.path.join(BASE_DIR, "mozconfig-arm") |
| 18 MOZCONFIG_X86_PATH = os.path.join(BASE_DIR, "mozconfig-x86") |
| 19 MOZCONFIG_STORE_PATH = os.path.join(BASE_DIR, "mozconfig-store") |
| 20 MOZCONFIG_RELEASE_PATH = os.path.join(BASE_DIR, "mozconfig-release") |
| 21 MOZCONFIG_CUSTOM_PATH = os.path.join(BASE_DIR, "mozconfig-custom") |
15 MULTI_L10N_PATH = os.path.join(BASE_DIR, "mozharness", "scripts", | 22 MULTI_L10N_PATH = os.path.join(BASE_DIR, "mozharness", "scripts", |
16 "multil10n.py") | 23 "multil10n.py") |
17 ABB_PATH = os.path.join(BASE_DIR, "adblockbrowser") | 24 ABB_PATH = os.path.join(BASE_DIR, "adblockbrowser") |
18 DIST_PATH = os.path.join(ABB_PATH, "obj-arm-linux-androideabi", "dist") | 25 ARCH_ARM = "arm" |
| 26 ARCH_X86 = "x86" |
| 27 ARCH_X86_I386 = "i386" |
| 28 DIST_STORE = "store" |
| 29 BUILD_RELEASE = "release" |
| 30 OBJDIR_ARM = "obj-arm-linux-androideabi" |
| 31 OBJDIR_X86 = "obj-i386-linux-android" |
19 | 32 |
20 | 33 |
21 def print_usage(): | 34 def print_usage(): |
22 print >>sys.stderr, string.Template("""\ | 35 print >>sys.stderr, string.Template("""\ |
23 Usage: $name build | 36 Usage: $name build |
24 $name sign APK_PATH | 37 $name sign APK_PATH |
25 $name build-and-sign\ | 38 $name build-and-sign\ |
26 """).substitute({"name": os.path.basename(sys.argv[0])}) | 39 """).substitute({"name": os.path.basename(sys.argv[0])}) |
27 | 40 |
28 | 41 |
29 def check_mozconfig(path, distribution_mode, build_mode): | 42 def generate_mozconfig(architecture, distribution_mode, build_mode): |
30 if not os.path.exists(path): | 43 mozconfig_path = GENERATED_MOZCONFIG_PATH |
31 raise Exception("'%s' doesn't exist, please create it." % path) | 44 with open(mozconfig_path, "w+") as mozconfig: |
32 | 45 mozconfig.write(". \"%s\"\n" % MOZCONFIG_COMMON_PATH) |
33 with open(path) as file: | 46 if architecture == ARCH_X86: |
34 contents = file.read() | 47 mozconfig.write(". \"%s\"\n" % MOZCONFIG_X86_PATH) |
35 | 48 else: |
36 # This check can be removed once https://issues.adblockplus.org/ticket/2490
is | 49 mozconfig.write(". \"%s\"\n" % MOZCONFIG_ARM_PATH) |
37 # done. | 50 if distribution_mode == DIST_STORE: |
38 if "--disable-crashreporter" not in contents: | 51 mozconfig.write(". \"%s\"\n" % MOZCONFIG_STORE_PATH) |
39 raise Exception( | 52 if build_mode == BUILD_RELEASE: |
40 "'%s' doesn't seem to set --disable-crashreporter, please do." % pat
h) | 53 mozconfig.write(". \"%s\"\n" % MOZCONFIG_RELEASE_PATH) |
41 | 54 mozconfig.write(". \"%s\"\n" % MOZCONFIG_CUSTOM_PATH) |
42 if "export MOZILLA_OFFICIAL=1" not in contents: | 55 return mozconfig_path |
43 raise Exception( | |
44 "'%s' doesn't seem to export MOZILLA_OFFICIAL=1, please do." % path) | |
45 | |
46 updater_disabled = "--disable-updater" in contents | |
47 if updater_disabled and distribution_mode == "standalone": | |
48 raise Exception("'%s' seems to set --disable-updater, please don't." % p
ath) | |
49 elif not updater_disabled and distribution_mode == "store": | |
50 raise Exception( | |
51 "'%s' doesn't seem to set --disable-updater, please do." % path) | |
52 | |
53 release_build = "export ABB_RELEASE_BUILD=1" in contents | |
54 if release_build and build_mode != "release": | |
55 raise Exception("'%s' shouldn't export ABB_RELEASE_BUILD=1." % path) | |
56 elif not release_build and build_mode == "release": | |
57 raise Exception("'%s' should export ABB_RELEASE_BUILD=1." % path) | |
58 | 56 |
59 | 57 |
60 def find_mozconfig(distribution_mode, build_mode): | 58 def build(architecture, distribution_mode, build_mode, sdk_path, ndk_path): |
61 mozconfig_path = os.path.join(BASE_DIR, "mozconfig-" + distribution_mode + | |
62 "-" + build_mode) | |
63 check_mozconfig(mozconfig_path, distribution_mode, build_mode) | |
64 return mozconfig_path | |
65 | |
66 | |
67 def build(distribution_mode, build_mode, sdk_path, ndk_path): | |
68 build_environment = os.environ.copy() | 59 build_environment = os.environ.copy() |
69 build_environment["MOZCONFIG"] = find_mozconfig(distribution_mode, build_mod
e) | 60 build_environment["MOZCONFIG"] = generate_mozconfig( |
| 61 architecture, distribution_mode, build_mode) |
70 build_environment["ANDROID_SDK_PATH"] = sdk_path | 62 build_environment["ANDROID_SDK_PATH"] = sdk_path |
71 build_environment["ANDROID_NDK_PATH"] = ndk_path | 63 build_environment["ANDROID_NDK_PATH"] = ndk_path |
| 64 obj_dir = OBJDIR_X86 if architecture == ARCH_X86 else OBJDIR_ARM |
| 65 build_environment["OBJDIR"] = obj_dir |
72 subprocess.check_call([os.path.join(ABB_PATH, "mach"), "clobber"], | 66 subprocess.check_call([os.path.join(ABB_PATH, "mach"), "clobber"], |
73 env=build_environment) | 67 env=build_environment) |
74 subprocess.check_call([MULTI_L10N_PATH, "--cfg", "adblockbrowser-cfg.py"], | 68 subprocess.check_call([MULTI_L10N_PATH, "--cfg", "adblockbrowser-cfg.py"], |
75 env=build_environment) | 69 env=build_environment) |
76 | 70 |
| 71 dist_path = os.path.join(ABB_PATH, obj_dir, "dist") |
| 72 arch_suffix = ARCH_X86_I386 if architecture == ARCH_X86 else ARCH_ARM |
77 [manifest_path] = glob.glob(os.path.join( | 73 [manifest_path] = glob.glob(os.path.join( |
78 DIST_PATH, "fennec-*.multi.android-arm.json")) | 74 dist_path, "fennec-*.multi.android-%s.json" % arch_suffix)) |
79 with open(manifest_path) as manifest_file: | 75 with open(manifest_path) as manifest_file: |
80 manifest = json.load(manifest_file) | 76 manifest = json.load(manifest_file) |
81 | 77 |
82 apk_path = os.path.join(DIST_PATH, "gecko-unsigned-unaligned.apk") | 78 apk_path = os.path.join(dist_path, "gecko-unsigned-unaligned.apk") |
83 if build_mode == "release": | 79 if build_mode == "release": |
84 target_apk_name = "adblockbrowser-%s-arm.apk" % manifest["moz_app_versio
n"] | 80 target_apk_name = "adblockbrowser-%s-%s.apk" % ( |
| 81 manifest["moz_app_version"], architecture) |
85 else: | 82 else: |
86 target_apk_name = "adblockbrowser-%s.%s-arm.apk" % ( | 83 target_apk_name = "adblockbrowser-%s.%s-%s.apk" % ( |
87 manifest["moz_app_version"], manifest["buildid"]) | 84 manifest["moz_app_version"], manifest["buildid"], architecture) |
88 target_apk_path = os.path.join(DIST_PATH, target_apk_name) | 85 target_apk_path = os.path.join(dist_path, target_apk_name) |
89 shutil.copyfile(apk_path, target_apk_path) | 86 shutil.copyfile(apk_path, target_apk_path) |
90 | 87 |
91 target_manifest_path = re.sub(r".apk$", ".json", target_apk_path) | 88 target_manifest_path = re.sub(r".apk$", ".json", target_apk_path) |
92 shutil.copyfile(manifest_path, target_manifest_path) | 89 shutil.copyfile(manifest_path, target_manifest_path) |
93 | 90 |
94 return target_apk_path | 91 return target_apk_path |
95 | 92 |
96 | 93 |
97 def sign(apk_path, key_store, key_name): | 94 def sign(apk_path, key_store, key_name): |
98 temp_apk_path = tempfile.NamedTemporaryFile().name | 95 temp_apk_path = tempfile.NamedTemporaryFile().name |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 distribution_mode = config.DISTRIBUTION_MODE | 127 distribution_mode = config.DISTRIBUTION_MODE |
131 if distribution_mode not in ("standalone", "store"): | 128 if distribution_mode not in ("standalone", "store"): |
132 print >>sys.stderr, "Invalid distribution mode, check config.py" | 129 print >>sys.stderr, "Invalid distribution mode, check config.py" |
133 sys.exit(4) | 130 sys.exit(4) |
134 | 131 |
135 build_mode = config.BUILD_MODE | 132 build_mode = config.BUILD_MODE |
136 if build_mode not in ("devbuild", "release"): | 133 if build_mode not in ("devbuild", "release"): |
137 print >>sys.stderr, "Invalid build mode, check config.py" | 134 print >>sys.stderr, "Invalid build mode, check config.py" |
138 sys.exit(5) | 135 sys.exit(5) |
139 | 136 |
| 137 architecture = config.ARCHITECTURE |
| 138 if architecture not in (ARCH_ARM, ARCH_X86): |
| 139 print >>sys.stderr, "Invalid architecture, check config.py" |
| 140 sys.exit(6) |
| 141 |
140 if do_build: | 142 if do_build: |
141 apk_path = build(distribution_mode, build_mode, config.ANDROID_SDK_PATH, | 143 apk_path = build(architecture, distribution_mode, build_mode, |
142 config.ANDROID_NDK_PATH) | 144 config.ANDROID_SDK_PATH, config.ANDROID_NDK_PATH) |
143 if do_sign: | 145 if do_sign: |
144 sign(apk_path, config.ANDROID_KEYSTORE_PATH, config.ANDROID_KEY_NAME) | 146 sign(apk_path, config.ANDROID_KEYSTORE_PATH, config.ANDROID_KEY_NAME) |
145 else: | 147 else: |
146 print apk_path | 148 print apk_path |
OLD | NEW |