如何从一个方面获取 cc_* 的所有 header 依赖项?

How to get all header dependencies of a cc_* from an aspect?

我有一个 Bazel 方面应该做 C/C++ 代码分析。当 运行 进行分析时,我需要所有 headers,与编译时相同。我已经为分析工具提供了它需要的所有标志,但是 运行 分析所需的文件不在沙箱中。

我需要几套headers:

我可以得到在cc_*规则中声明的srcs和hdrs headers,我以后可能可以自己弄清楚deps和implementation_deps,但是我如何得到工具链headers?

查看 bazel-bin 我看到 .d-files,列表 headers 及其路径。但我不知道如何从方面掌握它。或者如果我这样做了怎么办。


这个问题是 follow-up

我找到了一个解决方案,使用 cc_toolchain all_files 字段。在方面实现中:

cc_toolchain = find_cpp_toolchain(ctx.rule)
compiler_headers = cc_toolchain.all_files.to_list()

将 compiler_headers 过滤为编译器 headers 可能更可取。

至于其他的headers,在切面目标CcInfo中找到:

target[CcInfo].compilation_context.headers