OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | |
3 # This file is part of Adblock Plus <https://adblockplus.org/>, | 2 # This file is part of Adblock Plus <https://adblockplus.org/>, |
4 # Copyright (C) 2006-present eyeo GmbH | 3 # Copyright (C) 2006-present eyeo GmbH |
5 # | 4 # |
6 # Adblock Plus is free software: you can redistribute it and/or modify | 5 # Adblock Plus is free software: you can redistribute it and/or modify |
7 # it under the terms of the GNU General Public License version 3 as | 6 # it under the terms of the GNU General Public License version 3 as |
8 # published by the Free Software Foundation. | 7 # published by the Free Software Foundation. |
9 # | 8 # |
10 # Adblock Plus is distributed in the hope that it will be useful, | 9 # Adblock Plus is distributed in the hope that it will be useful, |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
(...skipping 16 matching lines...) Expand all Loading... |
29 _ABB_PATH = os.path.normpath(os.path.join(_BASE_DIR, "..")) | 28 _ABB_PATH = os.path.normpath(os.path.join(_BASE_DIR, "..")) |
30 _ENSURE_DEPENDENCIES_PATH = os.path.join(_ABB_PATH, "ensure_dependencies.py") | 29 _ENSURE_DEPENDENCIES_PATH = os.path.join(_ABB_PATH, "ensure_dependencies.py") |
31 _GENERATED_PATH = os.path.join(_BASE_DIR, "generated") | 30 _GENERATED_PATH = os.path.join(_BASE_DIR, "generated") |
32 _GENERATED_MOZCONFIG_PATH = os.path.join(_GENERATED_PATH, "mozconfig") | 31 _GENERATED_MOZCONFIG_PATH = os.path.join(_GENERATED_PATH, "mozconfig") |
33 _MOZCONFIG_COMMON_PATH = os.path.join(_BASE_DIR, "mozconfig-common") | 32 _MOZCONFIG_COMMON_PATH = os.path.join(_BASE_DIR, "mozconfig-common") |
34 _MOZCONFIG_ARM_PATH = os.path.join(_BASE_DIR, "mozconfig-arm") | 33 _MOZCONFIG_ARM_PATH = os.path.join(_BASE_DIR, "mozconfig-arm") |
35 _MOZCONFIG_X86_PATH = os.path.join(_BASE_DIR, "mozconfig-x86") | 34 _MOZCONFIG_X86_PATH = os.path.join(_BASE_DIR, "mozconfig-x86") |
36 _MOZCONFIG_STORE_PATH = os.path.join(_BASE_DIR, "mozconfig-store") | 35 _MOZCONFIG_STORE_PATH = os.path.join(_BASE_DIR, "mozconfig-store") |
37 _MOZCONFIG_RELEASE_PATH = os.path.join(_BASE_DIR, "mozconfig-release") | 36 _MOZCONFIG_RELEASE_PATH = os.path.join(_BASE_DIR, "mozconfig-release") |
38 _MOZCONFIG_CUSTOM_PATH = os.path.join(_BASE_DIR, "mozconfig-custom") | 37 _MOZCONFIG_CUSTOM_PATH = os.path.join(_BASE_DIR, "mozconfig-custom") |
39 _MULTI_L10N_PATH = os.path.join(_BASE_DIR, "mozharness", "scripts", | 38 _MAEMO_LOCALES_PATH = os.path.join(_ABB_PATH, "mobile", "android", "locales", |
40 "multil10n.py") | 39 "maemo-locales") |
| 40 |
| 41 _L10N_BASE_PATH = os.path.join(_BASE_DIR, "l10n-central") |
| 42 _LOCALE_CHANGESETS_PATH = os.path.join(_ABB_PATH, "mobile", "locales", |
| 43 "l10n-changesets.json") |
41 | 44 |
42 _CMD_BUILD = "build" | 45 _CMD_BUILD = "build" |
43 _CMD_SIGN = "sign" | 46 _CMD_SIGN = "sign" |
44 _CMD_BUILD_SIGN = "build-and-sign" | 47 _CMD_BUILD_SIGN = "build-and-sign" |
45 _ARCH_ARM = "arm" | 48 _ARCH_ARM = "arm" |
46 _ARCH_X86 = "x86" | 49 _ARCH_X86 = "x86" |
47 _ARCH_X86_I386 = "i386" | 50 _ARCH_X86_I386 = "i386" |
48 _ARCHS = (_ARCH_ARM, _ARCH_X86) | 51 _ARCHS = (_ARCH_ARM, _ARCH_X86) |
49 _DIST_STANDALONE = "standalone" | 52 _DIST_STANDALONE = "standalone" |
50 _DIST_STORE = "store" | 53 _DIST_STORE = "store" |
51 _DIST_MODES = (_DIST_STANDALONE, _DIST_STORE) | 54 _DIST_MODES = (_DIST_STANDALONE, _DIST_STORE) |
52 _BUILD_DEVBUILD = "devbuild" | 55 _BUILD_DEVBUILD = "devbuild" |
53 _BUILD_RELEASE = "release" | 56 _BUILD_RELEASE = "release" |
54 _BUILD_MODES = (_BUILD_DEVBUILD, _BUILD_RELEASE) | 57 _BUILD_MODES = (_BUILD_DEVBUILD, _BUILD_RELEASE) |
55 _OBJDIR_ARM = "obj-arm-linux-androideabi" | 58 _OBJDIR_ARM = "obj-arm-linux-androideabi" |
56 _OBJDIR_X86 = "obj-i386-linux-android" | 59 _OBJDIR_X86 = "obj-i386-linux-android" |
57 | 60 |
58 | 61 |
59 def print_usage(): | 62 def _print_usage(): |
60 print >>sys.stderr, string.Template("""\ | 63 print >>sys.stderr, string.Template("""\ |
61 Usage: $name %s | 64 Usage: $name %s |
62 $name %s APK_PATH | 65 $name %s APK_PATH |
63 $name %s\ | 66 $name %s\ |
64 """ % (_CMD_BUILD, _CMD_SIGN, | 67 """ % (_CMD_BUILD, _CMD_SIGN, |
65 _CMD_BUILD_SIGN)).substitute({"name": os.path.basename(sys.argv[0])}) | 68 _CMD_BUILD_SIGN)).substitute({"name": os.path.basename(sys.argv[0])}) |
66 | 69 |
67 | 70 |
68 def _generate_mozconfig(architecture, distribution_mode, build_mode): | 71 def _generate_mozconfig(architecture, distribution_mode, build_mode): |
69 if not os.path.exists(_GENERATED_PATH): | 72 if not os.path.exists(_GENERATED_PATH): |
70 os.makedirs(_GENERATED_PATH) | 73 os.makedirs(_GENERATED_PATH) |
| 74 |
71 with open(_GENERATED_MOZCONFIG_PATH, "w+") as mozconfig: | 75 with open(_GENERATED_MOZCONFIG_PATH, "w+") as mozconfig: |
72 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_COMMON_PATH) | 76 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_COMMON_PATH) |
73 if architecture == _ARCH_X86: | 77 if architecture == _ARCH_X86: |
74 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_X86_PATH) | 78 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_X86_PATH) |
75 else: | 79 else: |
76 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_ARM_PATH) | 80 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_ARM_PATH) |
77 if distribution_mode == _DIST_STORE: | 81 if distribution_mode == _DIST_STORE: |
78 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_STORE_PATH) | 82 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_STORE_PATH) |
79 if build_mode == _BUILD_RELEASE: | 83 if build_mode == _BUILD_RELEASE: |
80 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_RELEASE_PATH) | 84 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_RELEASE_PATH) |
81 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_CUSTOM_PATH) | 85 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_CUSTOM_PATH) |
82 return _GENERATED_MOZCONFIG_PATH | 86 return _GENERATED_MOZCONFIG_PATH |
83 | 87 |
84 | 88 |
85 def _build(architecture, distribution_mode, build_mode, sdk_path, ndk_path): | 89 def _checkout_l10n(): |
86 build_environment = os.environ.copy() | 90 with open(_LOCALE_CHANGESETS_PATH, "r") as fd: |
87 build_environment["ANDROID_SDK_PATH"] = sdk_path | 91 changesets = json.load(fd) |
88 build_environment["ANDROID_NDK_PATH"] = ndk_path | |
89 build_environment["MOZCONFIG"] = _generate_mozconfig( | |
90 architecture, distribution_mode, build_mode) | |
91 obj_dir = _OBJDIR_X86 if architecture == _ARCH_X86 else _OBJDIR_ARM | |
92 build_environment["OBJDIR"] = obj_dir | |
93 subprocess.check_call([os.path.join(_ABB_PATH, "mach"), "clobber"], | |
94 env=build_environment) | |
95 subprocess.check_call([_MULTI_L10N_PATH, "--cfg", "adblockbrowser-cfg.py"], | |
96 env=build_environment) | |
97 | 92 |
| 93 if not os.path.exists(_L10N_BASE_PATH): |
| 94 os.makedirs(_L10N_BASE_PATH) |
| 95 |
| 96 l10n_base_repo = "https://hg.mozilla.org/l10n-central/%s/" |
| 97 for locale in changesets.keys(): |
| 98 revision = changesets[locale]["revision"] |
| 99 repo_path = os.path.join(_L10N_BASE_PATH, locale) |
| 100 if os.path.exists(repo_path): |
| 101 update_cmd = ["hg", "up", "-r", revision] |
| 102 if subprocess.call(update_cmd, cwd=repo_path): |
| 103 subprocess.check_call(["hg", "pull"], cwd=repo_path) |
| 104 subprocess.check_call(update_cmd, cwd=repo_path) |
| 105 |
| 106 else: |
| 107 repo = l10n_base_repo % locale |
| 108 subprocess.check_call(["hg", "clone", repo, "-r", revision], |
| 109 cwd=_L10N_BASE_PATH) |
| 110 |
| 111 |
| 112 def _read_locales(): |
| 113 with open(_MAEMO_LOCALES_PATH, "r") as fd: |
| 114 lines = fd.readlines() |
| 115 |
| 116 return [line.strip() for line in lines] |
| 117 |
| 118 |
| 119 def _config_build_env(architecture, distribution_mode, build_mode, sdk_path, |
| 120 ndk_path, obj_dir, locales): |
| 121 build_env = os.environ.copy() |
| 122 build_env["ANDROID_SDK_PATH"] = sdk_path |
| 123 build_env["ANDROID_NDK_PATH"] = ndk_path |
| 124 mozconfig_path = _generate_mozconfig(architecture, distribution_mode, |
| 125 build_mode) |
| 126 |
| 127 build_env["MOZCONFIG"] = mozconfig_path |
| 128 build_env["OBJDIR"] = obj_dir |
| 129 build_env["L10NBASEDIR"] = _L10N_BASE_PATH |
| 130 build_env["MOZ_CHROME_MULTILOCALE"] = ' '.join(locales) |
| 131 build_env["AB_CD"] = "multi" |
| 132 return build_env |
| 133 |
| 134 |
| 135 def _create_target_apk(architecture, distribution_mode, build_mode, obj_dir): |
98 dist_path = os.path.join(_ABB_PATH, obj_dir, "dist") | 136 dist_path = os.path.join(_ABB_PATH, obj_dir, "dist") |
99 arch_suffix = _ARCH_X86_I386 if architecture == _ARCH_X86 else _ARCH_ARM | 137 arch_suffix = _ARCH_X86_I386 if architecture == _ARCH_X86 else _ARCH_ARM |
100 [manifest_path] = glob.glob(os.path.join( | 138 [manifest_path] = glob.glob(os.path.join( |
101 dist_path, "fennec-*.multi.android-%s.json" % arch_suffix)) | 139 dist_path, "fennec-*.en-US.android-%s.json" % arch_suffix)) |
| 140 |
102 with open(manifest_path) as manifest_file: | 141 with open(manifest_path) as manifest_file: |
103 manifest = json.load(manifest_file) | 142 manifest = json.load(manifest_file) |
104 apk_name = "fennec-%s.multi.android-%s-unsigned-unaligned.apk" % ( | 143 |
105 manifest["moz_app_version"], arch_suffix) | 144 apk_name = "fennec-%s.en-US.android-%s-unsigned-unaligned.apk" % ( |
| 145 manifest["moz_app_version"], arch_suffix) |
| 146 |
106 apk_path = os.path.join(dist_path, apk_name) | 147 apk_path = os.path.join(dist_path, apk_name) |
107 build_suffix = ("-%s" % manifest["buildid"] | 148 build_suffix = ("-%s" % manifest["buildid"] |
108 if build_mode == _BUILD_DEVBUILD | 149 if build_mode == _BUILD_DEVBUILD |
109 else "") | 150 else "") |
| 151 |
110 dist_suffix = ("-%s" % _DIST_STANDALONE | 152 dist_suffix = ("-%s" % _DIST_STANDALONE |
111 if distribution_mode == _DIST_STANDALONE | 153 if distribution_mode == _DIST_STANDALONE |
112 else "") | 154 else "") |
| 155 |
113 target_apk_name = "adblockbrowser-%s%s-%s%s.apk" % ( | 156 target_apk_name = "adblockbrowser-%s%s-%s%s.apk" % ( |
114 manifest["moz_app_version"], build_suffix, architecture, dist_suffix) | 157 manifest["moz_app_version"], build_suffix, architecture, dist_suffix) |
| 158 |
115 target_apk_path = os.path.join(dist_path, target_apk_name) | 159 target_apk_path = os.path.join(dist_path, target_apk_name) |
116 shutil.copyfile(apk_path, target_apk_path) | 160 shutil.copyfile(apk_path, target_apk_path) |
117 | |
118 target_manifest_path = re.sub(r".apk$", ".json", target_apk_path) | 161 target_manifest_path = re.sub(r".apk$", ".json", target_apk_path) |
119 shutil.copyfile(manifest_path, target_manifest_path) | 162 shutil.copyfile(manifest_path, target_manifest_path) |
| 163 return target_apk_path |
120 | 164 |
121 return target_apk_path | 165 |
| 166 def _build(architecture, distribution_mode, build_mode, sdk_path, ndk_path): |
| 167 _checkout_l10n() |
| 168 obj_dir = _OBJDIR_X86 if architecture == _ARCH_X86 else _OBJDIR_ARM |
| 169 locales = _read_locales() |
| 170 build_env = _config_build_env(architecture, distribution_mode, build_mode, |
| 171 sdk_path, ndk_path, obj_dir, locales) |
| 172 |
| 173 mach_path = os.path.join(_ABB_PATH, "mach") |
| 174 subprocess.check_call([mach_path, "clobber"], env=build_env, cwd=_ABB_PATH) |
| 175 subprocess.check_call([mach_path, "build"], env=build_env, cwd=_ABB_PATH) |
| 176 for locale in locales: |
| 177 chrome_str = "chrome-%s" % locale |
| 178 subprocess.check_call([mach_path, "build", chrome_str], env=build_env, |
| 179 cwd=_ABB_PATH) |
| 180 |
| 181 obj_dir_path = os.path.join(_ABB_PATH, obj_dir) |
| 182 import transform_locales as tl |
| 183 tl.transform_locales(_ABB_PATH, obj_dir_path) |
| 184 subprocess.check_call([mach_path, "package"], env=build_env, cwd=_ABB_PATH) |
| 185 return _create_target_apk(architecture, distribution_mode, build_mode, |
| 186 obj_dir) |
122 | 187 |
123 | 188 |
124 def _sign(apk_path, key_store, key_name, sdk_path): | 189 def _sign(apk_path, key_store, key_name, sdk_path): |
125 sys.path.append(os.path.join(_ABB_PATH, "python", "mozboot", "mozboot")) | 190 sys.path.append(os.path.join(_ABB_PATH, "python", "mozboot", "mozboot")) |
126 from android import ANDROID_BUILD_TOOLS_VERSION | 191 from android import ANDROID_BUILD_TOOLS_VERSION |
127 zipalign_path = os.path.join(sdk_path, "build-tools", | 192 zipalign_path = os.path.join(sdk_path, "build-tools", |
128 ANDROID_BUILD_TOOLS_VERSION, "zipalign") | 193 ANDROID_BUILD_TOOLS_VERSION, "zipalign") |
| 194 |
129 temp_apk_path = tempfile.NamedTemporaryFile().name | 195 temp_apk_path = tempfile.NamedTemporaryFile().name |
130 shutil.copyfile(apk_path, temp_apk_path) | 196 shutil.copyfile(apk_path, temp_apk_path) |
131 try: | 197 try: |
132 subprocess.check_call(["jarsigner", "-verbose", | 198 subprocess.check_call(["jarsigner", "-verbose", |
133 "-sigalg", "SHA1withRSA", | 199 "-sigalg", "SHA1withRSA", |
134 "-digestalg", "SHA1", | 200 "-digestalg", "SHA1", |
135 "-keystore", key_store, | 201 "-keystore", key_store, |
136 temp_apk_path, key_name]) | 202 temp_apk_path, key_name]) |
| 203 |
137 os.remove(apk_path) | 204 os.remove(apk_path) |
138 subprocess.check_call([zipalign_path, "-v", "4", temp_apk_path, | 205 subprocess.check_call([zipalign_path, "-v", "4", temp_apk_path, |
139 apk_path]) | 206 apk_path]) |
| 207 |
140 finally: | 208 finally: |
141 os.remove(temp_apk_path) | 209 os.remove(temp_apk_path) |
142 | 210 |
143 if __name__ == "__main__": | 211 if __name__ == "__main__": |
144 if len(sys.argv) < 2: | 212 if len(sys.argv) < 2: |
145 print_usage() | 213 _print_usage() |
146 sys.exit(1) | 214 sys.exit(1) |
147 | 215 |
148 mode = sys.argv[1] | 216 mode = sys.argv[1] |
149 do_build = mode in (_CMD_BUILD, _CMD_BUILD_SIGN) | 217 do_build = mode in (_CMD_BUILD, _CMD_BUILD_SIGN) |
150 do_sign = mode in (_CMD_SIGN, _CMD_BUILD_SIGN) | 218 do_sign = mode in (_CMD_SIGN, _CMD_BUILD_SIGN) |
151 if not do_build and not do_sign: | 219 if not do_build and not do_sign: |
152 print_usage() | 220 _print_usage() |
153 sys.exit(2) | 221 sys.exit(2) |
154 | 222 |
155 if do_sign: | 223 if do_sign: |
156 if len(sys.argv) < 3: | 224 if len(sys.argv) < 3: |
157 print_usage() | 225 _print_usage() |
158 sys.exit(3) | 226 sys.exit(3) |
159 apk_path = sys.argv[2] | 227 apk_path = sys.argv[2] |
160 | 228 |
161 subprocess.check_call([_ENSURE_DEPENDENCIES_PATH]) | 229 subprocess.check_call([_ENSURE_DEPENDENCIES_PATH]) |
| 230 error_msg = "Invalid %s, check config.py. Supported %s: %s" |
162 import config | 231 import config |
163 | |
164 error_msg = "Invalid %s, check config.py. Supported %s: %s" | |
165 distribution_mode = config.DISTRIBUTION_MODE | 232 distribution_mode = config.DISTRIBUTION_MODE |
166 if distribution_mode not in _DIST_MODES: | 233 if distribution_mode not in _DIST_MODES: |
167 print >>sys.stderr, error_msg % ( | 234 print >>sys.stderr, error_msg % ( |
168 "distribution mode", "distribution modes", _DIST_MODES) | 235 "distribution mode", "distribution modes", _DIST_MODES) |
169 sys.exit(4) | 236 sys.exit(4) |
170 | 237 |
171 build_mode = config.BUILD_MODE | 238 build_mode = config.BUILD_MODE |
172 if build_mode not in _BUILD_MODES: | 239 if build_mode not in _BUILD_MODES: |
173 print >>sys.stderr, error_msg % ( | 240 print >>sys.stderr, error_msg % ( |
174 "build mode", "build modes", _BUILD_MODES) | 241 "build mode", "build modes", _BUILD_MODES) |
175 sys.exit(5) | 242 sys.exit(5) |
176 | 243 |
177 architecture = config.ARCHITECTURE | 244 architecture = config.ARCHITECTURE |
178 if architecture not in _ARCHS: | 245 if architecture not in _ARCHS: |
179 print >>sys.stderr, error_msg % ( | 246 print >>sys.stderr, error_msg % ( |
180 "architecture", "architectures", _ARCHS) | 247 "architecture", "architectures", _ARCHS) |
181 sys.exit(6) | 248 sys.exit(6) |
182 | 249 |
183 if do_build: | 250 if do_build: |
184 apk_path = _build(architecture, distribution_mode, build_mode, | 251 apk_path = _build(architecture, distribution_mode, build_mode, |
185 config.ANDROID_SDK_PATH, config.ANDROID_NDK_PATH) | 252 config.ANDROID_SDK_PATH, config.ANDROID_NDK_PATH) |
186 if do_sign: | 253 if do_sign: |
187 _sign(apk_path, config.ANDROID_KEYSTORE_PATH, config.ANDROID_KEY_NAME, | 254 _sign(apk_path, config.ANDROID_KEYSTORE_PATH, config.ANDROID_KEY_NAME, |
188 config.ANDROID_SDK_PATH) | 255 config.ANDROID_SDK_PATH) |
189 else: | 256 else: |
190 print apk_path | 257 print(apk_path) |
OLD | NEW |