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

Side by Side Diff: build/check_sdk_extras_version.py

Issue 1418573010: Enable downloading Google Play services via deps hook (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on master Created 5 years, 1 month 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 | « build/android_sdk_extras.json ('k') | build/download_sdk_extras.py » ('j') | 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 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 '''Checks the status of an Android SDK package. 6 '''Checks the status of an Android SDK package.
7 7
8 Verifies the given package has been installed from the Android SDK Manager and 8 TODO(dgn) replaced by a direct update mechanism: http://crbug.com/541727
9 that its version is at least the minimum version required by the project 9 This file is now a placeholder until removal after 2 sided patches.
10 configuration.
11 ''' 10 '''
12
13 import argparse
14 import json
15 import os
16 import re
17 import sys
18
19
20 COLORAMA_ROOT = os.path.join(os.path.dirname(__file__),
21 os.pardir, 'third_party', 'colorama', 'src')
22
23 sys.path.append(COLORAMA_ROOT)
24 import colorama
25
26
27 UDPATE_SCRIPT_PATH = 'build/install-android-sdks.sh'
28
29 SDK_EXTRAS_JSON_FILE = os.path.join(os.path.dirname(__file__),
30 'android_sdk_extras.json')
31
32 PACKAGE_VERSION_PATTERN = r'^Pkg\.Revision=(?P<version>\d+).*$'
33
34 PKG_NOT_FOUND_MSG = ('Error while checking Android SDK extras versions. '
35 'Could not find the "{package_id}" package in '
36 '{checked_location}. Please run {script} to download it.')
37 UPDATE_NEEDED_MSG = ('Error while checking Android SDK extras versions. '
38 'Version {minimum_version} or greater is required for the '
39 'package "{package_id}". Version {actual_version} found. '
40 'Please run {script} to update it.')
41 REQUIRED_VERSION_ERROR_MSG = ('Error while checking Android SDK extras '
42 'versions. '
43 'Could not retrieve the required version for '
44 'package "{package_id}".')
45
46
47 def main():
48 parser = argparse.ArgumentParser(description=__doc__)
49 parser.add_argument('--package-id',
50 help=('id of the package to check for. The list of '
51 'available packages and their ids can be obtained '
52 'by running '
53 'third_party/android_tools/sdk/tools/android list '
54 'sdk --extended'))
55 parser.add_argument('--package-location',
56 help='path to the package\'s expected install location.',
57 metavar='DIR')
58 parser.add_argument('--stamp',
59 help=('if specified, a stamp file will be created at the '
60 'provided location.'),
61 metavar='FILE')
62
63 args = parser.parse_args()
64
65 if not ShouldSkipVersionCheck():
66 minimum_version = GetRequiredMinimumVersion(args.package_id)
67 CheckPackageVersion(args.package_id, args.package_location, minimum_version)
68
69 # Create the stamp file.
70 if args.stamp:
71 with open(args.stamp, 'a'):
72 os.utime(args.stamp, None)
73
74 sys.exit(0)
75
76 def ExitError(msg):
77 sys.exit(colorama.Fore.MAGENTA + colorama.Style.BRIGHT + msg +
78 colorama.Style.RESET_ALL)
79
80
81 def GetRequiredMinimumVersion(package_id):
82 with open(SDK_EXTRAS_JSON_FILE, 'r') as json_file:
83 packages = json.load(json_file)
84
85 for package in packages:
86 if package['package_id'] == package_id:
87 return int(package['version'].split('.')[0])
88
89 ExitError(REQUIRED_VERSION_ERROR_MSG.format(package_id=package_id))
90
91
92 def CheckPackageVersion(pkg_id, location, minimum_version):
93 version_file_path = os.path.join(location, 'source.properties')
94 # Extracts the version of the package described by the property file. We only
95 # care about the major version number here.
96 version_pattern = re.compile(PACKAGE_VERSION_PATTERN, re.MULTILINE)
97
98 if not os.path.isfile(version_file_path):
99 ExitError(PKG_NOT_FOUND_MSG.format(
100 package_id=pkg_id,
101 checked_location=location,
102 script=UDPATE_SCRIPT_PATH))
103
104 with open(version_file_path, 'r') as f:
105 match = version_pattern.search(f.read())
106
107 if not match:
108 ExitError(PKG_NOT_FOUND_MSG.format(
109 package_id=pkg_id,
110 checked_location=location,
111 script=UDPATE_SCRIPT_PATH))
112
113 pkg_version = int(match.group('version'))
114 if pkg_version < minimum_version:
115 ExitError(UPDATE_NEEDED_MSG.format(
116 package_id=pkg_id,
117 minimum_version=minimum_version,
118 actual_version=pkg_version,
119 script=UDPATE_SCRIPT_PATH))
120
121 # Everything looks ok, print nothing.
122
123 def ShouldSkipVersionCheck():
124 '''
125 Bots should not run the version check, since they download the sdk extras
126 in a different way.
127 '''
128 return bool(os.environ.get('CHROME_HEADLESS'))
129
130 if __name__ == '__main__':
131 main()
OLDNEW
« no previous file with comments | « build/android_sdk_extras.json ('k') | build/download_sdk_extras.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698