aboutsummaryrefslogtreecommitdiffhomepage
path: root/infra/bots
diff options
context:
space:
mode:
authorGravatar borenet <borenet@chromium.org>2016-06-30 05:20:03 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-06-30 05:20:03 -0700
commit501ca7f538f129efd27113e641ad17363920886e (patch)
tree2afa19d3562088e55fb0889d9b69eac456594f9f /infra/bots
parentdf4f47b8ff6378c4d8f775dcb3169ac7c64f2510 (diff)
Add Android SDK asset
This will allow us to use CIPD to install the Android SDK on bots. BUG=skia:5427 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2086003002 Review-Url: https://codereview.chromium.org/2086003002
Diffstat (limited to 'infra/bots')
-rw-r--r--infra/bots/android_sdk.isolate7
-rw-r--r--infra/bots/android_sdk_hash1
-rw-r--r--infra/bots/assets/android_sdk/VERSION1
-rwxr-xr-xinfra/bots/assets/android_sdk/common.py26
-rw-r--r--infra/bots/assets/android_sdk/create.py39
-rwxr-xr-xinfra/bots/assets/android_sdk/create_and_upload.py47
-rwxr-xr-xinfra/bots/assets/android_sdk/download.py16
-rwxr-xr-xinfra/bots/assets/android_sdk/upload.py16
-rw-r--r--infra/bots/isolate_android_sdk.py129
9 files changed, 145 insertions, 137 deletions
diff --git a/infra/bots/android_sdk.isolate b/infra/bots/android_sdk.isolate
deleted file mode 100644
index bd3346405d..0000000000
--- a/infra/bots/android_sdk.isolate
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- 'variables': {
- 'files': [
- '<(ANDROID_SDK_DIR)/',
- ],
- },
-}
diff --git a/infra/bots/android_sdk_hash b/infra/bots/android_sdk_hash
deleted file mode 100644
index c97d204e65..0000000000
--- a/infra/bots/android_sdk_hash
+++ /dev/null
@@ -1 +0,0 @@
-1665a0011fc1ee7bfdf35ad071d979ad8a608695 \ No newline at end of file
diff --git a/infra/bots/assets/android_sdk/VERSION b/infra/bots/assets/android_sdk/VERSION
new file mode 100644
index 0000000000..c227083464
--- /dev/null
+++ b/infra/bots/assets/android_sdk/VERSION
@@ -0,0 +1 @@
+0 \ No newline at end of file
diff --git a/infra/bots/assets/android_sdk/common.py b/infra/bots/assets/android_sdk/common.py
new file mode 100755
index 0000000000..4920c9b4fb
--- /dev/null
+++ b/infra/bots/assets/android_sdk/common.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Common vars used by scripts in this directory."""
+
+
+import os
+import sys
+
+FILE_DIR = os.path.dirname(os.path.abspath(__file__))
+INFRA_BOTS_DIR = os.path.realpath(os.path.join(FILE_DIR, os.pardir, os.pardir))
+
+sys.path.insert(0, INFRA_BOTS_DIR)
+from assets import assets
+
+ASSET_NAME = os.path.basename(FILE_DIR)
+
+
+def run(cmd):
+ """Run a command, eg. "upload" or "download". """
+ assets.main([cmd, ASSET_NAME] + sys.argv[1:])
diff --git a/infra/bots/assets/android_sdk/create.py b/infra/bots/assets/android_sdk/create.py
new file mode 100644
index 0000000000..256a41d9f4
--- /dev/null
+++ b/infra/bots/assets/android_sdk/create.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Create the asset."""
+
+
+import argparse
+import os
+import shutil
+
+
+def create_asset(target_dir, android_sdk_root):
+ """Create the asset."""
+ if not android_sdk_root:
+ android_sdk_root = (os.environ.get('ANDROID_HOME') or
+ os.environ.get('ANDROID_SDK_ROOT'))
+ if not android_sdk_root:
+ raise Exception('No --android_sdk_root provided and no ANDROID_HOME or '
+ 'ANDROID_SDK_ROOT environment variables.')
+
+ dst = os.path.join(target_dir, 'android-sdk')
+ shutil.copytree(android_sdk_root, dst)
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--android_sdk_root')
+ parser.add_argument('--target_dir', '-t', required=True)
+ args = parser.parse_args()
+ create_asset(args.target_dir, args.android_sdk_root)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/infra/bots/assets/android_sdk/create_and_upload.py b/infra/bots/assets/android_sdk/create_and_upload.py
new file mode 100755
index 0000000000..01b1b2c728
--- /dev/null
+++ b/infra/bots/assets/android_sdk/create_and_upload.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Create the asset and upload it."""
+
+
+import argparse
+import common
+import os
+import subprocess
+import sys
+import utils
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--android_sdk_root')
+ parser.add_argument('--gsutil')
+ args = parser.parse_args()
+
+ with utils.tmp_dir():
+ cwd = os.getcwd()
+ create_script = os.path.join(common.FILE_DIR, 'create.py')
+ upload_script = os.path.join(common.FILE_DIR, 'upload.py')
+
+ try:
+ cmd = ['python', create_script, '-t', cwd]
+ if args.android_sdk_root:
+ cmd.extend(['--android_sdk_root', args.android_sdk_root])
+ subprocess.check_call(cmd)
+
+ cmd = ['python', upload_script, '-t', cwd]
+ if args.gsutil:
+ cmd.extend(['--gsutil', args.gsutil])
+ subprocess.check_call(cmd)
+ except subprocess.CalledProcessError:
+ # Trap exceptions to avoid printing two stacktraces.
+ sys.exit(1)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/infra/bots/assets/android_sdk/download.py b/infra/bots/assets/android_sdk/download.py
new file mode 100755
index 0000000000..96cc87d43f
--- /dev/null
+++ b/infra/bots/assets/android_sdk/download.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Download the current version of the asset."""
+
+
+import common
+
+
+if __name__ == '__main__':
+ common.run('download')
diff --git a/infra/bots/assets/android_sdk/upload.py b/infra/bots/assets/android_sdk/upload.py
new file mode 100755
index 0000000000..ba7fc8b6a1
--- /dev/null
+++ b/infra/bots/assets/android_sdk/upload.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Upload a new version of the asset."""
+
+
+import common
+
+
+if __name__ == '__main__':
+ common.run('upload')
diff --git a/infra/bots/isolate_android_sdk.py b/infra/bots/isolate_android_sdk.py
deleted file mode 100644
index 1cb0accac4..0000000000
--- a/infra/bots/isolate_android_sdk.py
+++ /dev/null
@@ -1,129 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2016 Google Inc.
-#
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-
-"""Isolate a locally-managed Android SDK."""
-
-
-import argparse
-import os
-import shlex
-import shutil
-import subprocess
-import sys
-import utils
-
-
-INFRA_BOTS_DIR = os.path.realpath(os.path.dirname(os.path.abspath(__file__)))
-ISOLATE_FILE_NAME = 'android_sdk.isolate'
-REPO_SKIA = 'https://skia.googlesource.com/skia.git'
-SDK_DIR_NAME = 'android-sdk'
-
-
-def get_isolate_binary():
- """Find or, if necessary, obtain the isolate binary."""
- # Try to find isolate locally.
- platform = 'linux64'
- if sys.platform == 'win32':
- platform = 'win64'
- elif sys.platform == 'darwin':
- platform = 'mac64'
- repo_isolate = os.path.join(INFRA_BOTS_DIR,
- 'tools', 'luci-go', platform)
- path = os.pathsep.join((repo_isolate, os.environ['PATH']))
- try:
- output = subprocess.check_output(
- ['which', 'isolate'],
- env={'PATH':path}).rstrip()
- print 'Found isolate binary: %s' % output
- return output
- except subprocess.CalledProcessError:
- pass
-
- # Download isolate from GS.
- print 'Unable to find isolate binary; attempting to download...'
- try:
- subprocess.check_call(
- ['download_from_google_storage',
- '--bucket', 'chromium-luci',
- '-d', repo_isolate])
- except OSError as e:
- raise Exception('Failed to download isolate binary. '
- 'Is depot_tools in PATH? Error: %s' % e)
- except subprocess.CalledProcessError as e:
- raise Exception('Failed to download isolate binary. '
- 'Are you authenticated to Google Storage? Error: %s' % e)
-
- output = subprocess.check_output(
- ['which', 'isolate'],
- env={'PATH':path}).rstrip()
- return output
-
-
-def check_isolate_auth(isolate):
- """Ensure that we're authenticated to the isolate server."""
- not_logged_in = 'Not logged in'
- try:
- output = subprocess.check_output([isolate, 'whoami'])
-
- except subprocess.CalledProcessError:
- output = not_logged_in
- if output == not_logged_in:
- raise Exception('Not authenticated to isolate server. You probably need to '
- 'run:\n$ %s login' % isolate)
-
-
-def isolate_android_sdk(android_sdk_root):
- """Isolate the Android SDK and return the isolated hash."""
- repo_isolate_file = os.path.join(INFRA_BOTS_DIR, ISOLATE_FILE_NAME)
- with utils.tmp_dir():
- # Copy the SDK dir contents into a directory with a known name.
- sdk_dir = os.path.join(os.getcwd(), SDK_DIR_NAME)
- shutil.copytree(android_sdk_root, sdk_dir)
- isolate_file = os.path.join(os.getcwd(), ISOLATE_FILE_NAME)
- shutil.copyfile(repo_isolate_file, isolate_file)
-
- # Isolate the SDK.
- isolate = get_isolate_binary()
- check_isolate_auth(isolate)
- android_sdk_relpath = os.path.relpath(
- sdk_dir, os.path.dirname(isolate_file))
- isolate_cmd = [isolate, 'archive', '--quiet',
- '--isolate-server', 'https://isolateserver.appspot.com',
- '-i', isolate_file,
- '-s', 'android_sdk.isolated',
- '--extra-variable', 'ANDROID_SDK_DIR=%s' % android_sdk_relpath]
- isolate_out = subprocess.check_output(isolate_cmd).rstrip()
- return shlex.split(isolate_out)[0]
-
-
-def update_sdk_file(skia_path, isolated_hash):
- """Edit the android_sdk_hash file, upload a CL."""
- with utils.chdir(skia_path):
- with utils.git_branch():
- hash_file = os.path.join('infra', 'bots', 'android_sdk_hash')
- with open(hash_file, 'w') as f:
- f.write(isolated_hash)
- subprocess.check_call([utils.GIT, 'add', hash_file])
- subprocess.check_call([utils.GIT, 'commit', '-m', 'Update Android SDK'])
- subprocess.check_call([utils.GIT, 'cl', 'upload', '--bypass-hooks'])
-
-
-def main():
- parser = argparse.ArgumentParser()
- parser.add_argument('--android_sdk_root', required=True)
- args = parser.parse_args()
- skia_path = os.path.abspath(os.path.join(INFRA_BOTS_DIR,
- os.pardir, os.pardir))
-
- with utils.print_timings():
- isolated_hash = isolate_android_sdk(args.android_sdk_root)
- update_sdk_file(skia_path, isolated_hash)
-
-
-if __name__ == '__main__':
- main()