Chromium Code Reviews| Index: mojo/public/tools/git/dart_pub_get.py |
| diff --git a/mojo/public/tools/git/dart_pub_get.py b/mojo/public/tools/git/dart_pub_get.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..a826a517c492da0bb67cdce7dc05b775b12c5e6c |
| --- /dev/null |
| +++ b/mojo/public/tools/git/dart_pub_get.py |
| @@ -0,0 +1,71 @@ |
| +#!/usr/bin/python |
| +# Copyright 2015 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""This script runs "pub get" on all directories within the tree that have |
| +pubspec.yaml files. |
| + |
| +See https://www.dartlang.org/tools/pub/get-started.html for information about |
| +the pub tool.""" |
| + |
| +import argparse |
| +import os |
| +import subprocess |
| +import sys |
| + |
| +def pub_get(dart_sdk_path, target_directory): |
| + cmd = [ |
| + os.path.join(dart_sdk_path, "bin/pub") |
| + ] |
| + cmd.extend(["get"]) |
| + |
| + # Cache the downloaded pubs inside the repo to avoid the chance of multiple |
| + # 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
|
| + env = os.environ.copy() |
| + env["PUB_CACHE"] = os.path.join(os.getcwd(), ".pub-cache") |
| + subprocess.check_output(cmd, shell=False, |
| + stderr=subprocess.STDOUT, |
| + cwd=target_directory, |
| + env=env) |
| + |
| + |
| +def main(repository_root, dart_sdk_path): |
| + os.chdir(repository_root) |
| + |
| + # Relativize dart_sdk_path to repository_root. |
| + dart_sdk_path_from_root = os.path.join(repository_root, |
| + os.path.relpath(dart_sdk_path, repository_root)) |
| + |
| + 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.
|
| + pubspec_yaml_files = subprocess.check_output(cmd, |
| + shell=False, |
| + stderr=subprocess.STDOUT) |
| + |
| + for f in pubspec_yaml_files.split(): |
| + pub_get(dart_sdk_path_from_root, os.path.dirname(f)) |
| + |
| + |
| +if __name__ == '__main__': |
| + parser = argparse.ArgumentParser( |
| + description="Run 'pub get' on all directories with checked-in " |
| + "pubspec.yaml files") |
| + parser.add_argument("--repository-root", |
| + 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.
|
| + metavar="<repository-root>", |
| + type=str, |
| + required=True, |
| + help="Path to the root of the Git repository, " |
| + "specified as a relative path from this directory.") |
| + parser.add_argument("--dart-sdk-directory", |
| + dest="dart_sdk_directory", |
| + metavar="<dart-sdk-directory>", |
| + type=str, |
| + required=True, |
| + help="Path to the directory containing the Dart SDK, " |
| + "specified as a relative path from this directory.") |
| + args = parser.parse_args() |
| + _current_path = os.path.dirname(os.path.realpath(__file__)) |
| + _repository_root = os.path.join(_current_path, args.repository_root) |
| + _dart_sdk_path = os.path.join(_current_path, args.dart_sdk_directory) |
| + sys.exit(main(_repository_root, _dart_sdk_path)) |