Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: abb-build/build.py

Issue 29989567: Issue 7238 - Fix multi-locale builds (Closed)
Patch Set: Adding l10n repo checkout Created Jan. 26, 2019, 12:31 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « abb-build/adblockbrowser-cfg.py ('k') | abb-build/mozconfig-common » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 subprocess.check_call(["hg", "up", "-r", revision],
102 cwd=repo_path)
103 else:
104 repo = l10n_base_repo % locale
105 subprocess.check_call(["hg", "clone", repo, "-r", revision],
106 cwd=_L10N_BASE_PATH)
107
108
109 def _read_locales():
110 with open(_MAEMO_LOCALES_PATH, "r") as fd:
111 lines = fd.readlines()
112
113 return [line.strip() for line in lines]
114
115
116 def _config_build_env(architecture, distribution_mode, build_mode, sdk_path,
117 ndk_path, obj_dir, locales):
118 build_env = os.environ.copy()
119 build_env["ANDROID_SDK_PATH"] = sdk_path
120 build_env["ANDROID_NDK_PATH"] = ndk_path
121 mozconfig_path = _generate_mozconfig(architecture, distribution_mode,
122 build_mode)
123
124 build_env["MOZCONFIG"] = mozconfig_path
125 build_env["OBJDIR"] = obj_dir
126 build_env["L10NBASEDIR"] = _L10N_BASE_PATH
127 build_env["MOZ_CHROME_MULTILOCALE"] = ' '.join(locales)
128 build_env["AB_CD"] = "multi"
129 return build_env
130
131
132 def _create_target_apk(architecture, distribution_mode, build_mode, obj_dir):
98 dist_path = os.path.join(_ABB_PATH, obj_dir, "dist") 133 dist_path = os.path.join(_ABB_PATH, obj_dir, "dist")
99 arch_suffix = _ARCH_X86_I386 if architecture == _ARCH_X86 else _ARCH_ARM 134 arch_suffix = _ARCH_X86_I386 if architecture == _ARCH_X86 else _ARCH_ARM
100 [manifest_path] = glob.glob(os.path.join( 135 [manifest_path] = glob.glob(os.path.join(
101 dist_path, "fennec-*.multi.android-%s.json" % arch_suffix)) 136 dist_path, "fennec-*.en-US.android-%s.json" % arch_suffix))
137
102 with open(manifest_path) as manifest_file: 138 with open(manifest_path) as manifest_file:
103 manifest = json.load(manifest_file) 139 manifest = json.load(manifest_file)
104 apk_name = "fennec-%s.multi.android-%s-unsigned-unaligned.apk" % ( 140
105 manifest["moz_app_version"], arch_suffix) 141 apk_name = "fennec-%s.en-US.android-%s-unsigned-unaligned.apk" % (
142 manifest["moz_app_version"], arch_suffix)
143
106 apk_path = os.path.join(dist_path, apk_name) 144 apk_path = os.path.join(dist_path, apk_name)
107 build_suffix = ("-%s" % manifest["buildid"] 145 build_suffix = ("-%s" % manifest["buildid"]
108 if build_mode == _BUILD_DEVBUILD 146 if build_mode == _BUILD_DEVBUILD
109 else "") 147 else "")
148
110 dist_suffix = ("-%s" % _DIST_STANDALONE 149 dist_suffix = ("-%s" % _DIST_STANDALONE
111 if distribution_mode == _DIST_STANDALONE 150 if distribution_mode == _DIST_STANDALONE
112 else "") 151 else "")
152
113 target_apk_name = "adblockbrowser-%s%s-%s%s.apk" % ( 153 target_apk_name = "adblockbrowser-%s%s-%s%s.apk" % (
114 manifest["moz_app_version"], build_suffix, architecture, dist_suffix) 154 manifest["moz_app_version"], build_suffix, architecture, dist_suffix)
155
115 target_apk_path = os.path.join(dist_path, target_apk_name) 156 target_apk_path = os.path.join(dist_path, target_apk_name)
116 shutil.copyfile(apk_path, target_apk_path) 157 shutil.copyfile(apk_path, target_apk_path)
117
118 target_manifest_path = re.sub(r".apk$", ".json", target_apk_path) 158 target_manifest_path = re.sub(r".apk$", ".json", target_apk_path)
119 shutil.copyfile(manifest_path, target_manifest_path) 159 shutil.copyfile(manifest_path, target_manifest_path)
160 return target_apk_path
120 161
121 return target_apk_path 162
163 def _build(architecture, distribution_mode, build_mode, sdk_path, ndk_path):
164 _checkout_l10n()
165 obj_dir = _OBJDIR_X86 if architecture == _ARCH_X86 else _OBJDIR_ARM
166 locales = _read_locales()
167 build_env = _config_build_env(architecture, distribution_mode, build_mode,
168 sdk_path, ndk_path, obj_dir, locales)
169
170 mach_path = os.path.join(_ABB_PATH, "mach")
171 subprocess.check_call([mach_path, "clobber"], env=build_env, cwd=_ABB_PATH)
172 subprocess.check_call([mach_path, "build"], env=build_env, cwd=_ABB_PATH)
173 for locale in locales:
174 chrome_str = "chrome-%s" % locale
175 subprocess.check_call([mach_path, "build", chrome_str], env=build_env,
176 cwd=_ABB_PATH)
177
178 obj_dir_path = os.path.join(_ABB_PATH, obj_dir)
179 import transform_locales as tl
180 tl.transform_locales(_ABB_PATH, obj_dir_path)
181 subprocess.check_call([mach_path, "package"], env=build_env, cwd=_ABB_PATH)
182 return _create_target_apk(architecture, distribution_mode, build_mode,
183 obj_dir)
122 184
123 185
124 def _sign(apk_path, key_store, key_name, sdk_path): 186 def _sign(apk_path, key_store, key_name, sdk_path):
125 sys.path.append(os.path.join(_ABB_PATH, "python", "mozboot", "mozboot")) 187 sys.path.append(os.path.join(_ABB_PATH, "python", "mozboot", "mozboot"))
126 from android import ANDROID_BUILD_TOOLS_VERSION 188 from android import ANDROID_BUILD_TOOLS_VERSION
127 zipalign_path = os.path.join(sdk_path, "build-tools", 189 zipalign_path = os.path.join(sdk_path, "build-tools",
128 ANDROID_BUILD_TOOLS_VERSION, "zipalign") 190 ANDROID_BUILD_TOOLS_VERSION, "zipalign")
191
129 temp_apk_path = tempfile.NamedTemporaryFile().name 192 temp_apk_path = tempfile.NamedTemporaryFile().name
130 shutil.copyfile(apk_path, temp_apk_path) 193 shutil.copyfile(apk_path, temp_apk_path)
131 try: 194 try:
132 subprocess.check_call(["jarsigner", "-verbose", 195 subprocess.check_call(["jarsigner", "-verbose",
133 "-sigalg", "SHA1withRSA", 196 "-sigalg", "SHA1withRSA",
134 "-digestalg", "SHA1", 197 "-digestalg", "SHA1",
135 "-keystore", key_store, 198 "-keystore", key_store,
136 temp_apk_path, key_name]) 199 temp_apk_path, key_name])
200
137 os.remove(apk_path) 201 os.remove(apk_path)
138 subprocess.check_call([zipalign_path, "-v", "4", temp_apk_path, 202 subprocess.check_call([zipalign_path, "-v", "4", temp_apk_path,
139 apk_path]) 203 apk_path])
204
140 finally: 205 finally:
141 os.remove(temp_apk_path) 206 os.remove(temp_apk_path)
142 207
143 if __name__ == "__main__": 208 if __name__ == "__main__":
144 if len(sys.argv) < 2: 209 if len(sys.argv) < 2:
145 print_usage() 210 _print_usage()
146 sys.exit(1) 211 sys.exit(1)
147 212
148 mode = sys.argv[1] 213 mode = sys.argv[1]
149 do_build = mode in (_CMD_BUILD, _CMD_BUILD_SIGN) 214 do_build = mode in (_CMD_BUILD, _CMD_BUILD_SIGN)
150 do_sign = mode in (_CMD_SIGN, _CMD_BUILD_SIGN) 215 do_sign = mode in (_CMD_SIGN, _CMD_BUILD_SIGN)
151 if not do_build and not do_sign: 216 if not do_build and not do_sign:
152 print_usage() 217 _print_usage()
153 sys.exit(2) 218 sys.exit(2)
154 219
155 if do_sign: 220 if do_sign:
156 if len(sys.argv) < 3: 221 if len(sys.argv) < 3:
157 print_usage() 222 _print_usage()
158 sys.exit(3) 223 sys.exit(3)
159 apk_path = sys.argv[2] 224 apk_path = sys.argv[2]
160 225
161 subprocess.check_call([_ENSURE_DEPENDENCIES_PATH]) 226 subprocess.check_call([_ENSURE_DEPENDENCIES_PATH])
227 error_msg = "Invalid %s, check config.py. Supported %s: %s"
162 import config 228 import config
163
164 error_msg = "Invalid %s, check config.py. Supported %s: %s"
165 distribution_mode = config.DISTRIBUTION_MODE 229 distribution_mode = config.DISTRIBUTION_MODE
166 if distribution_mode not in _DIST_MODES: 230 if distribution_mode not in _DIST_MODES:
167 print >>sys.stderr, error_msg % ( 231 print >>sys.stderr, error_msg % (
168 "distribution mode", "distribution modes", _DIST_MODES) 232 "distribution mode", "distribution modes", _DIST_MODES)
169 sys.exit(4) 233 sys.exit(4)
170 234
171 build_mode = config.BUILD_MODE 235 build_mode = config.BUILD_MODE
172 if build_mode not in _BUILD_MODES: 236 if build_mode not in _BUILD_MODES:
173 print >>sys.stderr, error_msg % ( 237 print >>sys.stderr, error_msg % (
174 "build mode", "build modes", _BUILD_MODES) 238 "build mode", "build modes", _BUILD_MODES)
175 sys.exit(5) 239 sys.exit(5)
176 240
177 architecture = config.ARCHITECTURE 241 architecture = config.ARCHITECTURE
178 if architecture not in _ARCHS: 242 if architecture not in _ARCHS:
179 print >>sys.stderr, error_msg % ( 243 print >>sys.stderr, error_msg % (
180 "architecture", "architectures", _ARCHS) 244 "architecture", "architectures", _ARCHS)
181 sys.exit(6) 245 sys.exit(6)
182 246
183 if do_build: 247 if do_build:
184 apk_path = _build(architecture, distribution_mode, build_mode, 248 apk_path = _build(architecture, distribution_mode, build_mode,
185 config.ANDROID_SDK_PATH, config.ANDROID_NDK_PATH) 249 config.ANDROID_SDK_PATH, config.ANDROID_NDK_PATH)
186 if do_sign: 250 if do_sign:
187 _sign(apk_path, config.ANDROID_KEYSTORE_PATH, config.ANDROID_KEY_NAME, 251 _sign(apk_path, config.ANDROID_KEYSTORE_PATH, config.ANDROID_KEY_NAME,
188 config.ANDROID_SDK_PATH) 252 config.ANDROID_SDK_PATH)
189 else: 253 else:
190 print apk_path 254 print(apk_path)
OLDNEW
« no previous file with comments | « abb-build/adblockbrowser-cfg.py ('k') | abb-build/mozconfig-common » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld