[lkml]   [2021]   [Aug]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH v2] clang-tools: Print information when clang-tidy tool is missing
When clang-tidy tool is missing in the system, the FileNotFoundError
exception is raised in the program reporting a stack trace to the user:

$ ./scripts/clang-tools/ clang-tidy ./compile_commands.json
Traceback (most recent call last):
File "/usr/lib64/python3.8/multiprocessing/", line 125, in worker
result = (True, func(*args, **kwds))
File "/usr/lib64/python3.8/multiprocessing/", line 48, in mapstar
return list(map(*args))
File "./scripts/clang-tools/", line 54, in run_analysis
p =["clang-tidy", "-p", args.path, checks, entry["file"]],
File "/usr/lib64/python3.8/", line 489, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib64/python3.8/", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib64/python3.8/", line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'clang-tidy'

The patch adds more user-friendly information about missing tool:

$ ./scripts/clang-tools/ clang-tidy ./compile_commands.json
Command 'clang-tidy' is missing in the system

Signed-off-by: Maciej Falkowski <>
Hi Masahiro,

Thank you for your feedback!
I am sorry that I haven't replied for so long.

I agree with your point, based on this I would like
to propose a second version of the patch.

changes in v2:
- Solution has changed from LBYL style to EAFP

Best regards,
Maciej Falkowski
scripts/clang-tools/ | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/scripts/clang-tools/ b/scripts/clang-tools/
index fa7655c7cec0..27ebe2f2069a 100755
--- a/scripts/clang-tools/
+++ b/scripts/clang-tools/
@@ -67,7 +67,14 @@ def main():
# Read JSON data into the datastore variable
with open(args.path, "r") as f:
datastore = json.load(f)
-, datastore)
+ try:
+, datastore)
+ except FileNotFoundError as err:
+ if err.filename == 'clang-tidy':
+ print("Command 'clang-tidy' is missing in the system", file=sys.stderr)
+ sys.exit(127)
+ else:
+ raise err

if __name__ == "__main__":
 \ /
  Last update: 2021-08-07 13:02    [W:0.056 / U:0.076 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site