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

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

Issue 1469913002: Cleanup gms update/preprocess scripts, roll android_tools (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change the way the config is loaded Created 5 years 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
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 ''' 5 '''
6 Utility functions for all things related to manipulating google play services 6 Utility functions for all things related to manipulating google play services
7 related files. 7 related files.
8 ''' 8 '''
9 9
10 import argparse 10 import argparse
(...skipping 25 matching lines...) Expand all
36 class ConfigParser(object): 36 class ConfigParser(object):
37 '''Reads and writes the configuration files for play services related scripts 37 '''Reads and writes the configuration files for play services related scripts
38 38
39 The configuration files are JSON files. Here is the data they are expected 39 The configuration files are JSON files. Here is the data they are expected
40 to contain: 40 to contain:
41 41
42 - version_number 42 - version_number
43 Number. Mirrors @integer/google_play_services_version from the library. 43 Number. Mirrors @integer/google_play_services_version from the library.
44 Example: 815000 44 Example: 815000
45 45
46 - sdk_version
47 Version of the Play Services SDK to retrieve, when preprocessing the
48 library from a maven/gradle repository.
49 Example: "8.1.0"
50
51 - clients
52 List of strings. Name of the clients (or play services modules) to
53 include when preprocessing the library.
54 Example: ["play-services-base", "play-services-cast"]
55
56 - version_xml_path
57 String. Path to the version.xml string describing the current version.
58 Should be relative to the library base directory
59 Example: "res/values/version.xml"
60
61 - locale_whitelist
62 List of strings. List of locales to keep from the resources. Can be
63 obtained by generating an android build and looking at the content of
64 `out/Debug/gen/chrome/java/res`; or looking at the android section in
65 `//chrome/app/generated_resources.grd`
66 Example: ["am", "ar", "bg", "ca", "cs"]
67
46 ''' 68 '''
47 _VERSION_NUMBER_KEY = 'version_number' 69 _VERSION_NUMBER_KEY = 'version_number'
48 70
49 def __init__(self, path): 71 def __init__(self, path):
50 self.path = path 72 self.path = path
51 self.data = {} 73 self._data = {}
52 74
53 with open(path, 'r') as stream: 75 with open(path, 'r') as stream:
54 self.data = json.load(stream) 76 self._data = json.load(stream)
55 77
56 @property 78 self.version_number = self._data.get(self._VERSION_NUMBER_KEY)
jbudorick 2015/12/16 15:25:42 Having these as public members might imply to a cl
dgn 2015/12/16 16:10:09 Done.
57 def version_number(self): 79 self.sdk_version = self._data.get('sdk_version')
58 return self.data[self._VERSION_NUMBER_KEY] 80 self.clients = self._data.get('clients') or []
81 self.version_xml_path = self._data.get('version_xml_path')
82 self.locale_whitelist = self._data.get('locale_whitelist') or []
59 83
60 def UpdateVersionNumber(self, new_version_number): 84 def UpdateVersionNumber(self, new_version_number):
61 '''Updates the version number and saves it in the configuration file. ''' 85 '''Updates the version number and saves it in the configuration file. '''
62 86
63 with open(self.path, 'w') as stream: 87 with open(self.path, 'w') as stream:
64 self.data[self._VERSION_NUMBER_KEY] = new_version_number 88 self._data[self._VERSION_NUMBER_KEY] = new_version_number
65 json.dump(self.data, stream, sort_keys=True, indent=2) 89 stream.write(DumpTrimmedJson(self._data))
66 stream.write(os.linesep) 90
91 def DumpTrimmedJson(json_data):
92 '''
93 Default formatting when dumping json to string has trailing spaces and lacks
94 a new line at the end. This function fixes that.
95 '''
96
97 out = json.dumps(json_data, sort_keys=True, indent=2)
98 out = out.replace(' ' + os.linesep, os.linesep)
99 return out + os.linesep
67 100
68 101
69 def FileEquals(expected_file, actual_file): 102 def FileEquals(expected_file, actual_file):
70 ''' 103 '''
71 Returns whether the two files are equal. Returns False if any of the files 104 Returns whether the two files are equal. Returns False if any of the files
72 doesn't exist. 105 doesn't exist.
73 ''' 106 '''
74 107
75 if not os.path.isfile(actual_file) or not os.path.isfile(expected_file): 108 if not os.path.isfile(actual_file) or not os.path.isfile(expected_file):
76 return False 109 return False
(...skipping 27 matching lines...) Expand all
104 def MakeLocalCommit(repo_root, files_to_commit, message): 137 def MakeLocalCommit(repo_root, files_to_commit, message):
105 '''Makes a local git commit.''' 138 '''Makes a local git commit.'''
106 139
107 logging.debug('Staging files (%s) for commit.', files_to_commit) 140 logging.debug('Staging files (%s) for commit.', files_to_commit)
108 if cmd_helper.Call(['git', 'add'] + files_to_commit, cwd=repo_root) != 0: 141 if cmd_helper.Call(['git', 'add'] + files_to_commit, cwd=repo_root) != 0:
109 raise Exception('The local commit failed.') 142 raise Exception('The local commit failed.')
110 143
111 logging.debug('Committing.') 144 logging.debug('Committing.')
112 if cmd_helper.Call(['git', 'commit', '-m', message], cwd=repo_root) != 0: 145 if cmd_helper.Call(['git', 'commit', '-m', message], cwd=repo_root) != 0:
113 raise Exception('The local commit failed.') 146 raise Exception('The local commit failed.')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698