dart_format.py 1.8 KB

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