hedronvision / bazel-compile-commands-extractor

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

Missing headers when consumed by iwyu.sh #216

Closed sthornington closed 2 months ago

sthornington commented 2 months ago

Hi folks!

This is a vague issue to be sure, but has anyone had an issue with the compile_commands.json resulting from this rule causing iwyu.sh to fail to find issues in .hpp files?

I plan to dig into this more next week, but if anyone else is using the hedronvision rule as an input to iwyu.sh without any coverage gaps (or with) I'm curious to hear if there were any changes or flags you needed to specify.

Thanks!

sthornington commented 2 months ago

I guess another minor related question - when hedron picks a cpp file to use as bait, when producing a rule for a header file, it does at least pick a cpp file which includes that header, right…?

cpsauer commented 2 months ago

Hey Simon! Great to meet you--and thanks for working with this tool

The command listed for the header is indeed one that's actually used to compile the header; that is, the cpp file includes that header (potentially transitively). If you want to see where this happens in the code, _get_headers in refresh.template.py is your man.

I haven't used iqyu.sh personally, unfortunately, so I don't have comparative advantage there (sorry!) but if it chokes on headers, I want to make sure you know about the header-search exclusion options, at least to track down the issue? They Ideally they'd be robust to this, though, since needing to enrich the compilation database with headers is a a broader thing than this tool.

Happy coding! Chris

sthornington commented 2 months ago

Hi yeah thanks, I'll look into it a bit more next week. I'm happy enough to have gotten it working wel for clangd with our bazel wrapper situation using the changes in my PR #215 -- getting iwyu.sh working is a secondary concern and just as likely to be a bug in that tool.

sthornington commented 2 months ago

For anyone else that lands here, I fixed this issue by modifying our iwyu_tool.sh so that it passes -Xiwyu --check_also=... when building the Invocation. Specifically, I had to strip the <directory>/ from the <file> for all headers and pass that in. This causes iwyu to try to patch up that header, using the build command for the exemplar cpp file provided by the hedronvision compile_commands.json.

sthornington commented 2 months ago

workaround.