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

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: Address comments 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 @property
57 def version_number(self): 79 def version_number(self):
58 return self.data[self._VERSION_NUMBER_KEY] 80 return self._data.get(self._VERSION_NUMBER_KEY)
81
82 @property
83 def sdk_version(self):
84 return self._data.get('sdk_version')
85
86 @property
87 def clients(self):
88 return self._data.get('clients') or []
89
90 @property
91 def version_xml_path(self):
92 return self._data.get('version_xml_path')
93
94 @property
95 def locale_whitelist(self):
96 return self._data.get('locale_whitelist') or []
59 97
60 def UpdateVersionNumber(self, new_version_number): 98 def UpdateVersionNumber(self, new_version_number):
61 '''Updates the version number and saves it in the configuration file. ''' 99 '''Updates the version number and saves it in the configuration file. '''
62 100
63 with open(self.path, 'w') as stream: 101 with open(self.path, 'w') as stream:
64 self.data[self._VERSION_NUMBER_KEY] = new_version_number 102 self._data[self._VERSION_NUMBER_KEY] = new_version_number
65 json.dump(self.data, stream, sort_keys=True, indent=2) 103 stream.write(DumpTrimmedJson(self._data))
66 stream.write(os.linesep) 104
105
106 def DumpTrimmedJson(json_data):
107 '''
108 Default formatting when dumping json to string has trailing spaces and lacks
109 a new line at the end. This function fixes that.
110 '''
111
112 out = json.dumps(json_data, sort_keys=True, indent=2)
113 out = out.replace(' ' + os.linesep, os.linesep)
114 return out + os.linesep
67 115
68 116
69 def FileEquals(expected_file, actual_file): 117 def FileEquals(expected_file, actual_file):
70 ''' 118 '''
71 Returns whether the two files are equal. Returns False if any of the files 119 Returns whether the two files are equal. Returns False if any of the files
72 doesn't exist. 120 doesn't exist.
73 ''' 121 '''
74 122
75 if not os.path.isfile(actual_file) or not os.path.isfile(expected_file): 123 if not os.path.isfile(actual_file) or not os.path.isfile(expected_file):
76 return False 124 return False
(...skipping 27 matching lines...) Expand all
104 def MakeLocalCommit(repo_root, files_to_commit, message): 152 def MakeLocalCommit(repo_root, files_to_commit, message):
105 '''Makes a local git commit.''' 153 '''Makes a local git commit.'''
106 154
107 logging.debug('Staging files (%s) for commit.', files_to_commit) 155 logging.debug('Staging files (%s) for commit.', files_to_commit)
108 if cmd_helper.Call(['git', 'add'] + files_to_commit, cwd=repo_root) != 0: 156 if cmd_helper.Call(['git', 'add'] + files_to_commit, cwd=repo_root) != 0:
109 raise Exception('The local commit failed.') 157 raise Exception('The local commit failed.')
110 158
111 logging.debug('Committing.') 159 logging.debug('Committing.')
112 if cmd_helper.Call(['git', 'commit', '-m', message], cwd=repo_root) != 0: 160 if cmd_helper.Call(['git', 'commit', '-m', message], cwd=repo_root) != 0:
113 raise Exception('The local commit failed.') 161 raise Exception('The local commit failed.')
OLDNEW
« no previous file with comments | « build/android/play_services/update_test.py ('k') | build/android/preprocess_google_play_services.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698