Chromium Code Reviews| 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. | |
|
tonyg
2015/04/09 12:55:57
I wouldn't change anything here for now, but it se
blundell
2015/04/09 15:34:36
This was based on feedback from zra@, fwiw.
zra
2015/04/09 16:20:48
For better or worse, pub was envisioned as a devel
| |
| 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"] | |
|
tonyg
2015/04/09 12:55:57
I don't know the syntax here, but it looks like th
blundell
2015/04/09 15:34:36
Done.
| |
| 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 dest="repository_root", | |
|
tonyg
2015/04/09 12:55:57
nit: you can omit the dests when the only change i
blundell
2015/04/09 15:34:36
Done.
| |
| 55 metavar="<repository-root>", | |
| 56 type=str, | |
| 57 required=True, | |
| 58 help="Path to the root of the Git repository, " | |
| 59 "specified as a relative path from this directory.") | |
| 60 parser.add_argument("--dart-sdk-directory", | |
| 61 dest="dart_sdk_directory", | |
| 62 metavar="<dart-sdk-directory>", | |
| 63 type=str, | |
| 64 required=True, | |
| 65 help="Path to the directory containing the Dart SDK, " | |
| 66 "specified as a relative path from this directory.") | |
| 67 args = parser.parse_args() | |
| 68 _current_path = os.path.dirname(os.path.realpath(__file__)) | |
| 69 _repository_root = os.path.join(_current_path, args.repository_root) | |
| 70 _dart_sdk_path = os.path.join(_current_path, args.dart_sdk_directory) | |
| 71 sys.exit(main(_repository_root, _dart_sdk_path)) | |
| OLD | NEW |