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 |
(...skipping 16 matching lines...) Expand all Loading... |
27 def host_os_for_sdk(host_os): | 27 def host_os_for_sdk(host_os): |
28 if host_os.startswith('macos'): | 28 if host_os.startswith('macos'): |
29 return 'mac' | 29 return 'mac' |
30 if host_os.startswith('win'): | 30 if host_os.startswith('win'): |
31 return 'windows' | 31 return 'windows' |
32 return host_os | 32 return host_os |
33 | 33 |
34 # 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 |
35 # have to do it manually. | 35 # have to do it manually. |
36 def extract_file(zf, info, extract_dir): | 36 def extract_file(zf, info, extract_dir): |
37 zf.extract( info.filename, path=extract_dir ) | 37 try: |
38 out_path = os.path.join(extract_dir, info.filename) | 38 zf.extract(info.filename, path=extract_dir) |
39 perm = info.external_attr >> 16L | 39 out_path = os.path.join(extract_dir, info.filename) |
40 os.chmod(out_path, perm) | 40 perm = info.external_attr >> 16L |
| 41 os.chmod(out_path, perm) |
| 42 except IOError as err: |
| 43 if 'dart-sdk/bin/dart' in err.filename: |
| 44 print('Failed to extract the new Dart SDK dart binary. ' + |
| 45 'Kill stale instances (like the analyzer) and try the update again') |
| 46 return False |
| 47 raise |
| 48 return True |
41 | 49 |
42 def main(argv): | 50 def main(argv): |
43 host_os = host_os_for_sdk(HOST_OS) | 51 host_os = host_os_for_sdk(HOST_OS) |
44 zip_file = ('dartsdk-%s-x64-release.zip' % HOST_OS) | 52 zip_file = ('dartsdk-%s-x64-release.zip' % HOST_OS) |
45 sha_file = zip_file + '.sha256sum' | 53 sha_file = zip_file + '.sha256sum' |
46 sdk_path = os.path.join(DART_ROOT, 'tools', 'sdks', host_os) | 54 sdk_path = os.path.join(DART_ROOT, 'tools', 'sdks', host_os) |
47 local_sha_path = os.path.join(sdk_path, sha_file) | 55 local_sha_path = os.path.join(sdk_path, sha_file) |
48 remote_sha_path = os.path.join(sdk_path, sha_file + '.remote') | 56 remote_sha_path = os.path.join(sdk_path, sha_file + '.remote') |
49 zip_path = os.path.join(sdk_path, zip_file) | 57 zip_path = os.path.join(sdk_path, zip_file) |
50 | 58 |
(...skipping 18 matching lines...) Expand all Loading... |
69 urllib.urlretrieve(sha_url, remote_sha_path) | 77 urllib.urlretrieve(sha_url, remote_sha_path) |
70 with open(remote_sha_path, 'r') as fp: | 78 with open(remote_sha_path, 'r') as fp: |
71 remote_sha = fp.read() | 79 remote_sha = fp.read() |
72 os.remove(remote_sha_path) | 80 os.remove(remote_sha_path) |
73 | 81 |
74 if local_sha == '' or local_sha != remote_sha: | 82 if local_sha == '' or local_sha != remote_sha: |
75 print 'Downloading prebuilt Dart SDK from: ' + zip_url | 83 print 'Downloading prebuilt Dart SDK from: ' + zip_url |
76 urllib.urlretrieve(zip_url, zip_path) | 84 urllib.urlretrieve(zip_url, zip_path) |
77 with zipfile.ZipFile(zip_path, 'r') as zf: | 85 with zipfile.ZipFile(zip_path, 'r') as zf: |
78 for info in zf.infolist(): | 86 for info in zf.infolist(): |
79 extract_file(zf, info, sdk_path) | 87 if not extract_file(zf, info, sdk_path): |
| 88 return -1 |
80 with open(local_sha_path, 'w') as fp: | 89 with open(local_sha_path, 'w') as fp: |
81 fp.write(remote_sha) | 90 fp.write(remote_sha) |
| 91 return 0 |
82 | 92 |
83 if __name__ == '__main__': | 93 if __name__ == '__main__': |
84 sys.exit(main(sys.argv)) | 94 sys.exit(main(sys.argv)) |
OLD | NEW |