hedronvision / bazel-compile-commands-extractor

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

Select usage example for refresh_compile_commands #186

Open dambrosio opened 4 months ago

dambrosio commented 4 months ago

Creating a ticket based on a recent comment in a past closed ticket.

Was wondering if there is example usage for refresh_compile_commands with a targets select. As stated in the mentioned comment, I am a Bazel n00b so it might not be possible.

Fundamentally I am looking for a way to pass an argument (target package) to the root refresh_compile_commands.

Something like:

# BUILD

config_setting(
    name = "refresh_comp_cmds_target",
    values = {"define": "target="},
)

refresh_compile_commands(
    name = "refresh_comp_cmds",
    targets = select({
        ":refresh_comp_cmds_target": {"$(target)": ""},
        "//condition:default": {"//...": ""},
    }),
)

With command line usage of: bazel run :refresh_comp_cmds --define target=//my_pkg:my_target.

When I try the above I run into the following error:

ERROR: Traceback (most recent call last):
        File "/.../BUILD", line 21, column 25, in <toplevel>
                refresh_compile_commands(
        File "/.../external/hedron_compile_commands/refresh_compile_commands.bzl", line 82, column 37, in refresh_compile_commands
                for target, flags in targets.items()
Error: 'select' value has no field or method 'items'

Please let me know if moving the comment to a ticket was acceptable.

Appreciate the help and cheers!

neko-para commented 2 months ago

I've encountered a similar situation. My target doesn't recognize the passed config and failed for missing matching condition.


@dambrosio It's my problem. According to document, there should be an extra -- before argument for target.

bazel run :refresh_comp_cmds -- --define target=//my_pkg:my_target
                             ^