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 """Redirects to the version of dartfmt checked into a gclient repo. |
| 7 |
| 8 dartfmt binaries are pulled down during gclient sync in the mojo repo. |
| 9 |
| 10 This tool is named dart_format.py instead of dartfmt to parallel |
| 11 clang_format.py, which is in this same repository.""" |
| 12 |
| 13 import gclient_utils |
| 14 import os |
| 15 import subprocess |
| 16 import sys |
| 17 |
| 18 class NotFoundError(Exception): |
| 19 """A file could not be found.""" |
| 20 def __init__(self, e): |
| 21 Exception.__init__(self, |
| 22 'Problem while looking for dartfmt in Chromium source tree:\n' |
| 23 ' %s' % e) |
| 24 |
| 25 |
| 26 def FindDartFmtToolInChromiumTree(): |
| 27 """Return a path to the dartfmt executable, or die trying.""" |
| 28 primary_solution_path = gclient_utils.GetPrimarySolutionPath() |
| 29 if not primary_solution_path: |
| 30 raise NotFoundError( |
| 31 'Could not find checkout in any parent of the current path.') |
| 32 |
| 33 dartfmt_path = os.path.join(primary_solution_path, 'third_party', 'dart-sdk', |
| 34 'dart-sdk', 'bin', 'dartfmt') |
| 35 if not os.path.exists(dartfmt_path): |
| 36 raise NotFoundError('File does not exist: %s' % dartfmt_path) |
| 37 return dartfmt_path |
| 38 |
| 39 |
| 40 def main(args): |
| 41 try: |
| 42 tool = FindDartFmtToolInChromiumTree() |
| 43 except NotFoundError, e: |
| 44 print >> sys.stderr, e |
| 45 sys.exit(1) |
| 46 |
| 47 # Add some visibility to --help showing where the tool lives, since this |
| 48 # redirection can be a little opaque. |
| 49 help_syntax = ('-h', '--help', '-help', '-help-list', '--help-list') |
| 50 if any(match in args for match in help_syntax): |
| 51 print '\nDepot tools redirects you to the dartfmt at:\n %s\n' % tool |
| 52 |
| 53 return subprocess.call([tool] + sys.argv[1:]) |
| 54 |
| 55 |
| 56 if __name__ == '__main__': |
| 57 sys.exit(main(sys.argv)) |
OLD | NEW |