erg@chromium.org | e0a7c5d | 2015-02-23 20:30:08 +0000 | [diff] [blame^] | 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 os |
| 14 | import subprocess |
| 15 | import sys |
| 16 | |
| 17 | import gclient_utils |
| 18 | |
| 19 | class NotFoundError(Exception): |
| 20 | """A file could not be found.""" |
| 21 | def __init__(self, e): |
| 22 | Exception.__init__(self, |
| 23 | 'Problem while looking for dartfmt in Chromium source tree:\n' |
| 24 | ' %s' % e) |
| 25 | |
| 26 | |
| 27 | def FindDartFmtToolInChromiumTree(): |
| 28 | """Return a path to the dartfmt executable, or die trying.""" |
| 29 | primary_solution_path = gclient_utils.GetPrimarySolutionPath() |
| 30 | if not primary_solution_path: |
| 31 | raise NotFoundError( |
| 32 | 'Could not find checkout in any parent of the current path.') |
| 33 | |
| 34 | dartfmt_path = os.path.join(primary_solution_path, 'third_party', 'dart-sdk', |
| 35 | 'dart-sdk', 'bin', 'dartfmt') |
| 36 | if not os.path.exists(dartfmt_path): |
| 37 | raise NotFoundError('File does not exist: %s' % dartfmt_path) |
| 38 | return dartfmt_path |
| 39 | |
| 40 | |
| 41 | def main(args): |
| 42 | try: |
| 43 | tool = FindDartFmtToolInChromiumTree() |
| 44 | except NotFoundError, e: |
| 45 | print >> sys.stderr, e |
| 46 | sys.exit(1) |
| 47 | |
| 48 | # Add some visibility to --help showing where the tool lives, since this |
| 49 | # redirection can be a little opaque. |
| 50 | help_syntax = ('-h', '--help', '-help', '-help-list', '--help-list') |
| 51 | if any(match in args for match in help_syntax): |
| 52 | print '\nDepot tools redirects you to the dartfmt at:\n %s\n' % tool |
| 53 | |
| 54 | return subprocess.call([tool] + sys.argv[1:]) |
| 55 | |
| 56 | |
| 57 | if __name__ == '__main__': |
| 58 | sys.exit(main(sys.argv)) |