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 # Write a GN file containing a list of each GMS client's proguard file (if any). | |
198 def _EnumerateProguardFiles(gni_path, out_dir): | |
199 gni_dir = os.path.dirname(gni_path) | |
200 script_name = os.path.relpath(sys.argv[0], gni_dir) | |
201 | |
202 gni_text = '# This file generated by ' + script_name + '\n' | |
Maria
2017/04/19 05:40:35
Copyright should go here I guess.
| |
203 gni_text += 'gms_proguard_configs = [\n' | |
jbudorick
2017/04/18 23:59:12
Build the (sorted) list of extant proguard files,
paulmiller
2017/04/19 17:30:13
It looks like pformat emits single quotes. Not sur
jbudorick
2017/04/19 18:42:26
Ah, yeah, you're right.
| |
204 for client_dir in os.listdir(out_dir): | |
205 proguard_path = os.path.join( | |
206 out_dir, client_dir, 'proguard.txt') | |
207 if os.path.exists(os.path.dirname(proguard_path)): | |
208 relative = os.path.relpath(proguard_path, gni_dir) | |
209 gni_text += ' "' + relative + '",\n' | |
210 gni_text += ']\n' | |
211 | |
212 with open(gni_path, 'w') as gni_file: | |
213 gni_file.write(gni_text) | |
214 | |
215 | |
190 def _UpdateVersionInConfig(config, tmp_paths): | 216 def _UpdateVersionInConfig(config, tmp_paths): |
191 version_xml_path = os.path.join(tmp_paths['imported_clients'], | 217 version_xml_path = os.path.join(tmp_paths['imported_clients'], |
192 config.version_xml_path) | 218 config.version_xml_path) |
193 play_services_full_version = utils.GetVersionNumberFromLibraryResources( | 219 play_services_full_version = utils.GetVersionNumberFromLibraryResources( |
194 version_xml_path) | 220 version_xml_path) |
195 config.UpdateVersionNumber(play_services_full_version) | 221 config.UpdateVersionNumber(play_services_full_version) |
196 | 222 |
197 | 223 |
198 def _ExtractAll(zip_path, out_path): | 224 def _ExtractAll(zip_path, out_path): |
199 with zipfile.ZipFile(zip_path, 'r') as zip_file: | 225 with zipfile.ZipFile(zip_path, 'r') as zip_file: |
200 zip_file.extractall(out_path) | 226 zip_file.extractall(out_path) |
201 | 227 |
202 if __name__ == '__main__': | 228 if __name__ == '__main__': |
203 sys.exit(main()) | 229 sys.exit(main()) |
OLD | NEW |