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 builds | 10 We need to preprocess Google Play services before using it in Chrome builds |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 '--repository', | 53 '--repository', |
| 54 help=('the Google Play services repository ' | 54 help=('the Google Play services repository ' |
| 55 'location'), | 55 'location'), |
| 56 required=True, | 56 required=True, |
| 57 metavar='FILE') | 57 metavar='FILE') |
| 58 required_args.add_argument('-o', | 58 required_args.add_argument('-o', |
| 59 '--out-dir', | 59 '--out-dir', |
| 60 help='the output directory', | 60 help='the output directory', |
| 61 required=True, | 61 required=True, |
| 62 metavar='FILE') | 62 metavar='FILE') |
| 63 required_args.add_argument('-g', | |
| 64 '--gni-out-file', | |
| 65 help='the GN output file', | |
| 66 required=True, | |
| 67 metavar='FILE') | |
| 63 required_args.add_argument('-c', | 68 required_args.add_argument('-c', |
| 64 '--config-file', | 69 '--config-file', |
| 65 help='the config file path', | 70 help='the config file path', |
| 66 required=True, | 71 required=True, |
| 67 metavar='FILE') | 72 metavar='FILE') |
| 68 parser.add_argument('--config-help', | 73 parser.add_argument('--config-help', |
| 69 action='custom_help', | 74 action='custom_help', |
| 70 custom_help_text=utils.ConfigParser.__doc__, | 75 custom_help_text=utils.ConfigParser.__doc__, |
| 71 help='show the configuration file format help') | 76 help='show the configuration file format help') |
| 72 | 77 |
| 73 args = parser.parse_args() | 78 args = parser.parse_args() |
| 74 | 79 |
| 75 return ProcessGooglePlayServices(args.repository, | 80 return ProcessGooglePlayServices(args.repository, |
| 76 args.out_dir, | 81 args.out_dir, |
| 82 args.gni_out_file, | |
| 77 args.config_file) | 83 args.config_file) |
| 78 | 84 |
| 79 | 85 |
| 80 def ProcessGooglePlayServices(repo, out_dir, config_path): | 86 def ProcessGooglePlayServices(repo, out_dir, gni_out_file, config_path): |
| 81 config = utils.ConfigParser(config_path) | 87 config = utils.ConfigParser(config_path) |
| 82 | 88 |
| 83 tmp_root = tempfile.mkdtemp() | 89 tmp_root = tempfile.mkdtemp() |
| 84 try: | 90 try: |
| 85 tmp_paths = _SetupTempDir(tmp_root) | 91 tmp_paths = _SetupTempDir(tmp_root) |
| 86 _ImportFromExtractedRepo(config, tmp_paths, repo) | 92 _ImportFromExtractedRepo(config, tmp_paths, repo) |
| 87 _ProcessResources(config, tmp_paths, repo) | 93 _ProcessResources(config, tmp_paths, repo) |
| 88 _CopyToOutput(tmp_paths, out_dir) | 94 _CopyToOutput(tmp_paths, out_dir) |
| 95 _EnumerateProguardFiles(gni_out_file, out_dir) | |
| 89 _UpdateVersionInConfig(config, tmp_paths) | 96 _UpdateVersionInConfig(config, tmp_paths) |
| 90 finally: | 97 finally: |
| 91 shutil.rmtree(tmp_root) | 98 shutil.rmtree(tmp_root) |
| 92 | 99 |
| 93 return 0 | 100 return 0 |
| 94 | 101 |
| 95 | 102 |
| 96 def _SetupTempDir(tmp_root): | 103 def _SetupTempDir(tmp_root): |
| 97 tmp_paths = { | 104 tmp_paths = { |
| 98 'root': tmp_root, | 105 'root': tmp_root, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 shutil.copy(os.path.join(repo, whitelisted_file), rebased_res) | 187 shutil.copy(os.path.join(repo, whitelisted_file), rebased_res) |
| 181 finally: | 188 finally: |
| 182 _MakeWritable(rebased_res) | 189 _MakeWritable(rebased_res) |
| 183 | 190 |
| 184 | 191 |
| 185 def _CopyToOutput(tmp_paths, out_dir): | 192 def _CopyToOutput(tmp_paths, out_dir): |
| 186 shutil.rmtree(out_dir, ignore_errors=True) | 193 shutil.rmtree(out_dir, ignore_errors=True) |
| 187 shutil.copytree(tmp_paths['imported_clients'], out_dir) | 194 shutil.copytree(tmp_paths['imported_clients'], out_dir) |
| 188 | 195 |
| 189 | 196 |
| 197 gni_template = '''\ | |
|
jbudorick
2017/04/19 18:42:26
nits: _GNI_TEMPLATE + use textwrap.dedent + indent
paulmiller
2017/04/19 21:28:10
Thanks, I didn't know about dedent. But if I can i
jbudorick
2017/04/19 21:29:46
heh, it's at least a reminder to people working in
| |
| 198 # Copyright 2017 The Chromium Authors. All rights reserved. | |
| 199 # Use of this source code is governed by a BSD-style license that can be | |
| 200 # found in the LICENSE file. | |
| 201 | |
| 202 # This file generated by {script} | |
| 203 gms_proguard_configs = [ | |
| 204 {body} | |
| 205 ] | |
| 206 ''' | |
| 207 | |
| 208 # Write a GN file containing a list of each GMS client's proguard file (if any). | |
| 209 def _EnumerateProguardFiles(gni_path, out_dir): | |
| 210 gni_dir = os.path.dirname(gni_path) | |
| 211 | |
| 212 gni_lines = [] | |
| 213 for client_dir in os.listdir(out_dir): | |
| 214 proguard_path = os.path.join( | |
| 215 out_dir, client_dir, 'proguard.txt') | |
| 216 if os.path.exists(os.path.dirname(proguard_path)): | |
| 217 relative = os.path.relpath(proguard_path, gni_dir) | |
|
jbudorick
2017/04/19 18:42:26
I'm a bit concerned about the case in which out_di
paulmiller
2017/04/19 21:28:10
I'll make the paths absolute, then.
| |
| 218 gni_lines.append(' "' + relative + '",') | |
|
jbudorick
2017/04/19 18:42:26
nit: instead of the string appends, do
gni_lines
paulmiller
2017/04/19 21:28:10
Done.
| |
| 219 gni_lines.sort() | |
| 220 | |
| 221 gni_text = gni_template.format( | |
| 222 script=os.path.relpath(sys.argv[0], gni_dir), | |
| 223 body='\n'.join(gni_lines)) | |
| 224 | |
| 225 with open(gni_path, 'w') as gni_file: | |
| 226 gni_file.write(gni_text) | |
| 227 | |
| 228 | |
| 190 def _UpdateVersionInConfig(config, tmp_paths): | 229 def _UpdateVersionInConfig(config, tmp_paths): |
| 191 version_xml_path = os.path.join(tmp_paths['imported_clients'], | 230 version_xml_path = os.path.join(tmp_paths['imported_clients'], |
| 192 config.version_xml_path) | 231 config.version_xml_path) |
| 193 play_services_full_version = utils.GetVersionNumberFromLibraryResources( | 232 play_services_full_version = utils.GetVersionNumberFromLibraryResources( |
| 194 version_xml_path) | 233 version_xml_path) |
| 195 config.UpdateVersionNumber(play_services_full_version) | 234 config.UpdateVersionNumber(play_services_full_version) |
| 196 | 235 |
| 197 | 236 |
| 198 def _ExtractAll(zip_path, out_path): | 237 def _ExtractAll(zip_path, out_path): |
| 199 with zipfile.ZipFile(zip_path, 'r') as zip_file: | 238 with zipfile.ZipFile(zip_path, 'r') as zip_file: |
| 200 zip_file.extractall(out_path) | 239 zip_file.extractall(out_path) |
| 201 | 240 |
| 202 if __name__ == '__main__': | 241 if __name__ == '__main__': |
| 203 sys.exit(main()) | 242 sys.exit(main()) |
| OLD | NEW |