| 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 """This script runs "pub get" on all directories within the tree that have |
| 7 pubspec.yaml files. |
| 8 |
| 9 See https://www.dartlang.org/tools/pub/get-started.html for information about |
| 10 the pub tool.""" |
| 11 |
| 12 import argparse |
| 13 import os |
| 14 import subprocess |
| 15 import sys |
| 16 |
| 17 def pub_get(dart_sdk_path, target_directory): |
| 18 cmd = [ |
| 19 os.path.join(dart_sdk_path, "bin/pub") |
| 20 ] |
| 21 cmd.extend(["get"]) |
| 22 |
| 23 # Cache the downloaded pubs inside the repo to avoid the chance of multiple |
| 24 # simultaneous builds in different repos stomping on each other. |
| 25 env = os.environ.copy() |
| 26 env["PUB_CACHE"] = os.path.join(os.getcwd(), ".pub-cache") |
| 27 subprocess.check_output(cmd, shell=False, |
| 28 stderr=subprocess.STDOUT, |
| 29 cwd=target_directory, |
| 30 env=env) |
| 31 |
| 32 |
| 33 def main(repository_root, dart_sdk_path): |
| 34 os.chdir(repository_root) |
| 35 |
| 36 # Relativize dart_sdk_path to repository_root. |
| 37 dart_sdk_path_from_root = os.path.join(repository_root, |
| 38 os.path.relpath(dart_sdk_path, repository_root)) |
| 39 |
| 40 cmd = ["git", "ls-files", "*/pubspec.yaml"] |
| 41 pubspec_yaml_files = subprocess.check_output(cmd, |
| 42 shell=False, |
| 43 stderr=subprocess.STDOUT) |
| 44 |
| 45 for f in pubspec_yaml_files.split(): |
| 46 pub_get(dart_sdk_path_from_root, os.path.dirname(f)) |
| 47 |
| 48 |
| 49 if __name__ == '__main__': |
| 50 parser = argparse.ArgumentParser( |
| 51 description="Run 'pub get' on all directories with checked-in " |
| 52 "pubspec.yaml files") |
| 53 parser.add_argument("--repository-root", |
| 54 metavar="<repository-root>", |
| 55 type=str, |
| 56 required=True, |
| 57 help="Path to the root of the Git repository, " |
| 58 "specified as a relative path from this directory.") |
| 59 parser.add_argument("--dart-sdk-directory", |
| 60 metavar="<dart-sdk-directory>", |
| 61 type=str, |
| 62 required=True, |
| 63 help="Path to the directory containing the Dart SDK, " |
| 64 "specified as a relative path from this directory.") |
| 65 args = parser.parse_args() |
| 66 _current_path = os.path.dirname(os.path.realpath(__file__)) |
| 67 _repository_root = os.path.join(_current_path, args.repository_root) |
| 68 _dart_sdk_path = os.path.join(_current_path, args.dart_sdk_directory) |
| 69 sys.exit(main(_repository_root, _dart_sdk_path)) |
| OLD | NEW |