[go: nahoru, domu]

Enable downloading Google Play services via deps hook

Call build/android/play_services/update.py from DEPS and
remove now unused scripts.

BUG=541727

Review URL: https://codereview.chromium.org/1418573010

Cr-Commit-Position: refs/heads/master@{#358326}
diff --git a/DEPS b/DEPS
index c45f2627..52a1becf 100644
--- a/DEPS
+++ b/DEPS
@@ -540,13 +540,15 @@
   },
   {
     # This downloads SDK extras and puts them in the
-    # third_party/android_tools/sdk/extras directory on the bots. Developers
-    # need to manually install these packages and accept the ToS.
+    # third_party/android_tools/sdk/extras directory.
     'name': 'sdkextras',
     'pattern': '.',
     # When adding a new sdk extras package to download, add the package
     # directory and zip file to .gitignore in third_party/android_tools.
-    'action': ['python', 'src/build/download_sdk_extras.py'],
+    'action': ['python',
+               'src/build/android/play_services/update.py',
+               'download'
+    ],
   },
   {
     # Downloads the current stable linux sysroot to build/linux/ if needed.
diff --git a/build/android_sdk_extras.json b/build/android_sdk_extras.json
deleted file mode 100644
index 2735e2f..0000000
--- a/build/android_sdk_extras.json
+++ /dev/null
@@ -1,9 +0,0 @@
-[
-  {
-    "dir_name": "google",
-    "version": "26.0.0",
-    "zip": "google_google_play_services_26.0.0.zip",
-    "package": "google_play_services",
-    "package_id": "extra-google-google_play_services"
-  }
-]
diff --git a/build/check_sdk_extras_version.py b/build/check_sdk_extras_version.py
index 9b2f10d..3f2e62b3 100755
--- a/build/check_sdk_extras_version.py
+++ b/build/check_sdk_extras_version.py
@@ -5,127 +5,6 @@
 
 '''Checks the status of an Android SDK package.
 
-Verifies the given package has been installed from the Android SDK Manager and
-that its version is at least the minimum version required by the project
-configuration.
+TODO(dgn) replaced by a direct update mechanism: http://crbug.com/541727
+This file is now a placeholder until removal after 2 sided patches.
 '''
-
-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')
-
-PACKAGE_VERSION_PATTERN = r'^Pkg\.Revision=(?P<version>\d+).*$'
-
-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 {minimum_version} or greater 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 main():
-  parser = argparse.ArgumentParser(description=__doc__)
-  parser.add_argument('--package-id',
-                      help=('id of the package to check for. The list of '
-                            'available packages and their 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.',
-                      metavar='DIR')
-  parser.add_argument('--stamp',
-                      help=('if specified, a stamp file will be created at the '
-                            'provided location.'),
-                      metavar='FILE')
-
-  args = parser.parse_args()
-
-  if not ShouldSkipVersionCheck():
-    minimum_version = GetRequiredMinimumVersion(args.package_id)
-    CheckPackageVersion(args.package_id, args.package_location, minimum_version)
-
-  # Create the stamp file.
-  if args.stamp:
-    with open(args.stamp, 'a'):
-      os.utime(args.stamp, None)
-
-  sys.exit(0)
-
-def ExitError(msg):
-  sys.exit(colorama.Fore.MAGENTA + colorama.Style.BRIGHT + msg +
-           colorama.Style.RESET_ALL)
-
-
-def GetRequiredMinimumVersion(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, minimum_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(PACKAGE_VERSION_PATTERN, re.MULTILINE)
-
-  if 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 < minimum_version:
-      ExitError(UPDATE_NEEDED_MSG.format(
-        package_id=pkg_id,
-        minimum_version=minimum_version,
-        actual_version=pkg_version,
-        script=UDPATE_SCRIPT_PATH))
-
-  # Everything looks ok, print nothing.
-
-def ShouldSkipVersionCheck():
-  '''
-  Bots should not run the version check, since they download the sdk extras
-  in a different way.
-  '''
-  return bool(os.environ.get('CHROME_HEADLESS'))
-
-if __name__ == '__main__':
-  main()
diff --git a/build/download_sdk_extras.py b/build/download_sdk_extras.py
deleted file mode 100755
index 7c3a678..0000000
--- a/build/download_sdk_extras.py
+++ /dev/null
@@ -1,99 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2014 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.
-
-"""Script to download sdk/extras packages on the bots from google storage.
-
-The script expects arguments that specify zips file in the google storage
-bucket named: <dir in SDK extras>_<package name>_<version>.zip. The file will
-be extracted in the android_tools/sdk/extras directory on the test bots. This
-script will not do anything for developers.
-
-TODO(navabi): Move this script (crbug.com/459819).
-"""
-
-import find_depot_tools
-import json
-import os
-import shutil
-import subprocess
-import sys
-import zipfile
-
-SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
-CHROME_SRC = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir))
-sys.path.insert(0, os.path.join(SCRIPT_DIR, 'android'))
-
-from pylib import constants
-
-DEPOT_PATH = find_depot_tools.add_depot_tools_to_path()
-GSUTIL_PATH = os.path.join(DEPOT_PATH, 'gsutil.py')
-SDK_EXTRAS_BUCKET = 'gs://chrome-sdk-extras'
-SDK_EXTRAS_PATH = os.path.join(constants.ANDROID_SDK_ROOT, 'extras')
-SDK_EXTRAS_JSON_FILE = os.path.join(os.path.dirname(__file__),
-                                    'android_sdk_extras.json')
-
-
-def clean_and_extract(dir_name, package_name, zip_file):
-  local_dir = '%s/%s/%s' % (SDK_EXTRAS_PATH, dir_name, package_name)
-  if os.path.exists(local_dir):
-    shutil.rmtree(local_dir)
-  local_zip = '%s/%s' % (SDK_EXTRAS_PATH, zip_file)
-  with zipfile.ZipFile(local_zip) as z:
-    z.extractall(path=SDK_EXTRAS_PATH)
-
-
-def download_package_if_needed(remote_file, local_file):
-  """Download a file from GCS.
-
-  Returns:
-    success (bool): True if the download succeeded, False otherwise.
-  """
-  if not os.path.exists(local_file):
-    try:
-      subprocess.check_call(['python', GSUTIL_PATH, '--force-version', '4.7',
-                             'cp', remote_file, local_file])
-    except subprocess.CalledProcessError:
-      print ('WARNING: Failed to download SDK packages. If this bot compiles '
-             'for Android, it may have errors.')
-      return False
-  return True
-
-def main():
-  if not os.environ.get('CHROME_HEADLESS'):
-    # This is not a buildbot checkout.
-    return 0
-  # Update the android_sdk_extras.json file to update downloaded packages.
-  with open(SDK_EXTRAS_JSON_FILE) as json_file:
-    packages = json.load(json_file)
-  for package in packages:
-    local_zip = '%s/%s' % (SDK_EXTRAS_PATH, package['zip'])
-    package_zip = '%s/%s' % (SDK_EXTRAS_BUCKET, package['zip'])
-    for attempt in xrange(2):
-      print '(%d) Downloading package %s' % (attempt + 1, package['zip'])
-      if not download_package_if_needed(package_zip, local_zip):
-        # Ignore errors when download failed to keep the corresponding build
-        # step green. The error we're ignoring here is essentially
-        # 'permission denied', because we're using the presence or absence of
-        # credentials on a build machine as the way to mark android builders.
-        # See crbug.com/460463 for more context.
-        return 0
-      try:
-        # Always clean dir and extract zip to ensure correct contents.
-        clean_and_extract(package['dir_name'],
-                          package['package'],
-                          package['zip'])
-        break
-      except zipfile.BadZipfile:
-        print 'Failed unpacking zip file. Deleting and retrying...'
-        os.remove(local_zip)
-
-    else:
-      print ('WARNING: Failed to unpack SDK packages. If this bot compiles '
-             'for Android, it may have errors.')
-      return 1
-
-
-if __name__ == '__main__':
-  sys.exit(main())
diff --git a/build/get_sdk_extras_packages.py b/build/get_sdk_extras_packages.py
deleted file mode 100755
index a90b8a8..0000000
--- a/build/get_sdk_extras_packages.py
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env python
-# Copyright (c) 2014 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.
-
-import json
-import os
-import sys
-
-SDK_EXTRAS_JSON_FILE = os.path.join(os.path.dirname(__file__),
-                                    'android_sdk_extras.json')
-
-def main():
-  with open(SDK_EXTRAS_JSON_FILE) as json_file:
-    packages = json.load(json_file)
-
-  out = []
-  for package in packages:
-    out.append(package['package_id'])
-
-  print ','.join(out)
-
-if __name__ == '__main__':
-  sys.exit(main())
diff --git a/build/install-android-sdks.sh b/build/install-android-sdks.sh
deleted file mode 100755
index 1119b7d7..0000000
--- a/build/install-android-sdks.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/bash -e
-
-# Copyright (c) 2012 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.
-
-# Script to install SDKs needed to build chromium on android.
-# See http://code.google.com/p/chromium/wiki/AndroidBuildInstructions
-
-echo 'checking for sdk packages install'
-# Use absolute path to call 'android' so script can be run from any directory.
-cwd=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
-# Get the SDK extras packages to install from the DEPS file 'sdkextras' hook.
-packages="$(python ${cwd}/get_sdk_extras_packages.py)"
-if [[ -n "${packages}" ]]; then
-  ${cwd}/../third_party/android_tools/sdk/tools/android update sdk --no-ui \
-      --filter ${packages}
-fi
-
-echo "install-android-sdks.sh complete."
diff --git a/build/install-build-deps-android.sh b/build/install-build-deps-android.sh
index cf87381..9c3692c7 100755
--- a/build/install-build-deps-android.sh
+++ b/build/install-build-deps-android.sh
@@ -13,11 +13,10 @@
 # past the curses-based dialog press TAB <ret> TAB <ret> to agree.
 
 args="$@"
+
+# TODO(dgn) remove this this argument from calls (http://crbug.com/541727)
 if test "$1" = "--skip-sdk-packages"; then
-  skip_inst_sdk_packages=1
   args="${@:2}"
-else
-  skip_inst_sdk_packages=0
 fi
 
 if ! uname -m | egrep -q "i686|x86_64"; then
@@ -92,9 +91,4 @@
   fi
 fi
 
-# Install SDK packages for android
-if test "$skip_inst_sdk_packages" != 1; then
-  "$(dirname "${BASH_SOURCE[0]}")/install-android-sdks.sh"
-fi
-
 echo "install-build-deps-android.sh complete."
diff --git a/build/secondary/third_party/android_tools/BUILD.gn b/build/secondary/third_party/android_tools/BUILD.gn
index 710b7d7a..c849d035 100644
--- a/build/secondary/third_party/android_tools/BUILD.gn
+++ b/build/secondary/third_party/android_tools/BUILD.gn
@@ -93,9 +93,6 @@
   v14_skip = true
   resource_dirs = [ "$android_sdk_root/extras/google/google_play_services/libproject/google-play-services_lib/res" ]
   custom_package = "com.google.android.gms"
-  deps = [
-    ":check_sdk_extras_version",
-  ]
 }
 android_java_prebuilt("google_play_services_default_java") {
   deps = [
@@ -106,34 +103,9 @@
   ]
   proguard_preprocess = true
   proguard_config = "//third_party/android_tools/proguard.flags"
-
-  # TODO(dgn) deps should not complain about having a custom action here
-  # Currently, there is no guarantee that the data_deps actions will complete before the current one runs
-  data_deps = [
-    ":check_sdk_extras_version",
-  ]
   jar_path = "$android_sdk_root/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar"
 }
 
-action("check_sdk_extras_version") {
-  script = "//build/check_sdk_extras_version.py"
-  args = [
-    "--package-id",
-    "extra-google-google_play_services",
-    "--package-location",
-    rebase_path("$android_sdk_root/extras/google/google_play_services"),
-    "--stamp",
-    rebase_path("$target_gen_dir/checked_sdk_extras_version.stamp"),
-  ]
-  inputs = [
-    "//build/android_sdk_extras.json",
-    "$android_sdk_root/extras/google/google_play_services/source.properties",
-  ]
-  outputs = [
-    "$target_gen_dir/checked_sdk_extras_version.stamp",
-  ]
-}
-
 # TODO(jbudorick): Remove this once net_java_test_support no longer needs it.
 android_java_prebuilt("legacy_http_javalib") {
   jar_path = "$android_sdk/optional/org.apache.http.legacy.jar"