hedronvision / bazel-compile-commands-extractor

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

@hedron_compile_commands//:refresh_all failed #196

Closed FantasqueX closed 2 months ago

FantasqueX commented 2 months ago

When I executed bazelisk run @hedron_compile_commands//:refresh_all, I got

PrimaryInput: File:[C:/users/fantasquex/documents/develop/source/aqinfer[source]]test/test_allocator.cpp
PrimaryOutput: File:[[<execution_root>]bazel-out/x64_windows-fastbuild/bin]test/_objs/test_units/test_allocator.obj
Owner information: ConfiguredTargetKey{label=//test:test_units, config=BuildConfigurationKey[877c88e5133d151034292f0ca2d8d1aa4bb1c97e207d7cebe4dc9da88c9418a4]}, ConfiguredTargetKey{label=//test:test_units, config=BuildConfigurationKey[7416d744d215a3fd4cf0bdf037ced78486ab54d0a3c34094affe309ceedf5f57]}
MandatoryInputs: are equal
Outputs: are equal
ERROR: com.google.devtools.build.lib.actions.MutableActionGraph$ActionConflictException: for test/_objs/test_units/test_allocator.obj, previous action: action 'Compiling test/test_allocator.cpp', attempted action: action 'Compiling test/test_allocator.cpp'
Bazel aquery failed. Command: ['bazel', 'aquery', "mnemonic('(Objc|Cpp|Cuda)Compile',deps(@//...))", '--output=jsonproto', '--include_artifacts=false', '--ui_event_filters=-info', '--noshow_progress', '--features=-compiler_param_file', '--features=-layering_check', '--host_features=-compiler_param_file', '--host_features=-layering_check']
>>> Failed extracting commands for @//...
    Continuing gracefully...
>>> Not (over)writing compile_commands.json, since no commands were extracted and an empty file is of no use.
    There should be actionable warnings, above, that led to this.

I have no idea how to solve the problem. Any suggestion is welcome. My hedron_compile_commands is at a14ad3a64e7bf398ab48105aaa0348e032ac87f8

cpsauer commented 2 months ago

Hi @FantasqueX! Thanks for giving the tool a whirl, and I'm sorry about the error. That's definitely an opaque one.

This looks like some bazel internal issue (that's Bazel erroring out with the ActionConflictException)--and unfortunately not one I've seen before. Looks like Bazel's trying to generate two conflicting actions for building your test/test_allocator.cpp.

Here's what I'd recommend trying:

  1. Let's see how widespread this is. Could you try using a refresh_compile_commands target to specify just the top level target you most care about? How about if you specify that test? (Seems like Bazel should be handling this case, but this gets at whether it's bazel perhaps generating conflicting actions from different targets, since refresh_all tries to analyze all targets at once.)
  2. If that doesn't fix/surface things, would you be down to also try adding Bazelisk as bazel to your path ? This tool reinvokes Bazel inside itself, so there's some chance this is coming from two incompatible versions of bazel operating on the same cache or something.

Thanks! Chris

FantasqueX commented 2 months ago

Hi @FantasqueX! Thanks for giving the tool a whirl, and I'm sorry about the error. That's definitely an opaque one.

This looks like some bazel internal issue (that's Bazel erroring out with the ActionConflictException)--and unfortunately not one I've seen before. Looks like Bazel's trying to generate two conflicting actions for building your test/test_allocator.cpp.

Here's what I'd recommend trying:

  1. Let's see how widespread this is. Could you try using a refresh_compile_commands target to specify just the top level target you most care about? How about if you specify that test? (Seems like Bazel should be handling this case, but this gets at whether it's bazel perhaps generating conflicting actions from different targets, since refresh_all tries to analyze all targets at once.)
  2. If that doesn't fix/surface things, would you be down to also try adding Bazelisk as bazel to your path ? This tool reinvokes Bazel inside itself, so there's some chance this is coming from two incompatible versions of bazel operating on the same cache or something.

Thanks! Chris

Hi @cpsauer! Thanks for your advice. I've tried to add two refresh_compile_commands targets, the most interest one and test. Both of them are generated successfully. However, I don't know why the "all" target doesn't work. Maybe it's a Bazel bug :(

cpsauer commented 2 months ago

Great to hear the progress! Hopefully that unblocks you!

Any chance you'd be down to report the underlying problem to Bazel, too? (please cc me) To simplify, I think we could take this tool out of the equation by trying to see if it reproduces with a bazel build //...

(I'm guessing two targets (transitively) create that action, and then bazel fails to merge or distinguish them.)

FantasqueX commented 2 months ago

I figure out the problem. We use https://github.com/grailbio/bazel-compilation-database which adds a target in root package. The root package target needs "test". If I remove bazel-compilation-database, the problem disappears.

cpsauer commented 2 months ago

Oh, very interesting to know there's a clash. Thanks for reporting--I bet that'll help out a bunch of folks who run across this in the future!