Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Side by Side Diff: build/android/play_services/preprocess.py

Issue 2096763007: Roll internal Google Play Services (Chromium part) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | build/config/android/internal_rules.gni » ('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 # 2 #
3 # Copyright 2015 The Chromium Authors. All rights reserved. 3 # Copyright 2015 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 '''Prepares the Google Play services split client libraries before usage by 7 '''Prepares the Google Play services split client libraries before usage by
8 Chrome's build system. 8 Chrome's build system.
9 9
10 We need to preprocess Google Play services before using it in Chrome 10 We need to preprocess Google Play services before using it in Chrome
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 from datetime import datetime 61 from datetime import datetime
62 62
63 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) 63 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir))
64 import devil_chromium 64 import devil_chromium
65 from devil.utils import cmd_helper 65 from devil.utils import cmd_helper
66 from play_services import utils 66 from play_services import utils
67 from pylib.utils import argparse_utils 67 from pylib.utils import argparse_utils
68 68
69 69
70 M2_PKG_PATH = os.path.join('com', 'google', 'android', 'gms')
71
72
73 def main(): 70 def main():
74 parser = argparse.ArgumentParser(description=( 71 parser = argparse.ArgumentParser(description=(
75 "Prepares the Google Play services split client libraries before usage " 72 "Prepares the Google Play services split client libraries before usage "
76 "by Chrome's build system. See the script's documentation for more a " 73 "by Chrome's build system. See the script's documentation for more a "
77 "detailed help.")) 74 "detailed help."))
78 argparse_utils.CustomHelpAction.EnableFor(parser) 75 argparse_utils.CustomHelpAction.EnableFor(parser)
79 required_args = parser.add_argument_group('required named arguments') 76 required_args = parser.add_argument_group('required named arguments')
80 required_args.add_argument('-r', 77 required_args.add_argument('-r',
81 '--repository', 78 '--repository',
82 help=('the Google Play services repository ' 79 help=('the Google Play services repository '
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 return out_paths 158 return out_paths
162 159
163 160
164 def _MakeWritable(dir_path): 161 def _MakeWritable(dir_path):
165 for root, dirs, files in os.walk(dir_path): 162 for root, dirs, files in os.walk(dir_path):
166 for path in itertools.chain(dirs, files): 163 for path in itertools.chain(dirs, files):
167 st = os.stat(os.path.join(root, path)) 164 st = os.stat(os.path.join(root, path))
168 os.chmod(os.path.join(root, path), st.st_mode | stat.S_IWUSR) 165 os.chmod(os.path.join(root, path), st.st_mode | stat.S_IWUSR)
169 166
170 167
168 # E.g. turn "base_1p" into "base"
169 def _RemovePartySuffix(client):
170 return client[:-3] if client[-3:] == '_1p' else client
171
172
171 def _ImportFromAars(config, tmp_paths, repo): 173 def _ImportFromAars(config, tmp_paths, repo):
172 for client in config.clients: 174 for client in config.clients:
173 aar_name = '%s-%s.aar' % (client, config.sdk_version) 175 client_name = _RemovePartySuffix(client)
174 aar_path = os.path.join(repo, M2_PKG_PATH, client, 176 aar_name = 'client_' + client + '.aar'
175 config.sdk_version, aar_name) 177 aar_path = os.path.join(repo, client_name, aar_name)
176 aar_out_path = os.path.join(tmp_paths['imported_clients'], client) 178 aar_out_path = os.path.join(tmp_paths['imported_clients'], client)
177 _ExtractAll(aar_path, aar_out_path) 179 _ExtractAll(aar_path, aar_out_path)
178 180
179 client_jar_path = os.path.join(aar_out_path, 'classes.jar') 181 client_jar_path = os.path.join(aar_out_path, 'classes.jar')
180 _ExtractAll(client_jar_path, tmp_paths['extracted_jars']) 182 _ExtractAll(client_jar_path, tmp_paths['extracted_jars'])
181 183
182 184
183 def _ImportFromExtractedRepo(config, tmp_paths, repo): 185 def _ImportFromExtractedRepo(config, tmp_paths, repo):
184 # Import the clients 186 # Import the clients
185 try: 187 try:
(...skipping 10 matching lines...) Expand all
196 def _GenerateCombinedJar(tmp_paths): 198 def _GenerateCombinedJar(tmp_paths):
197 out_file_name = tmp_paths['combined_jar'] 199 out_file_name = tmp_paths['combined_jar']
198 working_dir = tmp_paths['extracted_jars'] 200 working_dir = tmp_paths['extracted_jars']
199 cmd_helper.Call(['jar', '-cf', out_file_name, '-C', working_dir, '.']) 201 cmd_helper.Call(['jar', '-cf', out_file_name, '-C', working_dir, '.'])
200 202
201 203
202 def _ProcessResources(config, tmp_paths, repo): 204 def _ProcessResources(config, tmp_paths, repo):
203 LOCALIZED_VALUES_BASE_NAME = 'values-' 205 LOCALIZED_VALUES_BASE_NAME = 'values-'
204 locale_whitelist = set(config.locale_whitelist) 206 locale_whitelist = set(config.locale_whitelist)
205 207
206 glob_pattern = os.path.join(tmp_paths['imported_clients'], '*', 'res', '*') 208 # The directory structure here is:
207 for res_dir in glob.glob(glob_pattern): 209 # <imported_clients temp dir>/<client name>_1p/res/<res type>/<res file>.xml
208 dir_name = os.path.basename(res_dir) 210 for client_dir in os.listdir(tmp_paths['imported_clients']):
211 client_prefix = _RemovePartySuffix(client_dir) + '_'
209 212
210 if dir_name.startswith('drawable'): 213 res_path = os.path.join(tmp_paths['imported_clients'], client_dir, 'res')
211 shutil.rmtree(res_dir) 214 if not os.path.isdir(res_path):
212 continue 215 continue
216 for res_type in os.listdir(res_path):
217 res_type_path = os.path.join(res_path, res_type)
213 218
214 if dir_name.startswith(LOCALIZED_VALUES_BASE_NAME): 219 if res_type.startswith('drawable'):
215 dir_locale = dir_name[len(LOCALIZED_VALUES_BASE_NAME):] 220 shutil.rmtree(res_type_path)
216 if dir_locale not in locale_whitelist: 221 continue
217 shutil.rmtree(res_dir) 222
223 if res_type.startswith(LOCALIZED_VALUES_BASE_NAME):
224 dir_locale = res_type[len(LOCALIZED_VALUES_BASE_NAME):]
225 if dir_locale not in locale_whitelist:
226 shutil.rmtree(res_type_path)
227 continue
228
229 if res_type.startswith('values'):
230 # Beginning with v3, resource file names are not necessarily unique, and
231 # would overwrite each other when merged at build time. Prefix each
232 # "values" resource file with its client name.
233 for res_file in os.listdir(res_type_path):
234 os.rename(os.path.join(res_type_path, res_file),
235 os.path.join(res_type_path, client_prefix + res_file))
218 236
219 # Reimport files from the whitelist. 237 # Reimport files from the whitelist.
220 for res_path in config.resource_whitelist: 238 for res_path in config.resource_whitelist:
221 for whitelisted_file in glob.glob(os.path.join(repo, res_path)): 239 for whitelisted_file in glob.glob(os.path.join(repo, res_path)):
222 resolved_file = os.path.relpath(whitelisted_file, repo) 240 resolved_file = os.path.relpath(whitelisted_file, repo)
223 rebased_res = os.path.join(tmp_paths['imported_clients'], resolved_file) 241 rebased_res = os.path.join(tmp_paths['imported_clients'], resolved_file)
224 242
225 if not os.path.exists(os.path.dirname(rebased_res)): 243 if not os.path.exists(os.path.dirname(rebased_res)):
226 os.makedirs(os.path.dirname(rebased_res)) 244 os.makedirs(os.path.dirname(rebased_res))
227 245
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 283
266 config.UpdateVersionNumber(play_services_full_version) 284 config.UpdateVersionNumber(play_services_full_version)
267 285
268 286
269 def _ExtractAll(zip_path, out_path): 287 def _ExtractAll(zip_path, out_path):
270 with zipfile.ZipFile(zip_path, 'r') as zip_file: 288 with zipfile.ZipFile(zip_path, 'r') as zip_file:
271 zip_file.extractall(out_path) 289 zip_file.extractall(out_path)
272 290
273 if __name__ == '__main__': 291 if __name__ == '__main__':
274 sys.exit(main()) 292 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | build/config/android/internal_rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698