blob: f374a952a035331535fee77a0f12bdcd1381dd1f [file] [log] [blame]
erg@chromium.orge0a7c5d2015-02-23 20:30:08 +00001#!/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
8dartfmt binaries are pulled down during gclient sync in the mojo repo.
9
10This tool is named dart_format.py instead of dartfmt to parallel
11clang_format.py, which is in this same repository."""
12
Raul Tambre80ee78e2019-05-06 22:41:05 +000013from __future__ import print_function
14
erg@chromium.orge0a7c5d2015-02-23 20:30:08 +000015import os
16import subprocess
17import sys
18
Nico Weber09e0b382019-03-11 16:54:07 +000019import gclient_paths
erg@chromium.orge0a7c5d2015-02-23 20:30:08 +000020
21class NotFoundError(Exception):
22 """A file could not be found."""
23 def __init__(self, e):
24 Exception.__init__(self,
25 'Problem while looking for dartfmt in Chromium source tree:\n'
26 ' %s' % e)
27
28
29def FindDartFmtToolInChromiumTree():
30 """Return a path to the dartfmt executable, or die trying."""
Nico Weber09e0b382019-03-11 16:54:07 +000031 primary_solution_path = gclient_paths.GetPrimarySolutionPath()
erg@chromium.orge0a7c5d2015-02-23 20:30:08 +000032 if not primary_solution_path:
33 raise NotFoundError(
34 'Could not find checkout in any parent of the current path.')
35
36 dartfmt_path = os.path.join(primary_solution_path, 'third_party', 'dart-sdk',
37 'dart-sdk', 'bin', 'dartfmt')
38 if not os.path.exists(dartfmt_path):
39 raise NotFoundError('File does not exist: %s' % dartfmt_path)
40 return dartfmt_path
41
42
43def main(args):
44 try:
45 tool = FindDartFmtToolInChromiumTree()
Raul Tambre7c938462019-05-24 16:35:35 +000046 except NotFoundError as e:
Raul Tambre80ee78e2019-05-06 22:41:05 +000047 print(e, file=sys.stderr)
erg@chromium.orge0a7c5d2015-02-23 20:30:08 +000048 sys.exit(1)
49
50 # Add some visibility to --help showing where the tool lives, since this
51 # redirection can be a little opaque.
52 help_syntax = ('-h', '--help', '-help', '-help-list', '--help-list')
53 if any(match in args for match in help_syntax):
Raul Tambre80ee78e2019-05-06 22:41:05 +000054 print('\nDepot tools redirects you to the dartfmt at:\n %s\n' % tool)
erg@chromium.orge0a7c5d2015-02-23 20:30:08 +000055
56 return subprocess.call([tool] + sys.argv[1:])
57
58
59if __name__ == '__main__':
60 sys.exit(main(sys.argv))