From 54985b6b969e4428c79b5b5e8fb277d25d48c404 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 14 Dec 2016 15:03:42 -0800 Subject: [PATCH] Improve clang-format error messages when run outside of chromium checkout Its useful to be able to run clang-format on projects outside of chromium. This change informs developers how they can do that. Change-Id: I01ef755aa6e5b53a0a5bb6377e92b2ffdfd17eff Reviewed-on: https://chromium-review.googlesource.com/414204 Reviewed-by: Aaron Gable Commit-Queue: Sam Clegg --- clang_format.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/clang_format.py b/clang_format.py index 5bfeb1ae9..804a2051e 100755 --- a/clang_format.py +++ b/clang_format.py @@ -20,7 +20,7 @@ class NotFoundError(Exception): def __init__(self, e): Exception.__init__(self, 'Problem while looking for clang-format in Chromium source tree:\n' - ' %s' % e) + '%s' % e) def FindClangFormatToolInChromiumTree(): @@ -28,7 +28,8 @@ def FindClangFormatToolInChromiumTree(): bin_path = gclient_utils.GetBuildtoolsPlatformBinaryPath() if not bin_path: raise NotFoundError( - 'Could not find checkout in any parent of the current path.') + 'Could not find checkout in any parent of the current path.\n' + 'Set CHROMIUM_BUILDTOOLS_PATH to use outside of a chromium checkout.') tool_path = os.path.join(bin_path, 'clang-format' + gclient_utils.GetExeSuffix()) @@ -42,7 +43,9 @@ def FindClangFormatScriptInChromiumTree(script_name): tools_path = gclient_utils.GetBuildtoolsPath() if not tools_path: raise NotFoundError( - 'Could not find checkout in any parent of the current path.') + 'Could not find checkout in any parent of the current path.\n', + 'Set CHROMIUM_BUILDTOOLS_PATH to use outside of a chromium checkout.') + script_path = os.path.join(tools_path, 'clang_format', 'script', script_name) if not os.path.exists(script_path): raise NotFoundError('File does not exist: %s' % script_path) @@ -52,9 +55,9 @@ def FindClangFormatScriptInChromiumTree(script_name): def main(args): try: tool = FindClangFormatToolInChromiumTree() - except NotFoundError, e: - print >> sys.stderr, e - sys.exit(1) + except NotFoundError as e: + sys.stderr.write("%s\n" % str(e)) + return 1 # Add some visibility to --help showing where the tool lives, since this # redirection can be a little opaque.