Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 repo_isolate = os.path.join(INFRA_BOTS_DIR, | |
| 31 'tools', 'luci-go', 'linux64') | |
|
rmistry
2016/05/27 14:38:04
What about the windows and mac isolates?
borenet
2016/05/27 14:50:07
Done, although I have no idea whether Android SDKs
| |
| 32 path = os.pathsep.join((repo_isolate, os.environ['PATH'])) | |
| 33 try: | |
| 34 output = subprocess.check_output( | |
| 35 ['which', 'isolate'], | |
| 36 env={'PATH':path}).rstrip() | |
| 37 print 'Found isolate binary: %s' % output | |
| 38 return output | |
| 39 except subprocess.CalledProcessError: | |
| 40 pass | |
| 41 | |
| 42 # Download isolate from GS. | |
| 43 print 'Unable to find isolate binary; attempting to download...' | |
| 44 try: | |
| 45 subprocess.check_call( | |
| 46 ['download_from_google_storage', | |
| 47 '--bucket', 'chromium-luci', | |
| 48 '-d', repo_isolate]) | |
| 49 except OSError as e: | |
| 50 raise Exception('Failed to download isolate binary. ' | |
| 51 'Is depot_tools in PATH? Error: %s' % e) | |
| 52 except subprocess.CalledProcessError as e: | |
| 53 raise Exception('Failed to download isolate binary. ' | |
| 54 'Are you authenticated to Google Storage? Error: %s' % e) | |
| 55 | |
| 56 output = subprocess.check_output( | |
| 57 ['which', 'isolate'], | |
| 58 env={'PATH':path}).rstrip() | |
| 59 return output | |
| 60 | |
| 61 | |
| 26 def isolate_android_sdk(android_sdk_root): | 62 def isolate_android_sdk(android_sdk_root): |
| 27 """Isolate the Android SDK and return the isolated hash.""" | 63 """Isolate the Android SDK and return the isolated hash.""" |
| 28 repo_isolate_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), | 64 repo_isolate_file = os.path.join(INFRA_BOTS_DIR, ISOLATE_FILE_NAME) |
| 29 ISOLATE_FILE_NAME) | |
| 30 with utils.tmp_dir(): | 65 with utils.tmp_dir(): |
| 31 # Copy the SDK dir contents into a directory with a known name. | 66 # Copy the SDK dir contents into a directory with a known name. |
| 32 sdk_dir = os.path.join(os.getcwd(), SDK_DIR_NAME) | 67 sdk_dir = os.path.join(os.getcwd(), SDK_DIR_NAME) |
| 33 shutil.copytree(android_sdk_root, sdk_dir) | 68 shutil.copytree(android_sdk_root, sdk_dir) |
| 34 isolate_file = os.path.join(os.getcwd(), ISOLATE_FILE_NAME) | 69 isolate_file = os.path.join(os.getcwd(), ISOLATE_FILE_NAME) |
| 35 shutil.copyfile(repo_isolate_file, isolate_file) | 70 shutil.copyfile(repo_isolate_file, isolate_file) |
| 36 | 71 |
| 37 # Isolate the SDK. | 72 # Isolate the SDK. |
| 38 isolate = 'isolate' # TODO(borenet): Don't assume this is in PATH. | 73 isolate = get_isolate_binary() |
| 39 android_sdk_relpath = os.path.relpath( | 74 android_sdk_relpath = os.path.relpath( |
| 40 sdk_dir, os.path.dirname(isolate_file)) | 75 sdk_dir, os.path.dirname(isolate_file)) |
| 41 isolate_cmd = [isolate, 'archive', '--quiet', | 76 isolate_cmd = [isolate, 'archive', '--quiet', |
| 42 '--isolate-server', 'https://isolateserver.appspot.com', | 77 '--isolate-server', 'https://isolateserver.appspot.com', |
| 43 '-i', isolate_file, | 78 '-i', isolate_file, |
| 44 '-s', 'android_sdk.isolated', | 79 '-s', 'android_sdk.isolated', |
| 45 '--extra-variable', 'ANDROID_SDK_DIR=%s' % android_sdk_relpath] | 80 '--extra-variable', 'ANDROID_SDK_DIR=%s' % android_sdk_relpath] |
| 46 isolate_out = subprocess.check_output(isolate_cmd).rstrip() | 81 isolate_out = subprocess.check_output(isolate_cmd).rstrip() |
| 47 return shlex.split(isolate_out)[0] | 82 return shlex.split(isolate_out)[0] |
| 48 | 83 |
| 49 | 84 |
| 50 | |
| 51 def update_sdk_file(skia_path, isolated_hash): | 85 def update_sdk_file(skia_path, isolated_hash): |
| 52 """Edit the android_sdk_hash file, upload a CL.""" | 86 """Edit the android_sdk_hash file, upload a CL.""" |
| 53 with utils.chdir(skia_path): | 87 with utils.chdir(skia_path): |
| 54 with utils.git_branch(): | 88 with utils.git_branch(): |
| 55 hash_file = os.path.join('infra', 'bots', 'android_sdk_hash') | 89 hash_file = os.path.join('infra', 'bots', 'android_sdk_hash') |
| 56 with open(hash_file, 'w') as f: | 90 with open(hash_file, 'w') as f: |
| 57 f.write(isolated_hash) | 91 f.write(isolated_hash) |
| 58 subprocess.check_call([utils.GIT, 'add', hash_file]) | 92 subprocess.check_call([utils.GIT, 'add', hash_file]) |
| 59 subprocess.check_call([utils.GIT, 'commit', '-m', 'Update Android SDK']) | 93 subprocess.check_call([utils.GIT, 'commit', '-m', 'Update Android SDK']) |
| 60 subprocess.check_call([utils.GIT, 'cl', 'upload', '--bypass-hooks']) | 94 subprocess.check_call([utils.GIT, 'cl', 'upload', '--bypass-hooks']) |
| 61 | 95 |
| 62 | 96 |
| 63 def main(): | 97 def main(): |
| 64 parser = argparse.ArgumentParser() | 98 parser = argparse.ArgumentParser() |
| 65 parser.add_argument('--android_sdk_root', required=True) | 99 parser.add_argument('--android_sdk_root', required=True) |
| 66 args = parser.parse_args() | 100 args = parser.parse_args() |
| 67 skia_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), | 101 skia_path = os.path.abspath(os.path.join(INFRA_BOTS_DIR, |
| 68 os.pardir, os.pardir) | 102 os.pardir, os.pardir)) |
| 69 | 103 |
| 70 with utils.print_timings(): | 104 with utils.print_timings(): |
| 71 isolated_hash = isolate_android_sdk(args.android_sdk_root) | 105 isolated_hash = isolate_android_sdk(args.android_sdk_root) |
| 72 update_sdk_file(skia_path, isolated_hash) | 106 update_sdk_file(skia_path, isolated_hash) |
| 73 | 107 |
| 74 | 108 |
| 75 if __name__ == '__main__': | 109 if __name__ == '__main__': |
| 76 main() | 110 main() |
| OLD | NEW |