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

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

Issue 2827793005: Get Proguard flags from GMS clients (upstream part) (Closed)
Patch Set: . Created 3 years, 8 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 | no next file » | 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 builds 10 We need to preprocess Google Play services before using it in Chrome builds
(...skipping 10 matching lines...) Expand all
21 +-- CLIENT_1 21 +-- CLIENT_1
22 | +-- <content of the first AAR file> 22 | +-- <content of the first AAR file>
23 +-- CLIENT_2 23 +-- CLIENT_2
24 +-- etc. 24 +-- etc.
25 25
26 The output will follow the same structure, with fewer resource files, in the 26 The output will follow the same structure, with fewer resource files, in the
27 provided output directory. 27 provided output directory.
28 ''' 28 '''
29 29
30 import argparse 30 import argparse
31 import datetime
31 import glob 32 import glob
32 import itertools 33 import itertools
33 import os 34 import os
34 import shutil 35 import shutil
35 import stat 36 import stat
36 import sys 37 import sys
37 import tempfile 38 import tempfile
38 import zipfile 39 import zipfile
39 40
40 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) 41 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir))
(...skipping 12 matching lines...) Expand all
53 '--repository', 54 '--repository',
54 help=('the Google Play services repository ' 55 help=('the Google Play services repository '
55 'location'), 56 'location'),
56 required=True, 57 required=True,
57 metavar='FILE') 58 metavar='FILE')
58 required_args.add_argument('-o', 59 required_args.add_argument('-o',
59 '--out-dir', 60 '--out-dir',
60 help='the output directory', 61 help='the output directory',
61 required=True, 62 required=True,
62 metavar='FILE') 63 metavar='FILE')
64 required_args.add_argument('-g',
65 '--gni-out-file',
66 help='the GN output file',
67 required=True,
68 metavar='FILE')
63 required_args.add_argument('-c', 69 required_args.add_argument('-c',
64 '--config-file', 70 '--config-file',
65 help='the config file path', 71 help='the config file path',
66 required=True, 72 required=True,
67 metavar='FILE') 73 metavar='FILE')
68 parser.add_argument('--config-help', 74 parser.add_argument('--config-help',
69 action='custom_help', 75 action='custom_help',
70 custom_help_text=utils.ConfigParser.__doc__, 76 custom_help_text=utils.ConfigParser.__doc__,
71 help='show the configuration file format help') 77 help='show the configuration file format help')
72 78
73 args = parser.parse_args() 79 args = parser.parse_args()
74 80
75 return ProcessGooglePlayServices(args.repository, 81 return ProcessGooglePlayServices(args.repository,
76 args.out_dir, 82 args.out_dir,
83 args.gni_out_file,
77 args.config_file) 84 args.config_file)
78 85
79 86
80 def ProcessGooglePlayServices(repo, out_dir, config_path): 87 def ProcessGooglePlayServices(repo, out_dir, gni_out_file, config_path):
81 config = utils.ConfigParser(config_path) 88 config = utils.ConfigParser(config_path)
82 89
83 tmp_root = tempfile.mkdtemp() 90 tmp_root = tempfile.mkdtemp()
84 try: 91 try:
85 tmp_paths = _SetupTempDir(tmp_root) 92 tmp_paths = _SetupTempDir(tmp_root)
86 _ImportFromExtractedRepo(config, tmp_paths, repo) 93 _ImportFromExtractedRepo(config, tmp_paths, repo)
87 _ProcessResources(config, tmp_paths, repo) 94 _ProcessResources(config, tmp_paths, repo)
88 _CopyToOutput(tmp_paths, out_dir) 95 _CopyToOutput(tmp_paths, out_dir)
96 _EnumerateProguardFiles(gni_out_file, out_dir)
89 _UpdateVersionInConfig(config, tmp_paths) 97 _UpdateVersionInConfig(config, tmp_paths)
90 finally: 98 finally:
91 shutil.rmtree(tmp_root) 99 shutil.rmtree(tmp_root)
92 100
93 return 0 101 return 0
94 102
95 103
96 def _SetupTempDir(tmp_root): 104 def _SetupTempDir(tmp_root):
97 tmp_paths = { 105 tmp_paths = {
98 'root': tmp_root, 106 'root': tmp_root,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 shutil.copy(os.path.join(repo, whitelisted_file), rebased_res) 188 shutil.copy(os.path.join(repo, whitelisted_file), rebased_res)
181 finally: 189 finally:
182 _MakeWritable(rebased_res) 190 _MakeWritable(rebased_res)
183 191
184 192
185 def _CopyToOutput(tmp_paths, out_dir): 193 def _CopyToOutput(tmp_paths, out_dir):
186 shutil.rmtree(out_dir, ignore_errors=True) 194 shutil.rmtree(out_dir, ignore_errors=True)
187 shutil.copytree(tmp_paths['imported_clients'], out_dir) 195 shutil.copytree(tmp_paths['imported_clients'], out_dir)
188 196
189 197
198 gni_template = '''\
199 # Copyright {year} The Chromium Authors. All rights reserved.
Maria 2017/04/19 18:20:22 not sure that year should be computed. Generally c
paulmiller 2017/04/19 18:34:27 Done.
200 # Use of this source code is governed by a BSD-style license that can be
201 # found in the LICENSE file.
202
203 # This file generated by {script}
204 gms_proguard_configs = [
205 {body}
206 ]
207 '''
208
209 # Write a GN file containing a list of each GMS client's proguard file (if any).
210 def _EnumerateProguardFiles(gni_path, out_dir):
211 gni_dir = os.path.dirname(gni_path)
212
213 gni_lines = []
214 for client_dir in os.listdir(out_dir):
215 proguard_path = os.path.join(
216 out_dir, client_dir, 'proguard.txt')
217 if os.path.exists(os.path.dirname(proguard_path)):
218 relative = os.path.relpath(proguard_path, gni_dir)
219 gni_lines.append(' "' + relative + '",')
220 gni_lines.sort()
221
222 gni_text = gni_template.format(
223 year=datetime.datetime.now().year,
224 script=os.path.relpath(sys.argv[0], gni_dir),
225 body='\n'.join(gni_lines))
226
227 with open(gni_path, 'w') as gni_file:
228 gni_file.write(gni_text)
229
230
190 def _UpdateVersionInConfig(config, tmp_paths): 231 def _UpdateVersionInConfig(config, tmp_paths):
191 version_xml_path = os.path.join(tmp_paths['imported_clients'], 232 version_xml_path = os.path.join(tmp_paths['imported_clients'],
192 config.version_xml_path) 233 config.version_xml_path)
193 play_services_full_version = utils.GetVersionNumberFromLibraryResources( 234 play_services_full_version = utils.GetVersionNumberFromLibraryResources(
194 version_xml_path) 235 version_xml_path)
195 config.UpdateVersionNumber(play_services_full_version) 236 config.UpdateVersionNumber(play_services_full_version)
196 237
197 238
198 def _ExtractAll(zip_path, out_path): 239 def _ExtractAll(zip_path, out_path):
199 with zipfile.ZipFile(zip_path, 'r') as zip_file: 240 with zipfile.ZipFile(zip_path, 'r') as zip_file:
200 zip_file.extractall(out_path) 241 zip_file.extractall(out_path)
201 242
202 if __name__ == '__main__': 243 if __name__ == '__main__':
203 sys.exit(main()) 244 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698