OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 # Copyright 2015 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 """Pulls down the current dart sdk to third_party/dart-sdk/. |
| 7 |
| 8 You can manually force this to run again by removing |
| 9 third_party/dart-sdk/STAMP_FILE, which contains the URL of the SDK that |
| 10 was downloaded. Rolling works by updating LINUX_64_SDK to a new URL. |
| 11 """ |
| 12 |
| 13 import os |
| 14 import shutil |
| 15 import subprocess |
| 16 import sys |
| 17 |
| 18 # How to roll the dart sdk: Just change this url! We write this to the stamp |
| 19 # file after we download, and then check the stamp file for differences. |
| 20 SDK_URL_BASE = ('https://gsdview.appspot.com/dart-archive/channels/dev/raw/' |
| 21 '1.15.0-dev.4.0/sdk/') |
| 22 |
| 23 LINUX_64_SDK = 'dartsdk-linux-x64-release.zip' |
| 24 MACOS_64_SDK = 'dartsdk-macos-x64-release.zip' |
| 25 |
| 26 # Path constants. (All of these should be absolute paths.) |
| 27 THIS_DIR = os.path.abspath(os.path.dirname(__file__)) |
| 28 MOJO_DIR = os.path.abspath(os.path.join(THIS_DIR, '..', '..')) |
| 29 DART_SDK_DIR = os.path.join(MOJO_DIR, 'third_party', 'dart-sdk') |
| 30 STAMP_FILE = os.path.join(DART_SDK_DIR, 'STAMP_FILE') |
| 31 |
| 32 def RunCommand(command, fail_hard=True): |
| 33 """Run command and return success (True) or failure; or if fail_hard is |
| 34 True, exit on failure.""" |
| 35 |
| 36 print 'Running %s' % (str(command)) |
| 37 if subprocess.call(command, shell=False) == 0: |
| 38 return True |
| 39 print 'Failed.' |
| 40 if fail_hard: |
| 41 sys.exit(1) |
| 42 return False |
| 43 |
| 44 def main(): |
| 45 # Only get the SDK if we don't have a stamp for or have an out of date stamp |
| 46 # file. |
| 47 get_sdk = False |
| 48 if sys.platform.startswith('linux'): |
| 49 sdk_url = SDK_URL_BASE + LINUX_64_SDK |
| 50 output_file = os.path.join(DART_SDK_DIR, LINUX_64_SDK) |
| 51 elif sys.platform.startswith('darwin'): |
| 52 sdk_url = SDK_URL_BASE + MACOS_64_SDK |
| 53 output_file = os.path.join(DART_SDK_DIR, MACOS_64_SDK) |
| 54 else: |
| 55 print "Platform not supported" |
| 56 return 1 |
| 57 |
| 58 if not os.path.exists(STAMP_FILE): |
| 59 get_sdk = True |
| 60 else: |
| 61 # Get the contents of the stamp file. |
| 62 with open(STAMP_FILE, "r") as stamp_file: |
| 63 stamp_url = stamp_file.read().replace('\n', '') |
| 64 if stamp_url != sdk_url: |
| 65 get_sdk = True |
| 66 |
| 67 if get_sdk: |
| 68 # Completely remove all traces of the previous SDK. |
| 69 if os.path.exists(DART_SDK_DIR): |
| 70 shutil.rmtree(DART_SDK_DIR) |
| 71 os.mkdir(DART_SDK_DIR) |
| 72 |
| 73 # Download the Linux x64 based Dart SDK. |
| 74 # '-C -': Resume transfer if possible. |
| 75 # '--location': Follow Location: redirects. |
| 76 # '-o': Output file. |
| 77 curl_command = ['curl', |
| 78 '-C', '-', |
| 79 '--location', |
| 80 '-o', output_file, |
| 81 sdk_url] |
| 82 if not RunCommand(curl_command, fail_hard=False): |
| 83 print "Failed to get dart sdk from server." |
| 84 return 1 |
| 85 |
| 86 # Write our stamp file so we don't redownload the sdk. |
| 87 with open(STAMP_FILE, "w") as stamp_file: |
| 88 stamp_file.write(sdk_url) |
| 89 |
| 90 unzip_command = ['unzip', '-o', '-q', output_file, '-d', DART_SDK_DIR] |
| 91 if not RunCommand(unzip_command, fail_hard=False): |
| 92 print "Failed to unzip the dart sdk." |
| 93 return 1 |
| 94 |
| 95 return 0 |
| 96 |
| 97 if __name__ == '__main__': |
| 98 sys.exit(main()) |
OLD | NEW |