Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 assert client[-3:] == '_1p' | |
|
jbudorick
2016/06/15 01:11:59
Can this instead remove _1p if it's present & othe
paulmiller
2016/06/15 19:06:35
Done.
| |
| 171 return client[:-3] | |
| 172 | |
| 173 | |
| 171 def _ImportFromAars(config, tmp_paths, repo): | 174 def _ImportFromAars(config, tmp_paths, repo): |
| 172 for client in config.clients: | 175 for client in config.clients: |
| 173 aar_name = '%s-%s.aar' % (client, config.sdk_version) | 176 client_name = _RemovePartySuffix(client) |
| 174 aar_path = os.path.join(repo, M2_PKG_PATH, client, | 177 aar_name = 'client_' + client + '.aar' |
| 175 config.sdk_version, aar_name) | 178 aar_path = os.path.join(repo, client_name, aar_name) |
| 176 aar_out_path = os.path.join(tmp_paths['imported_clients'], client) | 179 aar_out_path = os.path.join(tmp_paths['imported_clients'], client) |
| 177 _ExtractAll(aar_path, aar_out_path) | 180 _ExtractAll(aar_path, aar_out_path) |
| 178 | 181 |
| 179 client_jar_path = os.path.join(aar_out_path, 'classes.jar') | 182 client_jar_path = os.path.join(aar_out_path, 'classes.jar') |
| 180 _ExtractAll(client_jar_path, tmp_paths['extracted_jars']) | 183 _ExtractAll(client_jar_path, tmp_paths['extracted_jars']) |
| 181 | 184 |
| 182 | 185 |
| 183 def _ImportFromExtractedRepo(config, tmp_paths, repo): | 186 def _ImportFromExtractedRepo(config, tmp_paths, repo): |
| 184 # Import the clients | 187 # Import the clients |
| 185 try: | 188 try: |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 196 def _GenerateCombinedJar(tmp_paths): | 199 def _GenerateCombinedJar(tmp_paths): |
| 197 out_file_name = tmp_paths['combined_jar'] | 200 out_file_name = tmp_paths['combined_jar'] |
| 198 working_dir = tmp_paths['extracted_jars'] | 201 working_dir = tmp_paths['extracted_jars'] |
| 199 cmd_helper.Call(['jar', '-cf', out_file_name, '-C', working_dir, '.']) | 202 cmd_helper.Call(['jar', '-cf', out_file_name, '-C', working_dir, '.']) |
| 200 | 203 |
| 201 | 204 |
| 202 def _ProcessResources(config, tmp_paths, repo): | 205 def _ProcessResources(config, tmp_paths, repo): |
| 203 LOCALIZED_VALUES_BASE_NAME = 'values-' | 206 LOCALIZED_VALUES_BASE_NAME = 'values-' |
| 204 locale_whitelist = set(config.locale_whitelist) | 207 locale_whitelist = set(config.locale_whitelist) |
| 205 | 208 |
| 206 glob_pattern = os.path.join(tmp_paths['imported_clients'], '*', 'res', '*') | 209 # The directory structure here is: |
| 207 for res_dir in glob.glob(glob_pattern): | 210 # <imported_clients temp dir>/<client name>_1p/res/<res type>/<res file>.xml |
| 208 dir_name = os.path.basename(res_dir) | 211 for client_dir in os.listdir(tmp_paths['imported_clients']): |
| 212 client_prefix = _RemovePartySuffix(client_dir) + '_' | |
| 209 | 213 |
| 210 if dir_name.startswith('drawable'): | 214 res_path = os.path.join(tmp_paths['imported_clients'], client_dir, 'res') |
| 211 shutil.rmtree(res_dir) | 215 if not os.path.isdir(res_path): |
| 212 continue | 216 continue |
| 217 for res_type in os.listdir(res_path): | |
| 218 res_type_path = os.path.join(res_path, res_type) | |
| 213 | 219 |
| 214 if dir_name.startswith(LOCALIZED_VALUES_BASE_NAME): | 220 if res_type.startswith('drawable'): |
| 215 dir_locale = dir_name[len(LOCALIZED_VALUES_BASE_NAME):] | 221 shutil.rmtree(res_type_path) |
| 216 if dir_locale not in locale_whitelist: | 222 continue |
| 217 shutil.rmtree(res_dir) | 223 |
| 224 if res_type.startswith(LOCALIZED_VALUES_BASE_NAME): | |
| 225 dir_locale = res_type[len(LOCALIZED_VALUES_BASE_NAME):] | |
| 226 if dir_locale not in locale_whitelist: | |
| 227 shutil.rmtree(res_type_path) | |
| 228 continue | |
| 229 | |
| 230 # Beginning with v3, resource file names are not necessarily unique, and | |
|
agrieve
2016/06/15 01:01:11
Aren't filenames sometimes used by java code? I kn
paulmiller
2016/06/15 19:06:35
I don't see any gmscore resource file names hard-c
| |
| 231 # would overwrite each other when merged at build time. Prefix each | |
| 232 # resource file with its client name if it isn't already. | |
| 233 for res_file in os.listdir(res_type_path): | |
| 234 if not res_file.startswith(client_prefix): | |
| 235 os.rename(os.path.join(res_type_path, res_file), | |
| 236 os.path.join(res_type_path, client_prefix + res_file)) | |
| 218 | 237 |
| 219 # Reimport files from the whitelist. | 238 # Reimport files from the whitelist. |
| 220 for res_path in config.resource_whitelist: | 239 for res_path in config.resource_whitelist: |
| 221 for whitelisted_file in glob.glob(os.path.join(repo, res_path)): | 240 for whitelisted_file in glob.glob(os.path.join(repo, res_path)): |
| 222 resolved_file = os.path.relpath(whitelisted_file, repo) | 241 resolved_file = os.path.relpath(whitelisted_file, repo) |
| 223 rebased_res = os.path.join(tmp_paths['imported_clients'], resolved_file) | 242 rebased_res = os.path.join(tmp_paths['imported_clients'], resolved_file) |
| 224 | 243 |
| 225 if not os.path.exists(os.path.dirname(rebased_res)): | 244 if not os.path.exists(os.path.dirname(rebased_res)): |
| 226 os.makedirs(os.path.dirname(rebased_res)) | 245 os.makedirs(os.path.dirname(rebased_res)) |
| 227 | 246 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 | 284 |
| 266 config.UpdateVersionNumber(play_services_full_version) | 285 config.UpdateVersionNumber(play_services_full_version) |
| 267 | 286 |
| 268 | 287 |
| 269 def _ExtractAll(zip_path, out_path): | 288 def _ExtractAll(zip_path, out_path): |
| 270 with zipfile.ZipFile(zip_path, 'r') as zip_file: | 289 with zipfile.ZipFile(zip_path, 'r') as zip_file: |
| 271 zip_file.extractall(out_path) | 290 zip_file.extractall(out_path) |
| 272 | 291 |
| 273 if __name__ == '__main__': | 292 if __name__ == '__main__': |
| 274 sys.exit(main()) | 293 sys.exit(main()) |
| OLD | NEW |