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

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

Issue 2095473002: Revert of Roll internal Google Play Services (Chromium part) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
70 def main(): 73 def main():
71 parser = argparse.ArgumentParser(description=( 74 parser = argparse.ArgumentParser(description=(
72 "Prepares the Google Play services split client libraries before usage " 75 "Prepares the Google Play services split client libraries before usage "
73 "by Chrome's build system. See the script's documentation for more a " 76 "by Chrome's build system. See the script's documentation for more a "
74 "detailed help.")) 77 "detailed help."))
75 argparse_utils.CustomHelpAction.EnableFor(parser) 78 argparse_utils.CustomHelpAction.EnableFor(parser)
76 required_args = parser.add_argument_group('required named arguments') 79 required_args = parser.add_argument_group('required named arguments')
77 required_args.add_argument('-r', 80 required_args.add_argument('-r',
78 '--repository', 81 '--repository',
79 help=('the Google Play services repository ' 82 help=('the Google Play services repository '
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 return out_paths 161 return out_paths
159 162
160 163
161 def _MakeWritable(dir_path): 164 def _MakeWritable(dir_path):
162 for root, dirs, files in os.walk(dir_path): 165 for root, dirs, files in os.walk(dir_path):
163 for path in itertools.chain(dirs, files): 166 for path in itertools.chain(dirs, files):
164 st = os.stat(os.path.join(root, path)) 167 st = os.stat(os.path.join(root, path))
165 os.chmod(os.path.join(root, path), st.st_mode | stat.S_IWUSR) 168 os.chmod(os.path.join(root, path), st.st_mode | stat.S_IWUSR)
166 169
167 170
168 # E.g. turn "base_1p" into "base"
169 def _RemovePartySuffix(client):
170 return client[:-3] if client[-3:] == '_1p' else client
171
172
173 def _ImportFromAars(config, tmp_paths, repo): 171 def _ImportFromAars(config, tmp_paths, repo):
174 for client in config.clients: 172 for client in config.clients:
175 client_name = _RemovePartySuffix(client) 173 aar_name = '%s-%s.aar' % (client, config.sdk_version)
176 aar_name = 'client_' + client + '.aar' 174 aar_path = os.path.join(repo, M2_PKG_PATH, client,
177 aar_path = os.path.join(repo, client_name, aar_name) 175 config.sdk_version, aar_name)
178 aar_out_path = os.path.join(tmp_paths['imported_clients'], client) 176 aar_out_path = os.path.join(tmp_paths['imported_clients'], client)
179 _ExtractAll(aar_path, aar_out_path) 177 _ExtractAll(aar_path, aar_out_path)
180 178
181 client_jar_path = os.path.join(aar_out_path, 'classes.jar') 179 client_jar_path = os.path.join(aar_out_path, 'classes.jar')
182 _ExtractAll(client_jar_path, tmp_paths['extracted_jars']) 180 _ExtractAll(client_jar_path, tmp_paths['extracted_jars'])
183 181
184 182
185 def _ImportFromExtractedRepo(config, tmp_paths, repo): 183 def _ImportFromExtractedRepo(config, tmp_paths, repo):
186 # Import the clients 184 # Import the clients
187 try: 185 try:
(...skipping 10 matching lines...) Expand all
198 def _GenerateCombinedJar(tmp_paths): 196 def _GenerateCombinedJar(tmp_paths):
199 out_file_name = tmp_paths['combined_jar'] 197 out_file_name = tmp_paths['combined_jar']
200 working_dir = tmp_paths['extracted_jars'] 198 working_dir = tmp_paths['extracted_jars']
201 cmd_helper.Call(['jar', '-cf', out_file_name, '-C', working_dir, '.']) 199 cmd_helper.Call(['jar', '-cf', out_file_name, '-C', working_dir, '.'])
202 200
203 201
204 def _ProcessResources(config, tmp_paths, repo): 202 def _ProcessResources(config, tmp_paths, repo):
205 LOCALIZED_VALUES_BASE_NAME = 'values-' 203 LOCALIZED_VALUES_BASE_NAME = 'values-'
206 locale_whitelist = set(config.locale_whitelist) 204 locale_whitelist = set(config.locale_whitelist)
207 205
208 # The directory structure here is: 206 glob_pattern = os.path.join(tmp_paths['imported_clients'], '*', 'res', '*')
209 # <imported_clients temp dir>/<client name>_1p/res/<res type>/<res file>.xml 207 for res_dir in glob.glob(glob_pattern):
210 for client_dir in os.listdir(tmp_paths['imported_clients']): 208 dir_name = os.path.basename(res_dir)
211 client_prefix = _RemovePartySuffix(client_dir) + '_'
212 209
213 res_path = os.path.join(tmp_paths['imported_clients'], client_dir, 'res') 210 if dir_name.startswith('drawable'):
214 if not os.path.isdir(res_path): 211 shutil.rmtree(res_dir)
215 continue 212 continue
216 for res_type in os.listdir(res_path):
217 res_type_path = os.path.join(res_path, res_type)
218 213
219 if res_type.startswith('drawable'): 214 if dir_name.startswith(LOCALIZED_VALUES_BASE_NAME):
220 shutil.rmtree(res_type_path) 215 dir_locale = dir_name[len(LOCALIZED_VALUES_BASE_NAME):]
221 continue 216 if dir_locale not in locale_whitelist:
222 217 shutil.rmtree(res_dir)
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))
236 218
237 # Reimport files from the whitelist. 219 # Reimport files from the whitelist.
238 for res_path in config.resource_whitelist: 220 for res_path in config.resource_whitelist:
239 for whitelisted_file in glob.glob(os.path.join(repo, res_path)): 221 for whitelisted_file in glob.glob(os.path.join(repo, res_path)):
240 resolved_file = os.path.relpath(whitelisted_file, repo) 222 resolved_file = os.path.relpath(whitelisted_file, repo)
241 rebased_res = os.path.join(tmp_paths['imported_clients'], resolved_file) 223 rebased_res = os.path.join(tmp_paths['imported_clients'], resolved_file)
242 224
243 if not os.path.exists(os.path.dirname(rebased_res)): 225 if not os.path.exists(os.path.dirname(rebased_res)):
244 os.makedirs(os.path.dirname(rebased_res)) 226 os.makedirs(os.path.dirname(rebased_res))
245 227
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 265
284 config.UpdateVersionNumber(play_services_full_version) 266 config.UpdateVersionNumber(play_services_full_version)
285 267
286 268
287 def _ExtractAll(zip_path, out_path): 269 def _ExtractAll(zip_path, out_path):
288 with zipfile.ZipFile(zip_path, 'r') as zip_file: 270 with zipfile.ZipFile(zip_path, 'r') as zip_file:
289 zip_file.extractall(out_path) 271 zip_file.extractall(out_path)
290 272
291 if __name__ == '__main__': 273 if __name__ == '__main__':
292 sys.exit(main()) 274 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