OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2016 The Dart project authors. All rights reserved. | 2 # Copyright 2016 The Dart project authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # This script downloads the latest dev SDK from | 6 # This script downloads the latest dev SDK from |
7 # http://gsdview.appspot.com/dart-archive/channels/dev/raw/latest/sdk/ | 7 # http://gsdview.appspot.com/dart-archive/channels/dev/raw/latest/sdk/ |
8 # into tools/sdks/$HOST_OS/. It is intended to be invoked from Jiri hooks in | 8 # into tools/sdks/$HOST_OS/. It is intended to be invoked from Jiri hooks in |
9 # a Fuchsia checkout. | 9 # a Fuchsia checkout. |
10 | 10 |
11 import os | 11 import os |
12 import sys | 12 import sys |
13 import zipfile | 13 import zipfile |
14 import urllib | 14 import urllib |
15 import utils | 15 import utils |
16 | 16 |
17 HOST_OS = utils.GuessOS() | 17 HOST_OS = utils.GuessOS() |
18 HOST_ARCH = utils.GuessArchitecture() | 18 HOST_ARCH = utils.GuessArchitecture() |
19 SCRIPT_DIR = os.path.dirname(sys.argv[0]) | 19 SCRIPT_DIR = os.path.dirname(sys.argv[0]) |
20 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..')) | 20 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..')) |
| 21 FUCHSIA_ROOT = os.path.realpath(os.path.join(DART_ROOT, '..')) |
| 22 FLUTTER_ROOT = os.path.join(FUCHSIA_ROOT, 'lib', 'flutter') |
21 | 23 |
22 DART_VERSION = '1.25.0-dev.7.0' | 24 DEFAULT_DART_VERSION = 'latest' |
23 BASE_URL = 'http://gsdview.appspot.com/dart-archive/channels/dev/raw/' + DART_VE
RSION +'/sdk' | 25 BASE_URL = 'http://gsdview.appspot.com/dart-archive/channels/dev/raw/%s/sdk/%s' |
24 | 26 |
25 def host_os_for_sdk(host_os): | 27 def host_os_for_sdk(host_os): |
26 if host_os.startswith('macos'): | 28 if host_os.startswith('macos'): |
27 return 'mac' | 29 return 'mac' |
28 if host_os.startswith('win'): | 30 if host_os.startswith('win'): |
29 return 'windows' | 31 return 'windows' |
30 return host_os | 32 return host_os |
31 | 33 |
32 # Python's zipfile doesn't preserve file permissions during extraction, so we | 34 # Python's zipfile doesn't preserve file permissions during extraction, so we |
33 # have to do it manually. | 35 # have to do it manually. |
34 def extract_file(zf, info, extract_dir): | 36 def extract_file(zf, info, extract_dir): |
35 zf.extract( info.filename, path=extract_dir ) | 37 zf.extract( info.filename, path=extract_dir ) |
36 out_path = os.path.join(extract_dir, info.filename) | 38 out_path = os.path.join(extract_dir, info.filename) |
37 perm = info.external_attr >> 16L | 39 perm = info.external_attr >> 16L |
38 os.chmod(out_path, perm) | 40 os.chmod(out_path, perm) |
39 | 41 |
40 def main(argv): | 42 def main(argv): |
41 host_os = host_os_for_sdk(HOST_OS) | 43 host_os = host_os_for_sdk(HOST_OS) |
42 zip_file = ('dartsdk-%s-x64-release.zip' % HOST_OS) | 44 zip_file = ('dartsdk-%s-x64-release.zip' % HOST_OS) |
43 sha_file = zip_file + '.sha256sum' | 45 sha_file = zip_file + '.sha256sum' |
44 sdk_path = os.path.join(DART_ROOT, 'tools', 'sdks', host_os) | 46 sdk_path = os.path.join(DART_ROOT, 'tools', 'sdks', host_os) |
45 local_sha_path = os.path.join(sdk_path, sha_file) | 47 local_sha_path = os.path.join(sdk_path, sha_file) |
46 remote_sha_path = os.path.join(sdk_path, sha_file + '.remote') | 48 remote_sha_path = os.path.join(sdk_path, sha_file + '.remote') |
47 zip_path = os.path.join(sdk_path, zip_file) | 49 zip_path = os.path.join(sdk_path, zip_file) |
48 sha_url = BASE_URL + '/' + sha_file | 50 |
49 zip_url = BASE_URL + '/' + zip_file | 51 # If we're in a Fuchsia checkout with Flutter nearby, pull the same dev SDK |
| 52 # version that Flutter says it wants. Otherwise, pull the latest dev SDK. |
| 53 sdk_version_path = os.path.join( |
| 54 FLUTTER_ROOT, 'bin', 'internal', 'dart-sdk.version') |
| 55 sdk_version = DEFAULT_DART_VERSION |
| 56 if os.path.isfile(sdk_version_path): |
| 57 with open(sdk_version_path, 'r') as fp: |
| 58 sdk_version = fp.read().strip() |
| 59 |
| 60 sha_url = (BASE_URL % (sdk_version, sha_file)) |
| 61 zip_url = (BASE_URL % (sdk_version, zip_file)) |
50 | 62 |
51 local_sha = '' | 63 local_sha = '' |
52 if os.path.isfile(local_sha_path): | 64 if os.path.isfile(local_sha_path): |
53 with open(local_sha_path, 'r') as fp: | 65 with open(local_sha_path, 'r') as fp: |
54 local_sha = fp.read() | 66 local_sha = fp.read() |
55 | 67 |
56 remote_sha = '' | 68 remote_sha = '' |
57 urllib.urlretrieve(sha_url, remote_sha_path) | 69 urllib.urlretrieve(sha_url, remote_sha_path) |
58 with open(remote_sha_path, 'r') as fp: | 70 with open(remote_sha_path, 'r') as fp: |
59 remote_sha = fp.read() | 71 remote_sha = fp.read() |
60 os.remove(remote_sha_path) | 72 os.remove(remote_sha_path) |
61 | 73 |
62 if local_sha == '' or local_sha != remote_sha: | 74 if local_sha == '' or local_sha != remote_sha: |
63 with open(local_sha_path, 'w') as fp: | 75 with open(local_sha_path, 'w') as fp: |
64 fp.write(remote_sha) | 76 fp.write(remote_sha) |
65 print 'Downloading prebuilt Dart SDK from: ' + zip_url | 77 print 'Downloading prebuilt Dart SDK from: ' + zip_url |
66 urllib.urlretrieve(zip_url, zip_path) | 78 urllib.urlretrieve(zip_url, zip_path) |
67 with zipfile.ZipFile(zip_path, 'r') as zf: | 79 with zipfile.ZipFile(zip_path, 'r') as zf: |
68 for info in zf.infolist(): | 80 for info in zf.infolist(): |
69 extract_file(zf, info, sdk_path) | 81 extract_file(zf, info, sdk_path) |
70 | 82 |
71 if __name__ == '__main__': | 83 if __name__ == '__main__': |
72 sys.exit(main(sys.argv)) | 84 sys.exit(main(sys.argv)) |
OLD | NEW |