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

Unified Diff: build/check_play_services_version.py

Issue 1152203003: Add script to validate installed Android SDK packages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months 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 side-by-side diff with in-line comments
Download patch
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.
Andrew Hayden (chromium.org) 2015/05/28 12:55:00 It's totally 2015, man.
dgn 2015/06/08 14:34:09 Done.
+# 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} '
+ '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'
+END_STYLE = '\033[0m'
+
+def print_and_exit(msg):
+ """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)

Powered by Google App Engine
This is Rietveld 408576698