ctcache icon indicating copy to clipboard operation
ctcache copied to clipboard

run-clang-tidy - No such file or directory: '-p=...'

Open bansan85 opened this issue 1 year ago • 10 comments

It's probably related to #16

I did exactly the same thing:

CTCACHE_CLANG_TIDY=/usr/bin/clang-tidy-17 CTCACHE_DIR=/tmp/ctcache run-clang-tidy-17 -clang-tidy-binary /usr/local/bin/clang-tidy-cache

I tried with clang-tidy-cache from main and from commit 03644275e794b0587849bfc2ec6123d5ae0bdb1c (Jan 20, 2023). Both have the same problem.

I have:

$ CTCACHE_CLANG_TIDY=/usr/bin/clang-tidy-17 CTCACHE_DIR=/tmp/ctcache time run-clang-tidy-17 -clang-tidy-binary /usr/local/bin/clang-tidy-cache
<class 'FileNotFoundError'>: [Errno 2] No such file or directory: '-p=/home/...'
Unable to run clang-tidy.
Command exited with non-zero status 1
0.09user 0.01system 0:00.11elapsed 99%CPU (0avgtext+0avgdata 16456maxresident)k
0inputs+0outputs (0major+4391minor)pagefaults 0swaps

bansan85 avatar Mar 22 '24 11:03 bansan85

Hi, I've pushed some new changes, could you re-run it also with CTCACHE_DEBUG=1 and paste the output here?

matus-chochlik avatar Mar 23 '24 04:03 matus-chochlik

I have :

Options: ClangTidyCacheOpts(clang_tidy_args:['-p', '/home/...', '', '-list-checks', '-'],compiler_args:[],original_args:['-p=/home/...', '', '-list-checks', '-'])
Traceback (most recent call last):
  File "/usr/local/bin/clang-tidy-cache", line 1163, in <module>
    sys.exit(main())
  File "/usr/local/bin/clang-tidy-cache", line 1151, in main
    return run_clang_tidy_cached(log, opts)
  File "/usr/local/bin/clang-tidy-cache", line 1102, in run_clang_tidy_cached
    proc = subprocess.Popen(
  File "/usr/lib/python3.10/subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.10/subprocess.py", line 1863, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '-p=/home/...'
Unable to run clang-tidy.
Command exited with non-zero status 1
0.18user 0.02system 0:00.22elapsed 91%CPU (0avgtext+0avgdata 26648maxresident)k
720inputs+8outputs (1major+5864minor)pagefaults 0swaps

bansan85 avatar Mar 25 '24 08:03 bansan85

This will take some time. I need to have a look how run-clang-tidy actually invokes clang tidy, because the command-line passed to the cache misses the required first argument.

matus-chochlik avatar Mar 27 '24 04:03 matus-chochlik

You'll probably need to pass a script like this to run-clang-tidy instead of giving it the cache client directly

matus-chochlik avatar Mar 27 '24 04:03 matus-chochlik

Okay, thanks for your help.

CTCACHE_CLANG_TIDY=/usr/bin/clang-tidy-17 CTCACHE_DIR=/tmp/ctcache run-clang-tidy-17 -clang-tidy-binary /usr/local/bin/clang-tidy works like a charm.

Now I have to chose between you and kokulshan/clang-tidy-cache because both of you works well. 🎲

bansan85 avatar Mar 27 '24 10:03 bansan85

Isn't the "compile_commands.json" path required? or I create a "compile_commands.json" during the cmake_configuration phase(-DCMAKE_EXPORT_COMPILE_COMMANDS=ON). How can I run this ctcache with this method?

Also, I thought it was necessary to set the following variables. export CTCACHE_LOCAL=1 export CTCACHE_SAVE_OUTPUT=1

My run command: python3 tools/host/ctcache/clang_tidy_cache.py /usr/bin/run-clang-tidy-11 -clang-tidy-binary /usr/bin/clang-tidy-11 -p <compile_commands.json_path> -quiet

  • If I don't make any changes it works fine.
  • Especially when I inject error into a cc file it can't find it.

where am i making a mistake?

@matus-chochlik @bansan85 Thank you in advance.

eyuksekkolasin avatar Oct 22 '24 08:10 eyuksekkolasin

Hi,

when clang-tidy-cache is parsing arguments they are split between arguments for the cache tool and arguments forwarded to clang-tidy and these two sets should be separated by an -- argument. So this should work:

python3 tools/host/ctcache/clang_tidy_cache.py /usr/bin/run-clang-tidy-11 -clang-tidy-binary /usr/bin/clang-tidy-11 -p <compile_commands.json_path> -- -quiet

IIRC neither CTACHE_LOCAL nor CTCACHE_SAVE_OUTPUT should be necessary for the compile_commands to be used.

matus-chochlik avatar Oct 23 '24 07:10 matus-chochlik

Hello again,

I apologize for bothering you once more.

CMD:

python3 tools/host/ctcache/clang_tidy_cache.py /usr/bin/run-clang-tidy-11 -clang-tidy-binary /usr/bin/clang-tidy-11 -p <compile_commands.json_path>

When I run the script, the cache directory under /tmp is created as follows:

ls /tmp/ctcache-user
52/
    stats

However, when I run the script again, clang-tidy still takes the same amount of time. In this case, it seems that the cache is not being utilized.

Before using the script, as I mentioned earlier, when I set the following variables:

export CTCACHE_LOCAL=1
export CTCACHE_SAVE_OUTPUT=1

the second clang-tidy run uses the cache and completes much faster and the cache dir under /tmp is created as follows:

ls /tmp/ctcache-user
52/
   213284d23c794fce9b69d01d8c5ecb9c999dfc  stats
  • In this case, I am deliberately injecting an error into a file. As a result, it quickly retrieves from the cache and continues on its way. Especially when I inject error into a cc file it can't find it.

Could the reason for this situation be that it cannot detect which file has changed? After all, run-clang-tidy only requires the compile_command.json_path parameter. Who can detect changes to that file? Should I manage this manually?



Thank you very much for your patience.
@matus-chochlik @bansan85 @jeremy-coulon

P.S: I got to know you from the discussion over there :) Issue: run-clang-tidy support #16." @jeremy-coulon

eyuksekkolasin avatar Oct 28 '24 09:10 eyuksekkolasin

Hi, this looks like a bug, I'll have a look at it, this week.

matus-chochlik avatar Oct 28 '24 17:10 matus-chochlik

Thanks a lot..

eyuksekkolasin avatar Oct 30 '24 05:10 eyuksekkolasin