Chromium Code Reviews| Index: build/check_play_services_version.py |
| diff --git a/build/check_play_services_version.py b/build/check_play_services_version.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..de5696ba60c677707323c0a3ff2b6d03e8408303 |
| --- /dev/null |
| +++ b/build/check_play_services_version.py |
| @@ -0,0 +1,101 @@ |
| +#!/usr/bin/env python |
| +# Copyright 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +'''Checks the status of an android SDK package. |
| + |
| +Verifies the given package has been installed from the Android SDK Manager and |
| +that it is at an appropriate version. Prints only when there is an error. |
| +''' |
| + |
| +import argparse |
| +import os |
| +import re |
| +import json |
| + |
| +UDPATE_SCRIPT_PATH = 'build/install-build-deps-android.sh' |
| + |
| +SDK_EXTRAS_JSON_FILE = os.path.join(os.path.dirname(__file__), |
| + 'android_sdk_extras.json') |
| + |
| +REPO_NOT_FOUND_MSG = ('Could not find the Google Play services package in ' |
| + '{checked_location}. Please run {script} to download it. ' |
| + 'You might have to run it as root.') |
| +UPDATE_NEEDED_MSG = ('Google Play services package version {required_version} ' |
|
cjhopman
2015/05/22 20:25:22
Places in this file explicitly refer to google pla
dgn
2015/06/08 14:34:10
Done.
|
| + 'is required. Version {actual_version} found. Please run ' |
| + '{script} to update it. You might have to run it as root.') |
| +REQUIRED_VERSION_ERROR_MSG = ('Could not retrieve the required Google Play ' |
| + 'services package version.') |
| + |
| +BOLD_STYLE = '\033[1m' |
|
cjhopman
2015/05/22 20:25:22
I don't think I'd hardcode in these escape codes.
dgn
2015/06/08 14:34:09
Done.
|
| +END_STYLE = '\033[0m' |
| + |
| +def print_and_exit(msg): |
|
cjhopman
2015/05/22 20:25:22
python functions use CapWords() style
dgn
2015/06/08 14:34:09
Done.
|
| + """Should always exit with a success code for gyp to pick up the message. """ |
| + print('---------------\n') |
| + print(BOLD_STYLE + msg + END_STYLE) |
| + print('\n---------------') |
| + exit(0) |
| + |
| + |
| +def parse_args(): |
| + parser = argparse.ArgumentParser(description=__doc__) |
| + parser.add_argument('package_id', |
| + help=('Id of the package to check for. The list of ' |
| + 'possible ids can be obtained by running ' |
| + 'third_party/android_tools/sdk/tools/android list ' |
| + 'sdk --extended')) |
| + parser.add_argument('package_location', |
| + help=('Absolute path to the expected install location of ' |
| + 'the package')) |
| + |
| + return parser.parse_args() |
| + |
| + |
| +def get_required_version(package_id): |
| + with open(SDK_EXTRAS_JSON_FILE, 'r') as json_file: |
| + packages = json.load(json_file) |
| + |
| + for package in packages: |
| + if package['package_id'] == package_id: |
| + return int(package['version'].split('.')[0]) |
| + |
| + print_and_exit(REQUIRED_VERSION_ERROR_MSG) |
| + |
| + |
| +def check_m2repo_version(location, required_version): |
| + version_file_path = os.path.join(location, 'source.properties') |
| + # Extracts the version of the package described by the property file. We only |
| + # care about the major version number here. |
| + version_pattern = re.compile(r'^Pkg\.Revision=(?P<version>\d+).*$', |
| + re.MULTILINE) |
| + |
| + if not os.path.isdir(location) or not os.path.isfile(version_file_path): |
| + print_and_exit(REPO_NOT_FOUND_MSG.format( |
| + checked_location=location, |
| + script=UDPATE_SCRIPT_PATH)) |
| + |
| + with open(version_file_path, 'r') as f: |
| + match = version_pattern.search(f.read()) |
| + |
| + if not match: |
| + print_and_exit(REPO_NOT_FOUND_MSG.format( |
| + checked_location=location, |
| + script=UDPATE_SCRIPT_PATH)) |
| + |
| + pkg_version = int(match.group('version')) |
| + if pkg_version < required_version: |
| + print_and_exit(UPDATE_NEEDED_MSG.format( |
| + required_version=required_version, |
| + actual_version=pkg_version, |
| + script=UDPATE_SCRIPT_PATH)) |
| + |
| + # Everything looks ok, print nothing. |
| + |
| + |
| +if __name__ == '__main__': |
| + args = parse_args() |
| + required_version = get_required_version(args.package_id) |
| + check_m2repo_version(args.package_location, required_version) |
| + exit(0) |