Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Side by Side Diff: clang_format.py

Issue 177213013: clang-format: Allow .proto files to be formatted; remove warnings. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: More cleanup. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | git_cl.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 23 matching lines...) Expand all
34 return source_root 34 return source_root
35 35
36 36
37 def FindClangFormatToolInChromiumTree(): 37 def FindClangFormatToolInChromiumTree():
38 """Return a path to the clang-format executable, or die trying.""" 38 """Return a path to the clang-format executable, or die trying."""
39 tool_path = os.path.join(_FindChromiumSourceRoot(), 'third_party', 39 tool_path = os.path.join(_FindChromiumSourceRoot(), 'third_party',
40 'clang_format', 'bin', 40 'clang_format', 'bin',
41 gclient_utils.GetMacWinOrLinux(), 41 gclient_utils.GetMacWinOrLinux(),
42 'clang-format' + gclient_utils.GetExeSuffix()) 42 'clang-format' + gclient_utils.GetExeSuffix())
43 if not os.path.exists(tool_path): 43 if not os.path.exists(tool_path):
44 # TODO(nick): After March 2014, eliminate the following advisory. 44 raise NotFoundError('File does not exist: %s' % tool_path)
45 error_text = '''\n GIT CL FORMAT - WINTER WEATHER ADVISORY
46
47 clang-format binaries now come with every Chrome checkout!
48
49 Unfortunately, your depot_tools scripts tried to find clang-format binaries
50 in your Chrome checkout, but failed. This is expected if you haven't synced
51 since the binaries were added.
52
53 'git cl format' will probably not work until you sync your Chrome tree.
54 Sorry about that.
55
56 Contact nick@chromium.org if you have any additional questions.\n\n'''
57
58 error_text += 'File does not exist: %s' % tool_path
59
60 raise NotFoundError(error_text)
61 return tool_path 45 return tool_path
62 46
63 47
64 def FindClangFormatScriptInChromiumTree(script_name): 48 def FindClangFormatScriptInChromiumTree(script_name):
65 """Return a path to a clang-format helper script, or die trying.""" 49 """Return a path to a clang-format helper script, or die trying."""
66 script_path = os.path.join(_FindChromiumSourceRoot(), 'third_party', 50 script_path = os.path.join(_FindChromiumSourceRoot(), 'third_party',
67 'clang_format', 'script', script_name) 51 'clang_format', 'script', script_name)
68 if not os.path.exists(script_path): 52 if not os.path.exists(script_path):
69 # TODO(thakis): Remove the fallback to the old location after a few weeks. 53 raise NotFoundError('File does not exist: %s' % script_path)
70 script_path = os.path.join(_FindChromiumSourceRoot(), 'third_party',
71 'clang_format', 'scripts', script_name)
72 if not os.path.exists(script_path):
73 raise NotFoundError('File does not exist: %s' % script_path)
74 return script_path 54 return script_path
75 55
76 56
77 def main(args): 57 def main(args):
78 try: 58 try:
79 tool = FindClangFormatToolInChromiumTree() 59 tool = FindClangFormatToolInChromiumTree()
80 except NotFoundError, e: 60 except NotFoundError, e:
81 print >> sys.stderr, e 61 print >> sys.stderr, e
82 sys.exit(1) 62 sys.exit(1)
83 63
84 # Add some visibility to --help showing where the tool lives, since this 64 # Add some visibility to --help showing where the tool lives, since this
85 # redirection can be a little opaque. 65 # redirection can be a little opaque.
86 help_syntax = ('-h', '--help', '-help', '-help-list', '--help-list') 66 help_syntax = ('-h', '--help', '-help', '-help-list', '--help-list')
87 if any(match in args for match in help_syntax): 67 if any(match in args for match in help_syntax):
88 print '\nDepot tools redirects you to the clang-format at:\n %s\n' % tool 68 print '\nDepot tools redirects you to the clang-format at:\n %s\n' % tool
89 69
90 return subprocess.call([tool] + sys.argv[1:]) 70 return subprocess.call([tool] + sys.argv[1:])
91 71
92 72
93 if __name__ == '__main__': 73 if __name__ == '__main__':
94 sys.exit(main(sys.argv)) 74 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | git_cl.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698