| 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(), "dart-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, dirs_to_ignore): |
| 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 ignore = reduce(lambda x, y: x or f.startswith(y), dirs_to_ignore, False) |
| 47 if ignore: |
| 48 continue |
| 49 pub_get(dart_sdk_path_from_root, os.path.dirname(f)) |
| 50 |
| 51 |
| 52 if __name__ == '__main__': |
| 53 parser = argparse.ArgumentParser( |
| 54 description="Run 'pub get' on all directories with checked-in " |
| 55 "pubspec.yaml files") |
| 56 parser.add_argument("--repository-root", |
| 57 metavar="<repository-root>", |
| 58 type=str, |
| 59 required=True, |
| 60 help="Path to the root of the Git repository, " |
| 61 "specified as a relative path from this directory.") |
| 62 parser.add_argument("--dart-sdk-directory", |
| 63 metavar="<dart-sdk-directory>", |
| 64 type=str, |
| 65 required=True, |
| 66 help="Path to the directory containing the Dart SDK, " |
| 67 "specified as a relative path from this directory.") |
| 68 parser.add_argument("--dirs-to-ignore", |
| 69 metavar="<dir>", |
| 70 nargs="+", |
| 71 default=[], |
| 72 type=str, |
| 73 help="Optional list of directories to ignore, specified " |
| 74 "relative to the root of the repo. 'pub get' will " |
| 75 "not be run for any subdirectories of these " |
| 76 "directories.") |
| 77 args = parser.parse_args() |
| 78 _current_path = os.path.dirname(os.path.realpath(__file__)) |
| 79 _repository_root = os.path.join(_current_path, args.repository_root) |
| 80 _dart_sdk_path = os.path.join(_current_path, args.dart_sdk_directory) |
| 81 sys.exit(main(_repository_root, _dart_sdk_path, args.dirs_to_ignore)) |
| OLD | NEW |