hedronvision / bazel-compile-commands-extractor

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

Error when use with bazel --output_base flag #180

Open LittleCuteBug opened 5 months ago

LittleCuteBug commented 5 months ago

when run with bazel --output_base bazel-cache run @hedron_compile_commands//:refresh_all I got the following error, can anyone provide help?

ERROR: error loading package 'bazel-hello_world/external/bazel_tools/src/conditions': Every .bzl file must have a corresponding package, but '//tools/windows:windows_config.bzl' does not have one. Please create a BUILD file in the same or any parent directory. Note that this BUILD file does not need to do anything except exist.
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']
cpsauer commented 5 months ago

Hey @LittleCuteBug! Thanks for giving the tool a whirl. This is...a very strange one. Those are internal bazel tools failing to have been instantiated properly. Do things work properly if you remove the --output_base bazel-cache, add it to your bazelrc, or also pass it to our subcommands by appending -- --output_base bazel-cache (see the flag configuration section of the readme for more.)? I'm guessing the problem is that the tool is getting a different output base at runtime from compile time.

LittleCuteBug commented 5 months ago

Hi @cpsauer, I have also tried the .bazelrc and -- --output_base bazel-cache and still have the same error. Without the --output_base bazel-cache, the bazel run @hedron_compile_commands//:refresh_all works fine for me.

I'm guessing the problem is that the tool is getting a different output base at runtime from compile time.

Yes, I think that is the problem too.

LittleCuteBug commented 5 months ago

Hi @cpsauer, I think I found the reason, it's because I set the output_base inside the workspace, so the hedron_compile_commands tried to check in that directory also. Is there any way to exclude that directory?

cpsauer commented 5 months ago

Oh! interesting. Sounds like all works fine if the output_base is outside the workspace? If so, this really seems like a Bazel bug...and worth reporting to them. To help scope:

LittleCuteBug commented 5 months ago

yes, I have managed to work with the combination of startup --output_base=bazel-cache in the .bazelrc and bazel-cache in the .bazelignore file. A small interesting issue is the query command used in the hedron_compile_commands only takes effect of the .bazelrc when the hedron_compile_commands repo is imported by git_repository rule or local_repository rule. if I included it with http_archive, the .bazelrc config seems not to take effect.