| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2017 The Dart project authors. All rights reserved. | 2 # Copyright 2017 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 """Pulls down tools required to build Dart.""" | 6 """Pulls down tools required to build Dart.""" |
| 7 | 7 |
| 8 import os | 8 import os |
| 9 import subprocess | 9 import subprocess |
| 10 import shutil | 10 import shutil |
| 11 import sys | 11 import sys |
| 12 | 12 |
| 13 THIS_DIR = os.path.abspath(os.path.dirname(__file__)) | 13 THIS_DIR = os.path.abspath(os.path.dirname(__file__)) |
| 14 DART_ROOT = os.path.abspath(os.path.join(THIS_DIR, '..', '..')) | 14 DART_ROOT = os.path.abspath(os.path.join(THIS_DIR, '..', '..')) |
| 15 BUILDTOOLS = os.path.join(DART_ROOT, 'buildtools') | 15 BUILDTOOLS = os.path.join(DART_ROOT, 'buildtools') |
| 16 TOOLS_BUILDTOOLS = os.path.join(DART_ROOT, 'tools', 'buildtools') | 16 TOOLS_BUILDTOOLS = os.path.join(DART_ROOT, 'tools', 'buildtools') |
| 17 TOOLCHAIN = os.path.join(BUILDTOOLS, 'toolchain') |
| 17 | 18 |
| 18 sys.path.insert(0, os.path.join(DART_ROOT, 'tools')) | 19 sys.path.insert(0, os.path.join(DART_ROOT, 'tools')) |
| 19 import find_depot_tools | 20 import find_depot_tools |
| 20 | 21 |
| 21 DEPOT_PATH = find_depot_tools.add_depot_tools_to_path() | 22 DEPOT_PATH = find_depot_tools.add_depot_tools_to_path() |
| 22 | 23 |
| 23 | 24 |
| 24 def Update(): | 25 def Update(): |
| 25 path = os.path.join(BUILDTOOLS, 'update.sh') | 26 path = os.path.join(BUILDTOOLS, 'update.sh') |
| 26 return subprocess.call(['/bin/bash', path, '--toolchain', '--gn'], cwd=DART_RO
OT) | 27 command = ['/bin/bash', path, '--toolchain', '--gn'] |
| 28 return subprocess.call(command, cwd=DART_ROOT) |
| 27 | 29 |
| 28 | 30 |
| 29 def UpdateGNOnWindows(): | 31 def UpdateGNOnWindows(): |
| 30 sha1_file = os.path.join(BUILDTOOLS, 'win', 'gn.exe.sha1') | 32 sha1_file = os.path.join(BUILDTOOLS, 'win', 'gn.exe.sha1') |
| 31 downloader_script = os.path.join(DEPOT_PATH, 'download_from_google_storage.py'
) | 33 downloader_script = os.path.join( |
| 34 DEPOT_PATH, 'download_from_google_storage.py') |
| 32 download_cmd = [ | 35 download_cmd = [ |
| 33 'python', | 36 'python', |
| 34 downloader_script, | 37 downloader_script, |
| 35 '--no_auth', | 38 '--no_auth', |
| 36 '--no_resume', | 39 '--no_resume', |
| 37 '--quiet', | 40 '--quiet', |
| 38 '--platform=win*', | 41 '--platform=win*', |
| 39 '--bucket', | 42 '--bucket', |
| 40 'chromium-gn', | 43 'chromium-gn', |
| 41 '-s', | 44 '-s', |
| 42 sha1_file | 45 sha1_file |
| 43 ] | 46 ] |
| 44 return subprocess.call(download_cmd) | 47 return subprocess.call(download_cmd) |
| 45 | 48 |
| 46 | 49 |
| 47 def UpdateClangFormatOnWindows(): | 50 def UpdateClangFormatOnWindows(): |
| 48 sha1_file = os.path.join(TOOLS_BUILDTOOLS, 'win', 'clang-format.exe.sha1') | 51 sha1_file = os.path.join(TOOLS_BUILDTOOLS, 'win', 'clang-format.exe.sha1') |
| 49 output_dir = os.path.join(BUILDTOOLS, 'win', 'clang-format.exe') | 52 output_dir = os.path.join(BUILDTOOLS, 'win', 'clang-format.exe') |
| 50 downloader_script = os.path.join(DEPOT_PATH, 'download_from_google_storage.py'
) | 53 downloader_script = os.path.join( |
| 54 DEPOT_PATH, 'download_from_google_storage.py') |
| 51 download_cmd = [ | 55 download_cmd = [ |
| 52 'python', | 56 'python', |
| 53 downloader_script, | 57 downloader_script, |
| 54 '--no_auth', | 58 '--no_auth', |
| 55 '--no_resume', | 59 '--no_resume', |
| 56 '--quiet', | 60 '--quiet', |
| 57 '--platform=win', | 61 '--platform=win', |
| 58 '--bucket', | 62 '--bucket', |
| 59 'chromium-clang-format', | 63 'chromium-clang-format', |
| 60 '-s', | 64 '-s', |
| 61 sha1_file, | 65 sha1_file, |
| 62 '-o', | 66 '-o', |
| 63 output_dir | 67 output_dir |
| 64 ] | 68 ] |
| 65 return subprocess.call(download_cmd) | 69 return subprocess.call(download_cmd) |
| 66 | 70 |
| 67 | 71 |
| 68 def CopyClangFormatScripts(): | 72 # On Mac and Linux we copy clang-format to the place where git cl format |
| 69 linux_script = os.path.join(TOOLS_BUILDTOOLS, 'linux64', 'clang-format') | 73 # expects it to be. |
| 70 mac_script = os.path.join(TOOLS_BUILDTOOLS, 'mac', 'clang-format') | 74 def CopyClangFormat(): |
| 71 linux_dest = os.path.join(BUILDTOOLS, 'linux64', 'clang-format') | 75 if sys.platform == 'darwin': |
| 72 mac_dest = os.path.join(BUILDTOOLS, 'mac', 'clang-format') | 76 platform = 'darwin' |
| 73 shutil.copy2(linux_script, linux_dest) | 77 subdir = 'mac' |
| 74 shutil.copy2(mac_script, mac_dest) | 78 elif sys.platform.startswith('linux'): |
| 79 platform = 'linux' |
| 80 subdir = 'linux64' |
| 81 else: |
| 82 print 'Unknown platform: ' + sys.platform |
| 83 return 1 |
| 84 |
| 85 clang_format = os.path.join( |
| 86 TOOLCHAIN, 'clang+llvm-x86_64-' + platform, 'bin', 'clang-format') |
| 87 dest = os.path.join(BUILDTOOLS, subdir, 'clang-format') |
| 88 shutil.copy2(clang_format, dest) |
| 89 return 0 |
| 75 | 90 |
| 76 | 91 |
| 77 def main(argv): | 92 def main(argv): |
| 78 if sys.platform.startswith('win'): | 93 if sys.platform.startswith('win'): |
| 79 result = UpdateGNOnWindows() | 94 result = UpdateGNOnWindows() |
| 80 if result != 0: | 95 if result != 0: |
| 81 return result | 96 return result |
| 82 return UpdateClangFormatOnWindows() | 97 return UpdateClangFormatOnWindows() |
| 83 CopyClangFormatScripts() | 98 if Update() != 0: |
| 84 return Update() | 99 return 1 |
| 100 return CopyClangFormat() |
| 85 | 101 |
| 86 | 102 |
| 87 if __name__ == '__main__': | 103 if __name__ == '__main__': |
| 88 sys.exit(main(sys.argv)) | 104 sys.exit(main(sys.argv)) |
| OLD | NEW |