| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 tmp_root = tempfile.mkdtemp() | 118 tmp_root = tempfile.mkdtemp() |
| 119 try: | 119 try: |
| 120 tmp_paths = _SetupTempDir(tmp_root) | 120 tmp_paths = _SetupTempDir(tmp_root) |
| 121 | 121 |
| 122 if is_extracted_repo: | 122 if is_extracted_repo: |
| 123 _ImportFromExtractedRepo(config, tmp_paths, repo) | 123 _ImportFromExtractedRepo(config, tmp_paths, repo) |
| 124 else: | 124 else: |
| 125 _ImportFromAars(config, tmp_paths, repo) | 125 _ImportFromAars(config, tmp_paths, repo) |
| 126 | 126 |
| 127 _GenerateCombinedJar(tmp_paths) | 127 _GenerateCombinedJar(tmp_paths) |
| 128 _ProcessResources(config, tmp_paths) | 128 _ProcessResources(config, tmp_paths, repo) |
| 129 _BuildOutput(config, tmp_paths, out_dir) | 129 _BuildOutput(config, tmp_paths, out_dir) |
| 130 finally: | 130 finally: |
| 131 shutil.rmtree(tmp_root) | 131 shutil.rmtree(tmp_root) |
| 132 | 132 |
| 133 return 0 | 133 return 0 |
| 134 | 134 |
| 135 | 135 |
| 136 def _SetupTempDir(tmp_root): | 136 def _SetupTempDir(tmp_root): |
| 137 tmp_paths = { | 137 tmp_paths = { |
| 138 'root': tmp_root, | 138 'root': tmp_root, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 finally: | 192 finally: |
| 193 _MakeWritable(tmp_paths['imported_clients']) | 193 _MakeWritable(tmp_paths['imported_clients']) |
| 194 | 194 |
| 195 | 195 |
| 196 def _GenerateCombinedJar(tmp_paths): | 196 def _GenerateCombinedJar(tmp_paths): |
| 197 out_file_name = tmp_paths['combined_jar'] | 197 out_file_name = tmp_paths['combined_jar'] |
| 198 working_dir = tmp_paths['extracted_jars'] | 198 working_dir = tmp_paths['extracted_jars'] |
| 199 cmd_helper.Call(['jar', '-cf', out_file_name, '-C', working_dir, '.']) | 199 cmd_helper.Call(['jar', '-cf', out_file_name, '-C', working_dir, '.']) |
| 200 | 200 |
| 201 | 201 |
| 202 def _ProcessResources(config, tmp_paths): | 202 def _ProcessResources(config, tmp_paths, repo): |
| 203 LOCALIZED_VALUES_BASE_NAME = 'values-' | 203 LOCALIZED_VALUES_BASE_NAME = 'values-' |
| 204 locale_whitelist = set(config.locale_whitelist) | 204 locale_whitelist = set(config.locale_whitelist) |
| 205 | 205 |
| 206 glob_pattern = os.path.join(tmp_paths['imported_clients'], '*', 'res', '*') | 206 glob_pattern = os.path.join(tmp_paths['imported_clients'], '*', 'res', '*') |
| 207 for res_dir in glob.glob(glob_pattern): | 207 for res_dir in glob.glob(glob_pattern): |
| 208 dir_name = os.path.basename(res_dir) | 208 dir_name = os.path.basename(res_dir) |
| 209 | 209 |
| 210 if dir_name.startswith('drawable'): | 210 if dir_name.startswith('drawable'): |
| 211 shutil.rmtree(res_dir) | 211 shutil.rmtree(res_dir) |
| 212 continue | 212 continue |
| 213 | 213 |
| 214 if dir_name.startswith(LOCALIZED_VALUES_BASE_NAME): | 214 if dir_name.startswith(LOCALIZED_VALUES_BASE_NAME): |
| 215 dir_locale = dir_name[len(LOCALIZED_VALUES_BASE_NAME):] | 215 dir_locale = dir_name[len(LOCALIZED_VALUES_BASE_NAME):] |
| 216 if dir_locale not in locale_whitelist: | 216 if dir_locale not in locale_whitelist: |
| 217 shutil.rmtree(res_dir) | 217 shutil.rmtree(res_dir) |
| 218 | 218 |
| 219 # Reimport files from the whitelist. |
| 220 for res_path in config.resource_whitelist: |
| 221 for whitelisted_file in glob.glob(os.path.join(repo, res_path)): |
| 222 resolved_file = os.path.relpath(whitelisted_file, repo) |
| 223 rebased_res = os.path.join(tmp_paths['imported_clients'], resolved_file) |
| 224 |
| 225 if not os.path.exists(os.path.dirname(rebased_res)): |
| 226 os.makedirs(os.path.dirname(rebased_res)) |
| 227 |
| 228 shutil.copy(os.path.join(repo, whitelisted_file), rebased_res) |
| 229 |
| 219 | 230 |
| 220 def _BuildOutput(config, tmp_paths, out_dir): | 231 def _BuildOutput(config, tmp_paths, out_dir): |
| 221 generation_date = datetime.utcnow() | 232 generation_date = datetime.utcnow() |
| 222 version_xml_path = os.path.join(tmp_paths['imported_clients'], | 233 version_xml_path = os.path.join(tmp_paths['imported_clients'], |
| 223 config.version_xml_path) | 234 config.version_xml_path) |
| 224 play_services_full_version = utils.GetVersionNumberFromLibraryResources( | 235 play_services_full_version = utils.GetVersionNumberFromLibraryResources( |
| 225 version_xml_path) | 236 version_xml_path) |
| 226 | 237 |
| 227 out_paths = _SetupOutputDir(out_dir) | 238 out_paths = _SetupOutputDir(out_dir) |
| 228 | 239 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 254 | 265 |
| 255 config.UpdateVersionNumber(play_services_full_version) | 266 config.UpdateVersionNumber(play_services_full_version) |
| 256 | 267 |
| 257 | 268 |
| 258 def _ExtractAll(zip_path, out_path): | 269 def _ExtractAll(zip_path, out_path): |
| 259 with zipfile.ZipFile(zip_path, 'r') as zip_file: | 270 with zipfile.ZipFile(zip_path, 'r') as zip_file: |
| 260 zip_file.extractall(out_path) | 271 zip_file.extractall(out_path) |
| 261 | 272 |
| 262 if __name__ == '__main__': | 273 if __name__ == '__main__': |
| 263 sys.exit(main()) | 274 sys.exit(main()) |
| OLD | NEW |