hedronvision / bazel-compile-commands-extractor

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

Relevant arguments are lost by the `bazel aquery ...` portion of compile command generation #170

Open btalb opened 9 months ago

btalb commented 9 months ago

I've had a setup evolve so that it is now using a bazelrc in a custom location (i.e. bazel --bazelrc=/path/to/.bazelrc ... is now how all of my commands are run).

The bazel aquery ... portion of the compile command generation is a raw call that doesn't receive any of the arguments forwarded to it. Some simple examples:

It leaves me in a situation where my project builds perfectly fine, but I can't generate commands because the logic is in a non-standard bazelrc location or passed via the bazel run ... command itself.

I've:

Any ideas?

btalb commented 9 months ago

I've just seen the -- args workaround, which functionally does the job.

It still doesn't work for --bazelrc as it treats it as a command arg rather than startup option (i.e. before the aquery command).

I guess this is more a feature request then:

cpsauer commented 9 months ago

Hey, thanks for raising this, Ben.

I really wish we could pull the args from Bazel, but I don't know of a way. (Won't bazel help return the options from its invocation, which wouldn't automatically include the additional options)

Some workaround-ish ideas:

Chris

btalb commented 9 months ago

Thanks @cpsauer ; I had a feeling this may be the result.

I've got a gnarly workaround where I've wrapped my bazel invocations in scripts that pull args out of the bazelrc and directly pass them in as -- args which does the job.

The only suggestion I've got which is feasible but tedious, would be to evaluate the provided -- args against bazel help startup_options, and put those that match before the aquery part of the command in: https://github.com/hedronvision/bazel-compile-commands-extractor/blob/33658bab23a4858b513d767480b43d3d8fb6a3d1/refresh.template.py#L1208-L1212 That's probably just putting lipstick on a pig / complicating your project, so I'm not sure if it would be the type of thing you'd want to add.

cpsauer commented 9 months ago

Oh darn. I see. (Sorry for misunderstanding the `bazel help startup_options part and the startup positional restriction.)

Sorta open to it if there's not a better way, but I think it'll be a bit tricky to get right with args?

Just to make sure there aren't better ways given Bazel's functionality

btalb commented 9 months ago

I'm probably getting towards the nit-picky territory, but neither quite meet my needs:

Anyway, I'm happy for this to be closed as won't do given it's a bit boutique. Just thought I'd raise it in case I was missing something obvious :slightly_smiling_face:

cpsauer commented 9 months ago

I probably can't do given some severe time constraints over here--but I'd be open to a PR if you're down to do it well. (Up to you, close if no.) Sorry to not have a magic bullet up my sleeve for ya here. I really wish also that bazel handled some things differently here: accepting the args in any location and offering a way to introspect its args within bazel run. Maybe we should be filing an issue asking them for that? [I think I'm still not fully understanding why the gnarly wrapper script beats these alternatives--but maybe that's ok.]

Cheers, Chris