0

I have a Bazel aspect that is supposed to do C/C++ code analysis. When running the analysis I need all headers, same as when compiling. I've gotten so far as to feed the analysis tooling all the flags it needs, but the files it needs to run the analysis are not in the sandbox.

There are several sets of headers that I need:

  • srcs
  • hdrs
  • deps
  • implementation_deps
  • toolchain

I can get the srcs and hdrs headers declared in the cc_* rule, and I can probably figure out deps and implementation_deps myself later, but how do I get the toolchain headers?

Looking into bazel-bin I see the .d-files, listing headers and their paths. But I don't know how to get hold of that from the aspect. Or what to do with it if I do.


This question is a follow-up on How to integrate C/C++ analysis tooling in Bazel?

1 Answer 1

0

I found a solution, using the cc_toolchain all_files field. In the aspect implementation:

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

Filtering the compiler_headers into being just the compiler headers probably preferable.

As for the other headers, they are found in the aspect target CcInfo:

target[CcInfo].compilation_context.headers

Not the answer you're looking for? Browse other questions tagged or ask your own question.