Makefile: clang-tools: Print information when clang-tidy tool is missing
Subsystems (2)
PATCH 1/2 Makefile: 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/run-clang-tools.py clang-tidy ./compile_commands.json
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "/usr/lib64/python3.8/multiprocessing/pool.py", line 125, in worker
result = (True, func(*args, **kwds))
File "/usr/lib64/python3.8/multiprocessing/pool.py", line 48, in mapstar
return list(map(*args))
File "./scripts/clang-tools/run-clang-tools.py", line 54, in run_analysis
p = subprocess.run(["clang-tidy", "-p", args.path, checks, entry["file"]],
File "/usr/lib64/python3.8/subprocess.py", line 489, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib64/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib64/python3.8/subprocess.py", 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 above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "./scripts/clang-tools/run-clang-tools.py", line 74, in <module>
main()
File "./scripts/clang-tools/run-clang-tools.py", line 70, in main
pool.map(run_analysis, datastore)
File "/usr/lib64/python3.8/multiprocessing/pool.py", line 364, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "/usr/lib64/python3.8/multiprocessing/pool.py", line 771, in get
raise self._value
FileNotFoundError: [Errno 2] No such file or directory: 'clang-tidy'
The patch adds more user-friendly information on the missing tool by catching FileNotFoundError for clang-tidy file and raising exception again for possible other files:
$ ./scripts/clang-tools/run-clang-tools.py clang-tidy ./compile_commands.json Command `clang-tidy` is missing in the system.
--- scripts/clang-tools/run-clang-tools.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
scripts/clang-tools/run-clang-tools.py +7 -1
@@ -67,7 +67,13 @@ def main(): # Read JSON data into the datastore variable with open(args.path, "r") as f: datastore = json.load(f) - pool.map(run_analysis, datastore) + try: + pool.map(run_analysis, datastore) + except FileNotFoundError as not_found: + if not_found.filename == 'clang-tidy': + print('Command `clang-tidy` is missing in the system.') + else: + raise not_found if __name__ == "__main__":
Signature · 1 line
2.26.3
PATCH 2/2 Makefile: clang-tools: Omit printing stack trace when KeyboardInterrupt is raised
When user terminates the script (also implicitly through for example make clang-analyzer) by using
Ctrl+C (or sending SIGINT more generally) the KeyboardInterrupt is raised printing stack trace of the execution as shown below:
$ ./scripts/clang-tools/run-clang-tools.py clang-tidy ./compile_commands.json
^CTraceback (most recent call last):
File "./scripts/clang-tools/run-clang-tools.py", line 74, in <module>
main()
File "./scripts/clang-tools/run-clang-tools.py", line 70, in main
pool.map(run_analysis, datastore)
File "/usr/lib64/python3.8/multiprocessing/pool.py", line 364, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "/usr/lib64/python3.8/multiprocessing/pool.py", line 765, in get
self.wait(timeout)
File "/usr/lib64/python3.8/multiprocessing/pool.py", line 762, in wait
self._event.wait(timeout)
File "/usr/lib64/python3.8/threading.py", line 558, in wait
Process ForkPoolWorker-6:
Process ForkPoolWorker-1:
Process ForkPoolWorker-5:
Process ForkPoolWorker-7:
Process ForkPoolWorker-2:
Process ForkPoolWorker-3:
Process ForkPoolWorker-4:
Process ForkPoolWorker-8:
signaled = self._cond.wait(timeout)
File "/usr/lib64/python3.8/threading.py", line 302, in wait
waiter.acquire()
KeyboardInterruptThe patch handles the raise of the KeyboardInterrupt and exits when occurred with code 130 as documented in: https://tldp.org/LDP/abs/html/exitcodes.html
--- scripts/clang-tools/run-clang-tools.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
scripts/clang-tools/run-clang-tools.py +4 -1
@@ -77,4 +77,7 @@ def main(): if __name__ == "__main__": - main() + try: + main() + except KeyboardInterrupt: + sys.exit(130)
Signature · 1 line
2.26.3
Re: [PATCH 2/2] Makefile: clang-tools: Omit printing stack trace when KeyboardInterrupt is raised
Quoted 23 lines · Maciej Falkowski
When user terminates the script (also implicitly through for example
make clang-analyzer) by using
Ctrl+C (or sending SIGINT more generally) the KeyboardInterrupt is raised printing stack trace of the execution as shown below:$ ./scripts/clang-tools/run-clang-tools.py clang-tidy ./compile_commands.json ^CTraceback (most recent call last): File "./scripts/clang-tools/run-clang-tools.py", line 74, in <module> main() File "./scripts/clang-tools/run-clang-tools.py", line 70, in main pool.map(run_analysis, datastore) File "/usr/lib64/python3.8/multiprocessing/pool.py", line 364, in map return self._map_async(func, iterable, mapstar, chunksize).get() File "/usr/lib64/python3.8/multiprocessing/pool.py", line 765, in get self.wait(timeout) File "/usr/lib64/python3.8/multiprocessing/pool.py", line 762, in wait self._event.wait(timeout) File "/usr/lib64/python3.8/threading.py", line 558, in wait Process ForkPoolWorker-6: Process ForkPoolWorker-1: Process ForkPoolWorker-5: Process ForkPoolWorker-7:
Quoted 8 lines
Process ForkPoolWorker-2:
Process ForkPoolWorker-3:
Process ForkPoolWorker-4:
Process ForkPoolWorker-8:
signaled = self._cond.wait(timeout)
File "/usr/lib64/python3.8/threading.py", line 302, in wait
waiter.acquire()
KeyboardInterruptWith this applied,
$ make LLVM=1 LLVM_IAS=1 -j72 clang-analyzer ^C Process ForkPoolWorker-5: make: *** [Makefile:1902: clang-analyzer] Error 130
Thanks for the patch!
Quoted 24 lines
The patch handles the raise of the KeyboardInterrupt and exits when occurred with code 130 as documented in: https://tldp.org/LDP/abs/html/exitcodes.html
Signed-off-by Maciej Falkowski <[email protected]>--- scripts/clang-tools/run-clang-tools.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)scripts/clang-tools/run-clang-tools.py +4
-2@@ -77,4 +77,7 @@ def main(): if __name__ == "__main__": - main() + try: + main() + except KeyboardInterrupt: + sys.exit(130) --2.26.3
Signature · 2 lines
Thanks, ~Nick Desaulniers
Re: [PATCH 2/2] Makefile: clang-tools: Omit printing stack trace when KeyboardInterrupt is raised
Quoted 41 lines · Nick Desaulniers
Quoted 23 lines · Maciej Falkowski
When user terminates the script (also implicitly through for example
make clang-analyzer) by using
Ctrl+C (or sending SIGINT more generally) the KeyboardInterrupt is raised printing stack trace of the execution as shown below:$ ./scripts/clang-tools/run-clang-tools.py clang-tidy ./compile_commands.json ^CTraceback (most recent call last): File "./scripts/clang-tools/run-clang-tools.py", line 74, in <module> main() File "./scripts/clang-tools/run-clang-tools.py", line 70, in main pool.map(run_analysis, datastore) File "/usr/lib64/python3.8/multiprocessing/pool.py", line 364, in map return self._map_async(func, iterable, mapstar, chunksize).get() File "/usr/lib64/python3.8/multiprocessing/pool.py", line 765, in get self.wait(timeout) File "/usr/lib64/python3.8/multiprocessing/pool.py", line 762, in wait self._event.wait(timeout) File "/usr/lib64/python3.8/threading.py", line 558, in wait Process ForkPoolWorker-6: Process ForkPoolWorker-1: Process ForkPoolWorker-5: Process ForkPoolWorker-7:Quoted 8 lines
Process ForkPoolWorker-2: Process ForkPoolWorker-3: Process ForkPoolWorker-4: Process ForkPoolWorker-8: signaled = self._cond.wait(timeout) File "/usr/lib64/python3.8/threading.py", line 302, in wait waiter.acquire() KeyboardInterruptWith this applied,
$ make LLVM=1 LLVM_IAS=1 -j72 clang-analyzer ^C Process ForkPoolWorker-5: make: *** [Makefile:1902: clang-analyzer] Error 130
Quoted 4 lines
Reviewed-by Nick Desaulniers <[email protected]>Tested-by Nick Desaulniers <[email protected]>Thanks for the patch!
I am not a python expert, but is
"Let's suppress back-trace when a user presses an interrupt" the common coding style?
If really so, do we need to do something similar in all python scripts? I do not know what is special about run-clang-tools.py.
For example, if I press Ctrl-C while building Clang by using tc-build, I see a back-trace.
I have never thought back-tracing was annoying.
The exit code is 130 regardless of this patch.
BTW, I prefer not having "Makefile:" in the patch subject since this is not touching Makefile at all.
I rather like "clang-tools:" or "scripts/clang-tools:".
Quoted 15 lines
Quoted 15 lines
The patch handles the raise of the KeyboardInterrupt and exits when occurred with code 130 as documented in: https://tldp.org/LDP/abs/html/exitcodes.html
Signed-off-by Maciej Falkowski <[email protected]>--- scripts/clang-tools/run-clang-tools.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)scripts/clang-tools/run-clang-tools.py +0
-0@@ -77,4 +77,7 @@ def main():
Quoted 14 lines
Quoted 9 lines
scripts/clang-tools/run-clang-tools.py +4
-2if __name__ == "__main__": - main() + try: + main() + except KeyboardInterrupt: + sys.exit(130) --2.26.3
--
Thanks,
~Nick Desaulniers
--
Best Regards
Masahiro Yamada
Re: [PATCH 2/2] Makefile: clang-tools: Omit printing stack trace when KeyboardInterrupt is raised
Quoted 40 lines · Masahiro Yamada
Quoted 38 lines · Nick Desaulniers
Quoted 22 lines · Maciej Falkowski
When user terminates the script (also implicitly through for example
make clang-analyzer) by using
Ctrl+C (or sending SIGINT more generally) the KeyboardInterrupt is raised printing stack trace of the execution as shown below:$ ./scripts/clang-tools/run-clang-tools.py clang-tidy ./compile_commands.json ^CTraceback (most recent call last): File "./scripts/clang-tools/run-clang-tools.py", line 74, in <module> main() File "./scripts/clang-tools/run-clang-tools.py", line 70, in main pool.map(run_analysis, datastore) File "/usr/lib64/python3.8/multiprocessing/pool.py", line 364, in map return self._map_async(func, iterable, mapstar, chunksize).get() File "/usr/lib64/python3.8/multiprocessing/pool.py", line 765, in get self.wait(timeout) File "/usr/lib64/python3.8/multiprocessing/pool.py", line 762, in wait self._event.wait(timeout) File "/usr/lib64/python3.8/threading.py", line 558, in wait Process ForkPoolWorker-6: Process ForkPoolWorker-1: Process ForkPoolWorker-5: Process ForkPoolWorker-7:Quoted 8 lines
Process ForkPoolWorker-2: Process ForkPoolWorker-3: Process ForkPoolWorker-4: Process ForkPoolWorker-8: signaled = self._cond.wait(timeout) File "/usr/lib64/python3.8/threading.py", line 302, in wait waiter.acquire() KeyboardInterruptWith this applied,
$ make LLVM=1 LLVM_IAS=1 -j72 clang-analyzer ^C Process ForkPoolWorker-5: make: *** [Makefile:1902: clang-analyzer] Error 130
Quoted 8 lines
Quoted 4 lines
Reviewed-by Nick Desaulniers <[email protected]>Tested-by Nick Desaulniers <[email protected]>Thanks for the patch!
I am not a python expert, but is
"Let's suppress back-trace when a user presses an interrupt" the common coding style?
I think that is not a common coding style.
In this case, the back-trace is verbose and it is caused by a bug in multiprocessing Pool.
Quoted 2 lines
If really so, do we need to do something similar in all python scripts? I do not know what is special about
run-clang-tools.py.
I think no, I misunderstood the nature of the problem.
The verbose back-trace is a result of the multiprocessing Pool
not handling KeyboardInterrupt properly.
It is the old bug(bugs.python.org/issue8296), yet to be solved(bugs.python.org/issue22393). For more info please see:
https://stackoverflow.com/questions/1408356/keyboard-interrupts-with-pythons-multiprocessing-pool
This issue is already once solved in a Linux source tree in a scripts/checkkconfigsymbols.py:
scripts/checkkconfigsymbols.py:312
try:
return check_symbols_helper(pool, ignore)
except KeyboardInterrupt:
pool.terminate()
pool.join()
sys.exit(1)
Also the comment:scripts/checkkconfigsymbols.py:321
"""Helper method for check_symbols(). Used to catch keyboard interrupts in check_symbols() in order to properly terminate running worker processes."""
Quoted 5 lines
For example, if I press Ctrl-C while building Clang by using tc-build, I see a back-trace.
I have never thought back-tracing was annoying.The exit code is 130 regardless of this patch.
Okay.
Quoted 6 lines
BTW, I prefer not having "
Makefile:" in the patch subject since this is not touchingMakefileat all.I rather like "clang-tools:" or "
scripts/clang-tools:".
Okay.
The solution should cover the whole bug, I think this patch may be dismissed then.
Thank you for your feedback!
Best regards,
Maciej Falkowski
Quoted 38 lines
Quoted 20 lines
Quoted 20 lines
The patch handles the raise of the KeyboardInterrupt and exits when occurred with code 130 as documented in: https://tldp.org/LDP/abs/html/exitcodes.html
Signed-off-by Maciej Falkowski <[email protected]>--- scripts/clang-tools/run-clang-tools.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)scripts/clang-tools/run-clang-tools.py +0
-0@@ -77,4 +77,7 @@ def main():Quoted 13 lines
Quoted 9 lines
scripts/clang-tools/run-clang-tools.py +4
-2if __name__ == "__main__": - main() + try: + main() + except KeyboardInterrupt: + sys.exit(130) --2.26.3
--
Thanks,
~Nick Desaulniers--
Best Regards
Masahiro Yamada
Quoted 36 lines · Maciej Falkowski
When
clang-tidytool is missing in the system, the FileNotFoundError exception is raised in the program reporting a stack trace to the user:$ ./scripts/clang-tools/run-clang-tools.py clang-tidy ./compile_commands.json multiprocessing.pool.RemoteTraceback: """ Traceback (most recent call last): File "/usr/lib64/python3.8/multiprocessing/pool.py", line 125, in worker result = (True, func(*args, **kwds)) File "/usr/lib64/python3.8/multiprocessing/pool.py", line 48, in mapstar return list(map(*args)) File "./scripts/clang-tools/run-clang-tools.py", line 54, in run_analysis p = subprocess.run(["clang-tidy", "-p", args.path, checks, entry["file"]], File "/usr/lib64/python3.8/subprocess.py", line 489, in run with Popen(*popenargs, **kwargs) as process: File "/usr/lib64/python3.8/subprocess.py", line 854, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib64/python3.8/subprocess.py", 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 above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "./scripts/clang-tools/run-clang-tools.py", line 74, in <module>main()File "
./scripts/clang-tools/run-clang-tools.py", line 70, in main
pool.map(run_analysis, datastore)
File "/usr/lib64/python3.8/multiprocessing/pool.py", line 364, in map
returnself._map_async(func, iterable, mapstar, chunksize).get()
File "/usr/lib64/python3.8/multiprocessing/pool.py", line 771, in get
raise self._value
FileNotFoundError: [Errno 2] No such file or directory: 'clang-tidy'
Quoted 6 lines
The patch adds more user-friendly information on the missing tool by catching FileNotFoundError for
clang-tidyfile and raising exception again for possible other files:$ ./scripts/clang-tools/run-clang-tools.py clang-tidy ./compile_commands.json Command `clang-tidy` is missing in the system.
This is much nicer when I run:
$ make LLVM=1 LLVM_IAS=1 -j72 clang-analyzer without clang-tidy built or installed locally, thank you for the patch.
Please make sure to include the results from running ./scripts/get_maintainer.pl on your patch files for the CC list.
Quoted 29 lines
Signed-off-by Maciej Falkowski <[email protected]>--- scripts/clang-tools/run-clang-tools.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)scripts/clang-tools/run-clang-tools.py +7
-2@@ -67,7 +67,13 @@ def main(): # Read JSON data into the datastore variable with open(args.path, "r") as f: datastore = json.load(f) - pool.map(run_analysis, datastore) + try: + pool.map(run_analysis, datastore) + except FileNotFoundError as not_found: + if not_found.filename == 'clang-tidy': + print('Command `clang-tidy` is missing in the system.') + else: + raise not_found if __name__ == "__main__": --2.26.3
Signature · 2 lines
Thanks, ~Nick Desaulniers