| 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 17 matching lines...) Expand all Loading... |
| 28 ''' | 28 ''' |
| 29 | 29 |
| 30 import argparse | 30 import argparse |
| 31 import glob | 31 import glob |
| 32 import itertools | 32 import itertools |
| 33 import os | 33 import os |
| 34 import shutil | 34 import shutil |
| 35 import stat | 35 import stat |
| 36 import sys | 36 import sys |
| 37 import tempfile | 37 import tempfile |
| 38 import textwrap |
| 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)) |
| 41 from play_services import utils | 42 from play_services import utils |
| 42 from pylib.utils import argparse_utils | 43 from pylib.utils import argparse_utils |
| 43 | 44 |
| 44 | 45 |
| 45 def main(): | 46 def main(): |
| 46 parser = argparse.ArgumentParser(description=( | 47 parser = argparse.ArgumentParser(description=( |
| 47 "Prepares the Google Play services split client libraries before usage " | 48 "Prepares the Google Play services split client libraries before usage " |
| 48 "by Chrome's build system. See the script's documentation for more a " | 49 "by Chrome's build system. See the script's documentation for more a " |
| 49 "detailed help.")) | 50 "detailed help.")) |
| 50 argparse_utils.CustomHelpAction.EnableFor(parser) | 51 argparse_utils.CustomHelpAction.EnableFor(parser) |
| 51 required_args = parser.add_argument_group('required named arguments') | 52 required_args = parser.add_argument_group('required named arguments') |
| 52 required_args.add_argument('-r', | 53 required_args.add_argument('-r', |
| 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') |
| 59 required_args.add_argument('-d', |
| 60 '--root-dir', |
| 61 help='the directory which GN considers the root', |
| 62 required=True, |
| 63 metavar='FILE') |
| 58 required_args.add_argument('-o', | 64 required_args.add_argument('-o', |
| 59 '--out-dir', | 65 '--out-dir', |
| 60 help='the output directory', | 66 help='the output directory', |
| 61 required=True, | 67 required=True, |
| 62 metavar='FILE') | 68 metavar='FILE') |
| 69 required_args.add_argument('-g', |
| 70 '--gni-out-file', |
| 71 help='the GN output file', |
| 72 required=True, |
| 73 metavar='FILE') |
| 63 required_args.add_argument('-c', | 74 required_args.add_argument('-c', |
| 64 '--config-file', | 75 '--config-file', |
| 65 help='the config file path', | 76 help='the config file path', |
| 66 required=True, | 77 required=True, |
| 67 metavar='FILE') | 78 metavar='FILE') |
| 68 parser.add_argument('--config-help', | 79 parser.add_argument('--config-help', |
| 69 action='custom_help', | 80 action='custom_help', |
| 70 custom_help_text=utils.ConfigParser.__doc__, | 81 custom_help_text=utils.ConfigParser.__doc__, |
| 71 help='show the configuration file format help') | 82 help='show the configuration file format help') |
| 72 | 83 |
| 73 args = parser.parse_args() | 84 args = parser.parse_args() |
| 74 | 85 |
| 75 return ProcessGooglePlayServices(args.repository, | 86 return ProcessGooglePlayServices(args.repository, |
| 87 args.root_dir, |
| 76 args.out_dir, | 88 args.out_dir, |
| 89 args.gni_out_file, |
| 77 args.config_file) | 90 args.config_file) |
| 78 | 91 |
| 79 | 92 |
| 80 def ProcessGooglePlayServices(repo, out_dir, config_path): | 93 def ProcessGooglePlayServices( |
| 94 repo, root_dir, out_dir, gni_out_file, config_path): |
| 81 config = utils.ConfigParser(config_path) | 95 config = utils.ConfigParser(config_path) |
| 82 | 96 |
| 83 tmp_root = tempfile.mkdtemp() | 97 tmp_root = tempfile.mkdtemp() |
| 84 try: | 98 try: |
| 85 tmp_paths = _SetupTempDir(tmp_root) | 99 tmp_paths = _SetupTempDir(tmp_root) |
| 86 _ImportFromExtractedRepo(config, tmp_paths, repo) | 100 _ImportFromExtractedRepo(config, tmp_paths, repo) |
| 87 _ProcessResources(config, tmp_paths, repo) | 101 _ProcessResources(config, tmp_paths, repo) |
| 88 _CopyToOutput(tmp_paths, out_dir) | 102 _CopyToOutput(tmp_paths, out_dir) |
| 103 _EnumerateProguardFiles(root_dir, out_dir, gni_out_file) |
| 89 _UpdateVersionInConfig(config, tmp_paths) | 104 _UpdateVersionInConfig(config, tmp_paths) |
| 90 finally: | 105 finally: |
| 91 shutil.rmtree(tmp_root) | 106 shutil.rmtree(tmp_root) |
| 92 | 107 |
| 93 return 0 | 108 return 0 |
| 94 | 109 |
| 95 | 110 |
| 96 def _SetupTempDir(tmp_root): | 111 def _SetupTempDir(tmp_root): |
| 97 tmp_paths = { | 112 tmp_paths = { |
| 98 'root': tmp_root, | 113 '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) | 195 shutil.copy(os.path.join(repo, whitelisted_file), rebased_res) |
| 181 finally: | 196 finally: |
| 182 _MakeWritable(rebased_res) | 197 _MakeWritable(rebased_res) |
| 183 | 198 |
| 184 | 199 |
| 185 def _CopyToOutput(tmp_paths, out_dir): | 200 def _CopyToOutput(tmp_paths, out_dir): |
| 186 shutil.rmtree(out_dir, ignore_errors=True) | 201 shutil.rmtree(out_dir, ignore_errors=True) |
| 187 shutil.copytree(tmp_paths['imported_clients'], out_dir) | 202 shutil.copytree(tmp_paths['imported_clients'], out_dir) |
| 188 | 203 |
| 189 | 204 |
| 205 # Write a GN file containing a list of each GMS client's proguard file (if any). |
| 206 def _EnumerateProguardFiles(root_dir, out_dir, gni_path): |
| 207 gni_dir = os.path.dirname(gni_path) |
| 208 gni_template = textwrap.dedent('''\ |
| 209 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 210 # Use of this source code is governed by a BSD-style license that can be |
| 211 # found in the LICENSE file. |
| 212 |
| 213 # This file generated by {script} |
| 214 gms_proguard_configs = [ |
| 215 {body} |
| 216 ] |
| 217 ''') |
| 218 |
| 219 gni_lines = [] |
| 220 for client_dir in os.listdir(out_dir): |
| 221 proguard_path = os.path.join( |
| 222 out_dir, client_dir, 'proguard.txt') |
| 223 if os.path.exists(os.path.dirname(proguard_path)): |
| 224 rooted_path = os.path.relpath(proguard_path, root_dir) |
| 225 gni_lines.append(' "//{}",'.format(rooted_path)) |
| 226 gni_lines.sort() |
| 227 |
| 228 gni_text = gni_template.format( |
| 229 script=os.path.relpath(sys.argv[0], gni_dir), |
| 230 body='\n'.join(gni_lines)) |
| 231 |
| 232 with open(gni_path, 'w') as gni_file: |
| 233 gni_file.write(gni_text) |
| 234 |
| 235 |
| 190 def _UpdateVersionInConfig(config, tmp_paths): | 236 def _UpdateVersionInConfig(config, tmp_paths): |
| 191 version_xml_path = os.path.join(tmp_paths['imported_clients'], | 237 version_xml_path = os.path.join(tmp_paths['imported_clients'], |
| 192 config.version_xml_path) | 238 config.version_xml_path) |
| 193 play_services_full_version = utils.GetVersionNumberFromLibraryResources( | 239 play_services_full_version = utils.GetVersionNumberFromLibraryResources( |
| 194 version_xml_path) | 240 version_xml_path) |
| 195 config.UpdateVersionNumber(play_services_full_version) | 241 config.UpdateVersionNumber(play_services_full_version) |
| 196 | 242 |
| 197 | 243 |
| 198 def _ExtractAll(zip_path, out_path): | 244 def _ExtractAll(zip_path, out_path): |
| 199 with zipfile.ZipFile(zip_path, 'r') as zip_file: | 245 with zipfile.ZipFile(zip_path, 'r') as zip_file: |
| 200 zip_file.extractall(out_path) | 246 zip_file.extractall(out_path) |
| 201 | 247 |
| 202 if __name__ == '__main__': | 248 if __name__ == '__main__': |
| 203 sys.exit(main()) | 249 sys.exit(main()) |
| OLD | NEW |