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

Side by Side Diff: infra/bots/isolate_android_sdk.py

Issue 2086003002: Add Android SDK asset (Closed) Base URL: https://skia.googlesource.com/skia.git@cipd
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « infra/bots/assets/android_sdk/upload.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright 2016 Google Inc.
4 #
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
7
8
9 """Isolate a locally-managed Android SDK."""
10
11
12 import argparse
13 import os
14 import shlex
15 import shutil
16 import subprocess
17 import sys
18 import utils
19
20
21 INFRA_BOTS_DIR = os.path.realpath(os.path.dirname(os.path.abspath(__file__)))
22 ISOLATE_FILE_NAME = 'android_sdk.isolate'
23 REPO_SKIA = 'https://skia.googlesource.com/skia.git'
24 SDK_DIR_NAME = 'android-sdk'
25
26
27 def get_isolate_binary():
28 """Find or, if necessary, obtain the isolate binary."""
29 # Try to find isolate locally.
30 platform = 'linux64'
31 if sys.platform == 'win32':
32 platform = 'win64'
33 elif sys.platform == 'darwin':
34 platform = 'mac64'
35 repo_isolate = os.path.join(INFRA_BOTS_DIR,
36 'tools', 'luci-go', platform)
37 path = os.pathsep.join((repo_isolate, os.environ['PATH']))
38 try:
39 output = subprocess.check_output(
40 ['which', 'isolate'],
41 env={'PATH':path}).rstrip()
42 print 'Found isolate binary: %s' % output
43 return output
44 except subprocess.CalledProcessError:
45 pass
46
47 # Download isolate from GS.
48 print 'Unable to find isolate binary; attempting to download...'
49 try:
50 subprocess.check_call(
51 ['download_from_google_storage',
52 '--bucket', 'chromium-luci',
53 '-d', repo_isolate])
54 except OSError as e:
55 raise Exception('Failed to download isolate binary. '
56 'Is depot_tools in PATH? Error: %s' % e)
57 except subprocess.CalledProcessError as e:
58 raise Exception('Failed to download isolate binary. '
59 'Are you authenticated to Google Storage? Error: %s' % e)
60
61 output = subprocess.check_output(
62 ['which', 'isolate'],
63 env={'PATH':path}).rstrip()
64 return output
65
66
67 def check_isolate_auth(isolate):
68 """Ensure that we're authenticated to the isolate server."""
69 not_logged_in = 'Not logged in'
70 try:
71 output = subprocess.check_output([isolate, 'whoami'])
72
73 except subprocess.CalledProcessError:
74 output = not_logged_in
75 if output == not_logged_in:
76 raise Exception('Not authenticated to isolate server. You probably need to '
77 'run:\n$ %s login' % isolate)
78
79
80 def isolate_android_sdk(android_sdk_root):
81 """Isolate the Android SDK and return the isolated hash."""
82 repo_isolate_file = os.path.join(INFRA_BOTS_DIR, ISOLATE_FILE_NAME)
83 with utils.tmp_dir():
84 # Copy the SDK dir contents into a directory with a known name.
85 sdk_dir = os.path.join(os.getcwd(), SDK_DIR_NAME)
86 shutil.copytree(android_sdk_root, sdk_dir)
87 isolate_file = os.path.join(os.getcwd(), ISOLATE_FILE_NAME)
88 shutil.copyfile(repo_isolate_file, isolate_file)
89
90 # Isolate the SDK.
91 isolate = get_isolate_binary()
92 check_isolate_auth(isolate)
93 android_sdk_relpath = os.path.relpath(
94 sdk_dir, os.path.dirname(isolate_file))
95 isolate_cmd = [isolate, 'archive', '--quiet',
96 '--isolate-server', 'https://isolateserver.appspot.com',
97 '-i', isolate_file,
98 '-s', 'android_sdk.isolated',
99 '--extra-variable', 'ANDROID_SDK_DIR=%s' % android_sdk_relpath]
100 isolate_out = subprocess.check_output(isolate_cmd).rstrip()
101 return shlex.split(isolate_out)[0]
102
103
104 def update_sdk_file(skia_path, isolated_hash):
105 """Edit the android_sdk_hash file, upload a CL."""
106 with utils.chdir(skia_path):
107 with utils.git_branch():
108 hash_file = os.path.join('infra', 'bots', 'android_sdk_hash')
109 with open(hash_file, 'w') as f:
110 f.write(isolated_hash)
111 subprocess.check_call([utils.GIT, 'add', hash_file])
112 subprocess.check_call([utils.GIT, 'commit', '-m', 'Update Android SDK'])
113 subprocess.check_call([utils.GIT, 'cl', 'upload', '--bypass-hooks'])
114
115
116 def main():
117 parser = argparse.ArgumentParser()
118 parser.add_argument('--android_sdk_root', required=True)
119 args = parser.parse_args()
120 skia_path = os.path.abspath(os.path.join(INFRA_BOTS_DIR,
121 os.pardir, os.pardir))
122
123 with utils.print_timings():
124 isolated_hash = isolate_android_sdk(args.android_sdk_root)
125 update_sdk_file(skia_path, isolated_hash)
126
127
128 if __name__ == '__main__':
129 main()
OLDNEW
« no previous file with comments | « infra/bots/assets/android_sdk/upload.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698