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: Created Jan. 24, 2019, 3:21 p.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")
41 40
42 _CMD_BUILD = "build" 41 _CMD_BUILD = "build"
43 _CMD_SIGN = "sign" 42 _CMD_SIGN = "sign"
44 _CMD_BUILD_SIGN = "build-and-sign" 43 _CMD_BUILD_SIGN = "build-and-sign"
45 _ARCH_ARM = "arm" 44 _ARCH_ARM = "arm"
46 _ARCH_X86 = "x86" 45 _ARCH_X86 = "x86"
47 _ARCH_X86_I386 = "i386" 46 _ARCH_X86_I386 = "i386"
48 _ARCHS = (_ARCH_ARM, _ARCH_X86) 47 _ARCHS = (_ARCH_ARM, _ARCH_X86)
49 _DIST_STANDALONE = "standalone" 48 _DIST_STANDALONE = "standalone"
50 _DIST_STORE = "store" 49 _DIST_STORE = "store"
51 _DIST_MODES = (_DIST_STANDALONE, _DIST_STORE) 50 _DIST_MODES = (_DIST_STANDALONE, _DIST_STORE)
52 _BUILD_DEVBUILD = "devbuild" 51 _BUILD_DEVBUILD = "devbuild"
53 _BUILD_RELEASE = "release" 52 _BUILD_RELEASE = "release"
54 _BUILD_MODES = (_BUILD_DEVBUILD, _BUILD_RELEASE) 53 _BUILD_MODES = (_BUILD_DEVBUILD, _BUILD_RELEASE)
55 _OBJDIR_ARM = "obj-arm-linux-androideabi" 54 _OBJDIR_ARM = "obj-arm-linux-androideabi"
56 _OBJDIR_X86 = "obj-i386-linux-android" 55 _OBJDIR_X86 = "obj-i386-linux-android"
57 56
58 57
59 def print_usage(): 58 def _print_usage():
60 print >>sys.stderr, string.Template("""\ 59 print >>sys.stderr, string.Template("""\
61 Usage: $name %s 60 Usage: $name %s
62 $name %s APK_PATH 61 $name %s APK_PATH
63 $name %s\ 62 $name %s\
64 """ % (_CMD_BUILD, _CMD_SIGN, 63 """ % (_CMD_BUILD, _CMD_SIGN,
65 _CMD_BUILD_SIGN)).substitute({"name": os.path.basename(sys.argv[0])}) 64 _CMD_BUILD_SIGN)).substitute({"name": os.path.basename(sys.argv[0])})
66 65
67 66
68 def _generate_mozconfig(architecture, distribution_mode, build_mode): 67 def _generate_mozconfig(architecture, distribution_mode, build_mode):
69 if not os.path.exists(_GENERATED_PATH): 68 if not os.path.exists(_GENERATED_PATH):
70 os.makedirs(_GENERATED_PATH) 69 os.makedirs(_GENERATED_PATH)
70
71 with open(_GENERATED_MOZCONFIG_PATH, "w+") as mozconfig: 71 with open(_GENERATED_MOZCONFIG_PATH, "w+") as mozconfig:
72 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_COMMON_PATH) 72 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_COMMON_PATH)
73 if architecture == _ARCH_X86: 73 if architecture == _ARCH_X86:
74 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_X86_PATH) 74 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_X86_PATH)
75 else: 75 else:
76 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_ARM_PATH) 76 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_ARM_PATH)
77 if distribution_mode == _DIST_STORE: 77 if distribution_mode == _DIST_STORE:
78 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_STORE_PATH) 78 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_STORE_PATH)
79 if build_mode == _BUILD_RELEASE: 79 if build_mode == _BUILD_RELEASE:
80 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_RELEASE_PATH) 80 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_RELEASE_PATH)
81 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_CUSTOM_PATH) 81 mozconfig.write(". \"%s\"\n" % _MOZCONFIG_CUSTOM_PATH)
82 return _GENERATED_MOZCONFIG_PATH 82 return _GENERATED_MOZCONFIG_PATH
83 83
84 84
85 def _build(architecture, distribution_mode, build_mode, sdk_path, ndk_path): 85 def _read_locales():
86 build_environment = os.environ.copy() 86 with open(_MAEMO_LOCALES_PATH, "r") as fd:
87 build_environment["ANDROID_SDK_PATH"] = sdk_path 87 lines = fd.readlines()
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 88
89 return [line.strip() for line in lines]
90
91
92 def _config_build_env(architecture, distribution_mode, build_mode, sdk_path,
93 ndk_path, obj_dir, locales):
94 build_env = os.environ.copy()
95 build_env["ANDROID_SDK_PATH"] = sdk_path
96 build_env["ANDROID_NDK_PATH"] = ndk_path
97 mozconfig_path = _generate_mozconfig(architecture, distribution_mode,
98 build_mode)
99
100 build_env["MOZCONFIG"] = mozconfig_path
101 build_env["OBJDIR"] = obj_dir
102 build_env["MOZ_CHROME_MULTILOCALE"] = ' '.join(locales)
103 build_env["AB_CD"] = "multi"
104 return build_env
105
106
107 def _create_target_apk(architecture, distribution_mode, build_mode, obj_dir):
98 dist_path = os.path.join(_ABB_PATH, obj_dir, "dist") 108 dist_path = os.path.join(_ABB_PATH, obj_dir, "dist")
99 arch_suffix = _ARCH_X86_I386 if architecture == _ARCH_X86 else _ARCH_ARM 109 arch_suffix = _ARCH_X86_I386 if architecture == _ARCH_X86 else _ARCH_ARM
100 [manifest_path] = glob.glob(os.path.join( 110 [manifest_path] = glob.glob(os.path.join(
101 dist_path, "fennec-*.multi.android-%s.json" % arch_suffix)) 111 dist_path, "fennec-*.en-US.android-%s.json" % arch_suffix))
112
102 with open(manifest_path) as manifest_file: 113 with open(manifest_path) as manifest_file:
103 manifest = json.load(manifest_file) 114 manifest = json.load(manifest_file)
104 apk_name = "fennec-%s.multi.android-%s-unsigned-unaligned.apk" % ( 115
105 manifest["moz_app_version"], arch_suffix) 116 apk_name = "fennec-%s.en-US.android-%s-unsigned-unaligned.apk" % (
117 manifest["moz_app_version"], arch_suffix)
118
106 apk_path = os.path.join(dist_path, apk_name) 119 apk_path = os.path.join(dist_path, apk_name)
107 build_suffix = ("-%s" % manifest["buildid"] 120 build_suffix = ("-%s" % manifest["buildid"]
108 if build_mode == _BUILD_DEVBUILD 121 if build_mode == _BUILD_DEVBUILD
109 else "") 122 else "")
123
110 dist_suffix = ("-%s" % _DIST_STANDALONE 124 dist_suffix = ("-%s" % _DIST_STANDALONE
111 if distribution_mode == _DIST_STANDALONE 125 if distribution_mode == _DIST_STANDALONE
112 else "") 126 else "")
127
113 target_apk_name = "adblockbrowser-%s%s-%s%s.apk" % ( 128 target_apk_name = "adblockbrowser-%s%s-%s%s.apk" % (
114 manifest["moz_app_version"], build_suffix, architecture, dist_suffix) 129 manifest["moz_app_version"], build_suffix, architecture, dist_suffix)
130
115 target_apk_path = os.path.join(dist_path, target_apk_name) 131 target_apk_path = os.path.join(dist_path, target_apk_name)
116 shutil.copyfile(apk_path, target_apk_path) 132 shutil.copyfile(apk_path, target_apk_path)
117
118 target_manifest_path = re.sub(r".apk$", ".json", target_apk_path) 133 target_manifest_path = re.sub(r".apk$", ".json", target_apk_path)
119 shutil.copyfile(manifest_path, target_manifest_path) 134 shutil.copyfile(manifest_path, target_manifest_path)
135 return target_apk_path
120 136
121 return target_apk_path 137
138 def _build(architecture, distribution_mode, build_mode, sdk_path, ndk_path):
139 obj_dir = _OBJDIR_X86 if architecture == _ARCH_X86 else _OBJDIR_ARM
140 locales = _read_locales()
141 build_env = _config_build_env(architecture, distribution_mode, build_mode,
142 sdk_path, ndk_path, obj_dir, locales)
143
144 mach_path = os.path.join(_ABB_PATH, "mach")
145 subprocess.check_call([mach_path, "clobber"], env=build_env, cwd=_ABB_PATH)
146 subprocess.check_call([mach_path, "build"], env=build_env, cwd=_ABB_PATH)
147 for locale in locales:
148 chrome_str = "chrome-%s" % locale
149 subprocess.check_call([mach_path, "build", chrome_str], env=build_env,
150 cwd=_ABB_PATH)
151
152 obj_dir_path = os.path.join(_ABB_PATH, obj_dir)
153 import transform_locales as tl
154 tl.transform_locales(_ABB_PATH, obj_dir_path)
155 # build_env["AB_CD"] = "multi"
156 subprocess.check_call([mach_path, "package"], env=build_env, cwd=_ABB_PATH)
157 return _create_target_apk(architecture, distribution_mode, build_mode,
158 obj_dir)
122 159
123 160
124 def _sign(apk_path, key_store, key_name, sdk_path): 161 def _sign(apk_path, key_store, key_name, sdk_path):
125 sys.path.append(os.path.join(_ABB_PATH, "python", "mozboot", "mozboot")) 162 sys.path.append(os.path.join(_ABB_PATH, "python", "mozboot", "mozboot"))
126 from android import ANDROID_BUILD_TOOLS_VERSION 163 from android import ANDROID_BUILD_TOOLS_VERSION
127 zipalign_path = os.path.join(sdk_path, "build-tools", 164 zipalign_path = os.path.join(sdk_path, "build-tools",
128 ANDROID_BUILD_TOOLS_VERSION, "zipalign") 165 ANDROID_BUILD_TOOLS_VERSION, "zipalign")
166
129 temp_apk_path = tempfile.NamedTemporaryFile().name 167 temp_apk_path = tempfile.NamedTemporaryFile().name
130 shutil.copyfile(apk_path, temp_apk_path) 168 shutil.copyfile(apk_path, temp_apk_path)
131 try: 169 try:
132 subprocess.check_call(["jarsigner", "-verbose", 170 subprocess.check_call(["jarsigner", "-verbose",
133 "-sigalg", "SHA1withRSA", 171 "-sigalg", "SHA1withRSA",
134 "-digestalg", "SHA1", 172 "-digestalg", "SHA1",
135 "-keystore", key_store, 173 "-keystore", key_store,
136 temp_apk_path, key_name]) 174 temp_apk_path, key_name])
175
137 os.remove(apk_path) 176 os.remove(apk_path)
138 subprocess.check_call([zipalign_path, "-v", "4", temp_apk_path, 177 subprocess.check_call([zipalign_path, "-v", "4", temp_apk_path,
139 apk_path]) 178 apk_path])
179
140 finally: 180 finally:
141 os.remove(temp_apk_path) 181 os.remove(temp_apk_path)
142 182
143 if __name__ == "__main__": 183 if __name__ == "__main__":
144 if len(sys.argv) < 2: 184 if len(sys.argv) < 2:
145 print_usage() 185 _print_usage()
146 sys.exit(1) 186 sys.exit(1)
147 187
148 mode = sys.argv[1] 188 mode = sys.argv[1]
149 do_build = mode in (_CMD_BUILD, _CMD_BUILD_SIGN) 189 do_build = mode in (_CMD_BUILD, _CMD_BUILD_SIGN)
150 do_sign = mode in (_CMD_SIGN, _CMD_BUILD_SIGN) 190 do_sign = mode in (_CMD_SIGN, _CMD_BUILD_SIGN)
151 if not do_build and not do_sign: 191 if not do_build and not do_sign:
152 print_usage() 192 _print_usage()
153 sys.exit(2) 193 sys.exit(2)
154 194
155 if do_sign: 195 if do_sign:
156 if len(sys.argv) < 3: 196 if len(sys.argv) < 3:
157 print_usage() 197 _print_usage()
158 sys.exit(3) 198 sys.exit(3)
159 apk_path = sys.argv[2] 199 apk_path = sys.argv[2]
160 200
161 subprocess.check_call([_ENSURE_DEPENDENCIES_PATH]) 201 subprocess.check_call([_ENSURE_DEPENDENCIES_PATH])
202 error_msg = "Invalid %s, check config.py. Supported %s: %s"
162 import config 203 import config
163
164 error_msg = "Invalid %s, check config.py. Supported %s: %s"
165 distribution_mode = config.DISTRIBUTION_MODE 204 distribution_mode = config.DISTRIBUTION_MODE
166 if distribution_mode not in _DIST_MODES: 205 if distribution_mode not in _DIST_MODES:
167 print >>sys.stderr, error_msg % ( 206 print >>sys.stderr, error_msg % (
168 "distribution mode", "distribution modes", _DIST_MODES) 207 "distribution mode", "distribution modes", _DIST_MODES)
169 sys.exit(4) 208 sys.exit(4)
170 209
171 build_mode = config.BUILD_MODE 210 build_mode = config.BUILD_MODE
172 if build_mode not in _BUILD_MODES: 211 if build_mode not in _BUILD_MODES:
173 print >>sys.stderr, error_msg % ( 212 print >>sys.stderr, error_msg % (
174 "build mode", "build modes", _BUILD_MODES) 213 "build mode", "build modes", _BUILD_MODES)
175 sys.exit(5) 214 sys.exit(5)
176 215
177 architecture = config.ARCHITECTURE 216 architecture = config.ARCHITECTURE
178 if architecture not in _ARCHS: 217 if architecture not in _ARCHS:
179 print >>sys.stderr, error_msg % ( 218 print >>sys.stderr, error_msg % (
180 "architecture", "architectures", _ARCHS) 219 "architecture", "architectures", _ARCHS)
181 sys.exit(6) 220 sys.exit(6)
182 221
183 if do_build: 222 if do_build:
184 apk_path = _build(architecture, distribution_mode, build_mode, 223 apk_path = _build(architecture, distribution_mode, build_mode,
185 config.ANDROID_SDK_PATH, config.ANDROID_NDK_PATH) 224 config.ANDROID_SDK_PATH, config.ANDROID_NDK_PATH)
186 if do_sign: 225 if do_sign:
187 _sign(apk_path, config.ANDROID_KEYSTORE_PATH, config.ANDROID_KEY_NAME, 226 _sign(apk_path, config.ANDROID_KEYSTORE_PATH, config.ANDROID_KEY_NAME,
188 config.ANDROID_SDK_PATH) 227 config.ANDROID_SDK_PATH)
189 else: 228 else:
190 print apk_path 229 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