bazel-compile-commands-extractor icon indicating copy to clipboard operation
bazel-compile-commands-extractor copied to clipboard

Support custom output configurations

Open chadnorvell opened this issue 1 year ago • 8 comments

This change adds two main features:

  1. You can configure compile commands for certain targets or groups of targets to go into separate files

For embedded systems development in particular, clangd doesn't work well with compile_commands.json generated for multiple targets. For example, if you have a build target that runs on your host machine in one configuration and another that runs on device in another configuration, compile_commands.json will contain multiple conflicting compile commands for the same source files. clangd will just use the first one it finds, which may not be the one you want to use for code intelligence. It's convenient to have separate compile commands files for each target, and switch the file clangd uses depending on how you want to navigate your code.

By providing the target_collections argument, you can associate targets with named collections. Separate compile commands files will be generated for each of the specified collections, and will be placed in subdirectories with the specified names. This is most useful when you associate multiple targets with a collection, for example, to configure code intelligence to use the compile commands for all of the targets that build for one architecture or device.

This means that you can now specify a target more than once, generating compile commands for builds of the same target but with different flags (e.g. --platform). Before, you implicitly could only specify each target once since the targets were dict keys.

  1. You can specify a different output path

If you are generating multiple compile commands files, its preferable not to output them into the workspace root. So you can specify a separate output path, relative to the workspace root.

This patch doesn't change any existing behavior; if you don't add either of the new arguments to your invocation of refresh_compile_commands, everything will work exactly as it did before.

chadnorvell avatar Jun 26 '24 22:06 chadnorvell