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

Unified Diff: build/check_sdk_extras_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: Added the GN check Created 5 years, 6 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_sdk_extras_version.py
diff --git a/build/check_sdk_extras_version.py b/build/check_sdk_extras_version.py
new file mode 100755
index 0000000000000000000000000000000000000000..56b46626014e81bf4ca828f55ad8f800f115dab6
--- /dev/null
+++ b/build/check_sdk_extras_version.py
@@ -0,0 +1,116 @@
+#!/usr/bin/env python
+# Copyright 2015 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.
+'''
+
+import argparse
+import json
+import os
+import re
+import sys
+
+
+COLORAMA_ROOT = os.path.join(os.path.dirname(__file__),
+ os.pardir, 'third_party', 'colorama', 'src')
+
+sys.path.append(COLORAMA_ROOT)
+import colorama
+
+
+UDPATE_SCRIPT_PATH = 'build/install-android-sdks.sh'
+
+SDK_EXTRAS_JSON_FILE = os.path.join(os.path.dirname(__file__),
+ 'android_sdk_extras.json')
+
+PKG_NOT_FOUND_MSG = ('Error while checking Android SDK extras versions. '
+ 'Could not find the "{package_id}" package in '
+ '{checked_location}. Please run {script} to download it.')
+UPDATE_NEEDED_MSG = ('Error while checking Android SDK extras versions. '
+ 'Version {required_version} is required for the package '
+ '"{package_id}". Version {actual_version} found. Please '
+ 'run {script} to update it.')
+REQUIRED_VERSION_ERROR_MSG = ('Error while checking Android SDK extras '
+ 'versions. '
+ 'Could not retrieve the required version for '
+ 'package "{package_id}".')
+
+
+def ExitError(msg):
+ sys.exit(colorama.Fore.MAGENTA + colorama.Style.BRIGHT + msg +
+ colorama.Fore.RESET)
+
+
+def GetRequiredVersion(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])
+
+ ExitError(REQUIRED_VERSION_ERROR_MSG.format(package_id=package_id))
+
+
+def CheckPackageVersion(pkg_id, 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):
+ ExitError(PKG_NOT_FOUND_MSG.format(
+ package_id=pkg_id,
+ checked_location=location,
+ script=UDPATE_SCRIPT_PATH))
+
+ with open(version_file_path, 'r') as f:
+ match = version_pattern.search(f.read())
+
+ if not match:
+ ExitError(PKG_NOT_FOUND_MSG.format(
+ package_id=pkg_id,
+ checked_location=location,
+ script=UDPATE_SCRIPT_PATH))
+
+ pkg_version = int(match.group('version'))
+ if pkg_version < required_version:
+ ExitError(UPDATE_NEEDED_MSG.format(
+ package_id=pkg_id,
+ required_version=required_version,
+ actual_version=pkg_version,
+ script=UDPATE_SCRIPT_PATH))
+
+ # Everything looks ok, print nothing.
+
+
+if __name__ == '__main__':
+ 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='Path to the package\'s expected install location.')
+ parser.add_argument('--stamp',
+ help=('If specified, a stamp file will be created at the '
+ 'provided location.'))
+
+ args = parser.parse_args()
+
+ required_version = GetRequiredVersion(args.package_id)
+ CheckPackageVersion(args.package_id, args.package_location, required_version)
+
+ # Create the stamp file.
+ if args.stamp:
+ with open(args.stamp, 'a'):
+ os.utime(args.stamp, None)
+
+ sys.exit(0)

Powered by Google App Engine
This is Rietveld 408576698