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 | |
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', []) | |
45 if 'fuchsia' not in target_os: | |
46 # Nothing to do. | |
47 return 0 | |
Dirk Pranke
2017/05/11 22:31:30
Why use CR for this, rather than just loading .gcl
scottmg
2017/05/11 22:38:17
No good reason. I'll do that if the hooks_os thing
| |
48 | |
49 sdk_hash = sys.argv[1] | |
50 output_dir = os.path.join(REPOSITORY_ROOT, 'third_party', 'fuchsia-sdk') | |
51 bucket = 'gs://fuchsia-build/fuchsia/sdk/linux64/' | |
52 print 'Downloading SDK %s...' % sdk_hash | |
53 | |
54 if os.path.isdir(output_dir): | |
55 os.removedirs(output_dir) | |
56 | |
57 with tempfile.NamedTemporaryFile() as f: | |
58 cmd = [os.path.join(find_depot_tools.DEPOT_TOOLS_PATH, 'gsutil.py'), | |
59 'cp', bucket + sdk_hash, f.name] | |
60 print cmd | |
61 subprocess.check_call(cmd) | |
62 f.seek(0) | |
63 EnsureDirExists(output_dir) | |
64 tarfile.open(mode='r:gz', fileobj=f).extractall(path=output_dir) | |
65 | |
66 | |
67 if __name__ == '__main__': | |
68 sys.exit(main()) | |
OLD | NEW |