hedronvision / bazel-compile-commands-extractor

Goal: Enable awesome tooling for Bazel users of the C language family.
Other
696 stars 112 forks source link

Add pre-processed header support. #209

Open helly25 opened 3 months ago

helly25 commented 3 months ago

This is a expanded version of https://github.com/hedronvision/bazel-compile-commands-extractor/pull/205

It adds more header file extensions.

This fixes: https://github.com/hedronvision/bazel-compile-commands-extractor/issues/199

mikael-s-persson commented 2 months ago

I just tried to use this patch, and it failed on one of my dependencies (mcap library) that has some .inl headers. That is a fairly common header('ish) extension too.

I'd suggest adding .inl to the list, I guess to the C list.

helly25 commented 2 months ago

I just tried to use this patch, and it failed on one of my dependencies (mcap library) that has some .inl headers. That is a fairly common header('ish) extension too.

I'd suggest adding .inl to the list, I guess to the C list.

I have added '.inl' as possible c source. However, there is an issue with those as they are typically not meant as stand alone sources. Nonetheless, the tool should just gracefully warn on failure.

Imo it would be better to provide good defaults an customization, so the '.inl' could be optional. One way to allow customization is https://github.com/helly25/bazel-compile-commands-extractor/tree/custom-control-args another would be to use actual config files.

mikael-s-persson commented 2 months ago

I've noticed a couple of remaining issues with this. Example of a short excerpt of output:

....
clang: error: no such file or directory: 'bazel-out/k8-opt-exec-ST-d57f47055a04/bin/external/abseil-cpp~/absl/container/_objs/flat_hash_map/flat_hash_map.h.processed'
clang: warning: argument unused during compilation: '-fsyntax-only' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-fsyntax-only' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-fsyntax-only' [-Wunused-command-line-argument]
clang: error: no such file or directory: 'bazel-out/k8-opt-exec-ST-d57f47055a04/bin/external/abseil-cpp~/absl/time/_objs/time/civil_time.h.processed'
clang: error: no such file or directory: 'bazel-out/k8-opt-exec-ST-d57f47055a04/bin/external/abseil-cpp~/absl/time/_objs/time/clock.h.processed'
clang: error: no such file or directory: 'bazel-out/k8-opt-exec-ST-d57f47055a04/bin/external/abseil-cpp~/absl/time/_objs/time/time.h.processed'
clang: error: no such file or directory: 'bazel-out/k8-dbg/bin/external/abseil-cpp~/absl/container/_objs/flat_hash_map/flat_hash_map.h.processed'
....

The first issue is that the "-fsyntax-only" argument should be filtered out of the compilation arguments. I'm not familiar enough to know where exactly to do that but it seems like that should be trivial. This issue is not making it fail, but just creates a lot of noise in the output.

The second issue appears to me to be some sort of a race-condition on the ".processed" files. When re-running the generation again, the problem goes away, i.e., maybe the dependency on those output files is not getting properly registered/declared so that a more-or-less fresh run causes commands that expect those files to exist to be run before those files have been generated / sym-linked. Again, I don't know exactly how to fix that.