| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Redirects to the version of clang-format checked into the Chrome tree. | 6 """Redirects to the version of clang-format checked into the Chrome tree. |
| 7 | 7 |
| 8 clang-format binaries are pulled down from Google Cloud Storage whenever you | 8 clang-format binaries are pulled down from Google Cloud Storage whenever you |
| 9 sync Chrome, to platform-specific locations. This script knows how to locate | 9 sync Chrome, to platform-specific locations. This script knows how to locate |
| 10 those tools, assuming the script is invoked from inside a Chromium checkout.""" | 10 those tools, assuming the script is invoked from inside a Chromium checkout.""" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 Contact nick@chromium.org if you have any additional questions.\n\n''' | 55 Contact nick@chromium.org if you have any additional questions.\n\n''' |
| 56 | 56 |
| 57 error_text += 'File does not exist: %s' % tool_path | 57 error_text += 'File does not exist: %s' % tool_path |
| 58 | 58 |
| 59 raise NotFoundError(error_text) | 59 raise NotFoundError(error_text) |
| 60 return tool_path | 60 return tool_path |
| 61 | 61 |
| 62 | 62 |
| 63 def FindClangFormatScriptInChromiumTree(script_name): | 63 def FindClangFormatScriptInChromiumTree(script_name): |
| 64 """Return a path to a clang-format helper script, or die trying.""" | 64 """Return a path to a clang-format helper script, or die trying.""" |
| 65 # The binaries in platform-specific subdirectories in src/tools/gn/bin. | |
| 66 script_path = os.path.join(_FindChromiumTree(), 'src', 'third_party', | 65 script_path = os.path.join(_FindChromiumTree(), 'src', 'third_party', |
| 67 'clang_format', 'scripts', script_name) | 66 'clang_format', 'script', script_name) |
| 68 if not os.path.exists(script_path): | 67 if not os.path.exists(script_path): |
| 69 raise NotFoundError('File does not exist: %s' % script_path) | 68 # TODO(thakis): Remove the fallback to the old location after a few weeks. |
| 69 script_path = os.path.join(_FindChromiumTree(), 'src', 'third_party', |
| 70 'clang_format', 'scripts', script_name) |
| 71 if not os.path.exists(script_path): |
| 72 raise NotFoundError('File does not exist: %s' % script_path) |
| 70 return script_path | 73 return script_path |
| 71 | 74 |
| 72 | 75 |
| 73 def main(args): | 76 def main(args): |
| 74 try: | 77 try: |
| 75 tool = FindClangFormatToolInChromiumTree() | 78 tool = FindClangFormatToolInChromiumTree() |
| 76 except NotFoundError, e: | 79 except NotFoundError, e: |
| 77 print >> sys.stderr, e | 80 print >> sys.stderr, e |
| 78 sys.exit(1) | 81 sys.exit(1) |
| 79 | 82 |
| 80 # Add some visibility to --help showing where the tool lives, since this | 83 # Add some visibility to --help showing where the tool lives, since this |
| 81 # redirection can be a little opaque. | 84 # redirection can be a little opaque. |
| 82 help_syntax = ('-h', '--help', '-help', '-help-list', '--help-list') | 85 help_syntax = ('-h', '--help', '-help', '-help-list', '--help-list') |
| 83 if any(match in args for match in help_syntax): | 86 if any(match in args for match in help_syntax): |
| 84 print '\nDepot tools redirects you to the clang-format at:\n %s\n' % tool | 87 print '\nDepot tools redirects you to the clang-format at:\n %s\n' % tool |
| 85 | 88 |
| 86 return subprocess.call([tool] + sys.argv[1:]) | 89 return subprocess.call([tool] + sys.argv[1:]) |
| 87 | 90 |
| 88 | 91 |
| 89 if __name__ == '__main__': | 92 if __name__ == '__main__': |
| 90 sys.exit(main(sys.argv)) | 93 sys.exit(main(sys.argv)) |
| OLD | NEW |