Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2017 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Updates the Fuchsia SDK to the given revision. Checks .gclient target_os | |
| 7 so that it doesn't download unnecessarily.""" | |
| 8 | |
| 9 import os | |
| 10 import subprocess | |
| 11 import sys | |
| 12 import tarfile | |
| 13 import tempfile | |
| 14 | |
| 15 REPOSITORY_ROOT = os.path.abspath(os.path.join( | |
| 16 os.path.dirname(__file__), '..', '..')) | |
| 17 sys.path.append(os.path.join(REPOSITORY_ROOT, 'build')) | |
| 18 sys.path.append(os.path.join(REPOSITORY_ROOT, 'tools', 'cr')) | |
| 19 | |
| 20 import cr.base | |
|
Nico
2017/05/11 22:31:19
Since you're suing cr.auto and cr.loader below, sh
scottmg
2017/05/11 22:38:17
I'd actually never heard of it before 20mins ago,
| |
| 21 import find_depot_tools | |
| 22 | |
| 23 | |
| 24 def EnsureDirExists(path): | |
| 25 if not os.path.exists(path): | |
| 26 print 'Creating directory %s' % path | |
| 27 os.makedirs(path) | |
| 28 | |
| 29 | |
| 30 def main(): | |
| 31 if len(sys.argv) != 2: | |
| 32 print >>sys.stderr, 'usage: %s <sdk_hash>' % sys.argv[0] | |
| 33 return 1 | |
| 34 | |
| 35 # Check whether we're targeting Fuchsia. | |
| 36 user_path = os.path.expanduser(os.path.join('~', '.config', 'cr')) | |
| 37 cr.auto.user.__path__.append(user_path) | |
| 38 cr.loader.Scan() | |
| 39 with cr.base.context.Create( | |
| 40 description='Fuchsia SDK update tool', | |
| 41 epilog='') as context: | |
| 42 | |
| 43 cr.base.client.DetectClient() | |
| 44 target_os = cr.context.gclient.get('target_os', []) | |
|
Nico
2017/05/11 22:31:19
How hard is it to add hooks_os to gclient directly
scottmg
2017/05/11 22:38:17
I admit I just got a little avoid-y when I landed
| |
| 45 if 'fuchsia' not in target_os: | |
| 46 # Nothing to do. | |
| 47 return 0 | |
| 48 | |
| 49 sdk_hash = sys.argv[1] | |
| 50 output_dir = os.path.join(REPOSITORY_ROOT, 'third_party', 'fuchsia-sdk') | |
| 51 | |
| 52 hash_filename = os.path.join(output_dir, '.hash') | |
| 53 if os.path.exists(hash_filename): | |
| 54 with open(hash_filename, 'r') as f: | |
| 55 if f.read().strip() == sdk_hash: | |
| 56 # Nothing to do. | |
| 57 return 0 | |
| 58 | |
| 59 print 'Downloading SDK %s...' % sdk_hash | |
| 60 | |
| 61 if os.path.isdir(output_dir): | |
| 62 os.removedirs(output_dir) | |
| 63 | |
| 64 bucket = 'gs://fuchsia-build/fuchsia/sdk/linux64/' | |
| 65 with tempfile.NamedTemporaryFile() as f: | |
| 66 cmd = [os.path.join(find_depot_tools.DEPOT_TOOLS_PATH, 'gsutil.py'), | |
| 67 'cp', bucket + sdk_hash, f.name] | |
| 68 print cmd | |
| 69 subprocess.check_call(cmd) | |
| 70 f.seek(0) | |
| 71 EnsureDirExists(output_dir) | |
| 72 tarfile.open(mode='r:gz', fileobj=f).extractall(path=output_dir) | |
| 73 | |
| 74 with open(hash_filename, 'w') as f: | |
| 75 f.write(sdk_hash) | |
| 76 | |
| 77 | |
| 78 if __name__ == '__main__': | |
| 79 sys.exit(main()) | |
| OLD | NEW |