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

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

Issue 2016353003: isolate_android_sdk: Find or download isolate binary, fix infra path (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add check_isolate_auth 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 | « .gitignore ('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
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2016 Google Inc. 3 # Copyright 2016 Google Inc.
4 # 4 #
5 # Use of this source code is governed by a BSD-style license that can be 5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file. 6 # found in the LICENSE file.
7 7
8 8
9 """Isolate a locally-managed Android SDK.""" 9 """Isolate a locally-managed Android SDK."""
10 10
11 11
12 import argparse 12 import argparse
13 import os 13 import os
14 import shlex 14 import shlex
15 import shutil 15 import shutil
16 import subprocess 16 import subprocess
17 import sys 17 import sys
18 import utils 18 import utils
19 19
20 20
21 INFRA_BOTS_DIR = os.path.realpath(os.path.dirname(os.path.abspath(__file__)))
21 ISOLATE_FILE_NAME = 'android_sdk.isolate' 22 ISOLATE_FILE_NAME = 'android_sdk.isolate'
22 REPO_SKIA = 'https://skia.googlesource.com/skia.git' 23 REPO_SKIA = 'https://skia.googlesource.com/skia.git'
23 SDK_DIR_NAME = 'android-sdk' 24 SDK_DIR_NAME = 'android-sdk'
24 25
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
26 def isolate_android_sdk(android_sdk_root): 80 def isolate_android_sdk(android_sdk_root):
27 """Isolate the Android SDK and return the isolated hash.""" 81 """Isolate the Android SDK and return the isolated hash."""
28 repo_isolate_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 82 repo_isolate_file = os.path.join(INFRA_BOTS_DIR, ISOLATE_FILE_NAME)
29 ISOLATE_FILE_NAME)
30 with utils.tmp_dir(): 83 with utils.tmp_dir():
31 # Copy the SDK dir contents into a directory with a known name. 84 # Copy the SDK dir contents into a directory with a known name.
32 sdk_dir = os.path.join(os.getcwd(), SDK_DIR_NAME) 85 sdk_dir = os.path.join(os.getcwd(), SDK_DIR_NAME)
33 shutil.copytree(android_sdk_root, sdk_dir) 86 shutil.copytree(android_sdk_root, sdk_dir)
34 isolate_file = os.path.join(os.getcwd(), ISOLATE_FILE_NAME) 87 isolate_file = os.path.join(os.getcwd(), ISOLATE_FILE_NAME)
35 shutil.copyfile(repo_isolate_file, isolate_file) 88 shutil.copyfile(repo_isolate_file, isolate_file)
36 89
37 # Isolate the SDK. 90 # Isolate the SDK.
38 isolate = 'isolate' # TODO(borenet): Don't assume this is in PATH. 91 isolate = get_isolate_binary()
92 check_isolate_auth(isolate)
39 android_sdk_relpath = os.path.relpath( 93 android_sdk_relpath = os.path.relpath(
40 sdk_dir, os.path.dirname(isolate_file)) 94 sdk_dir, os.path.dirname(isolate_file))
41 isolate_cmd = [isolate, 'archive', '--quiet', 95 isolate_cmd = [isolate, 'archive', '--quiet',
42 '--isolate-server', 'https://isolateserver.appspot.com', 96 '--isolate-server', 'https://isolateserver.appspot.com',
43 '-i', isolate_file, 97 '-i', isolate_file,
44 '-s', 'android_sdk.isolated', 98 '-s', 'android_sdk.isolated',
45 '--extra-variable', 'ANDROID_SDK_DIR=%s' % android_sdk_relpath] 99 '--extra-variable', 'ANDROID_SDK_DIR=%s' % android_sdk_relpath]
46 isolate_out = subprocess.check_output(isolate_cmd).rstrip() 100 isolate_out = subprocess.check_output(isolate_cmd).rstrip()
47 return shlex.split(isolate_out)[0] 101 return shlex.split(isolate_out)[0]
48 102
49 103
50
51 def update_sdk_file(skia_path, isolated_hash): 104 def update_sdk_file(skia_path, isolated_hash):
52 """Edit the android_sdk_hash file, upload a CL.""" 105 """Edit the android_sdk_hash file, upload a CL."""
53 with utils.chdir(skia_path): 106 with utils.chdir(skia_path):
54 with utils.git_branch(): 107 with utils.git_branch():
55 hash_file = os.path.join('infra', 'bots', 'android_sdk_hash') 108 hash_file = os.path.join('infra', 'bots', 'android_sdk_hash')
56 with open(hash_file, 'w') as f: 109 with open(hash_file, 'w') as f:
57 f.write(isolated_hash) 110 f.write(isolated_hash)
58 subprocess.check_call([utils.GIT, 'add', hash_file]) 111 subprocess.check_call([utils.GIT, 'add', hash_file])
59 subprocess.check_call([utils.GIT, 'commit', '-m', 'Update Android SDK']) 112 subprocess.check_call([utils.GIT, 'commit', '-m', 'Update Android SDK'])
60 subprocess.check_call([utils.GIT, 'cl', 'upload', '--bypass-hooks']) 113 subprocess.check_call([utils.GIT, 'cl', 'upload', '--bypass-hooks'])
61 114
62 115
63 def main(): 116 def main():
64 parser = argparse.ArgumentParser() 117 parser = argparse.ArgumentParser()
65 parser.add_argument('--android_sdk_root', required=True) 118 parser.add_argument('--android_sdk_root', required=True)
66 args = parser.parse_args() 119 args = parser.parse_args()
67 skia_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 120 skia_path = os.path.abspath(os.path.join(INFRA_BOTS_DIR,
68 os.pardir, os.pardir) 121 os.pardir, os.pardir))
69 122
70 with utils.print_timings(): 123 with utils.print_timings():
71 isolated_hash = isolate_android_sdk(args.android_sdk_root) 124 isolated_hash = isolate_android_sdk(args.android_sdk_root)
72 update_sdk_file(skia_path, isolated_hash) 125 update_sdk_file(skia_path, isolated_hash)
73 126
74 127
75 if __name__ == '__main__': 128 if __name__ == '__main__':
76 main() 129 main()
OLDNEW
« no previous file with comments | « .gitignore ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698