hedronvision / bazel-compile-commands-extractor

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

Error when running `bazel run @hedron_compile_commands//:refresh_all` #228

Open rohansatapathy opened 2 weeks ago

rohansatapathy commented 2 weeks ago

I'm trying to get clangd to recognize my Bazel dependencies, and I got an error when using this tool. I think the issue might be related to the fact that one of my dependencies Boost.Asio is header-only, so there's no .cpp file to compile it with, but I'm not 100% sure. I'm on macOS Sonoma 14.0, using clang, clangd, LLVM, and Bazelisk installed through Homebrew.

Project structure:

.
├── MODULE.bazel
├── MODULE.bazel.lock
├── external -> bazel-out/../../../external
└── src
    ├── BUILD
    └── main.cpp

MODULE.bazel:

# Hedron's Compile Commands Extractor for Bazel
# https://github.com/hedronvision/bazel-compile-commands-extractor
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
git_override(
    module_name = "hedron_compile_commands",
    remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
    commit = "4f28899228fb3ad0126897876f147ca15026151e",
)

bazel_dep(
    name = "boost.asio",
    version = "1.83.0",
)

src/BUILD:

cc_binary(
    name = "btp",
    srcs = ["main.cpp"],
    deps = [
        "@boost.asio"
    ]
)

src/main.cpp:

#include <boost/asio.hpp>
#include <iostream>

int main() {
    std::cout << "Hello, world!" << std::endl;
}

Error message:

❯ bazel run @hedron_compile_commands//:refresh_all
Starting local Bazel server and connecting to it...
INFO: Analyzed target @@hedron_compile_commands~//:refresh_all (99 packages loaded, 3242 targets configured).
INFO: Found 1 target...
Target @@hedron_compile_commands~//:refresh_all up-to-date:
  bazel-bin/external/hedron_compile_commands~/refresh_all
  bazel-bin/external/hedron_compile_commands~/refresh_all.check_python_version.py
  bazel-bin/external/hedron_compile_commands~/refresh_all.py
INFO: Elapsed time: 8.085s, Critical Path: 0.57s
INFO: 13 processes: 11 internal, 2 darwin-sandbox.
INFO: Build completed successfully, 13 total actions
INFO: Running command line: bazel-bin/external/hedron_compile_commands~/refresh_all
>>> Automatically added //external workspace link:
    This link makes it easy for you--and for build tooling--to see the external dependencies you bring in. It also makes your source tree have the same directory structure as the build sandbox.
    It's a win/win: It's easier for you to browse the code you use, and it eliminates whole categories of edge cases for build tooling.
>>> Analyzing commands used in @//...
WARNING: Build options --features and --host_features have changed, discarding analysis cache (this can be expensive, see https://bazel.build/advanced/performance/iteration-speed).
>>> A source file you compile doesn't (yet) exist: bazel-out/darwin_arm64-fastbuild/bin/external/boost.asio~/boost.asio.src.cpp
    It's probably a generated file, and you haven't yet run a build to generate it.
    That's OK; your code doesn't even have to compile for this tool to work.
    If you can, though, you might want to run a build of your code with --keep_going.
        That way everything possible is generated, browsable and indexed for autocomplete.
    However, if you have *already* built your code, and generated the missing file...
        Please make sure you're supplying this tool with the same flags you use to build.
        You can either use a refresh_compile_commands rule or the special -- syntax. Please see the README.
        [Supplying flags normally won't work. That just causes this tool to be built with those flags.]
    Continuing gracefully...
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_rohansatapathy/8ef8466f9ff240a4ad7ad21906dbbed7/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/external/hedron_compile_commands~/refresh_all.runfiles/_main/../hedron_compile_commands~/refresh_all.check_python_version.py", line 15, in <module>
    refresh_all.main()
  File "/private/var/tmp/_bazel_rohansatapathy/8ef8466f9ff240a4ad7ad21906dbbed7/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/external/hedron_compile_commands~/refresh_all.runfiles/hedron_compile_commands~/refresh_all.py", line 1416, in main
    compile_command_entries.extend(_get_commands(target, flags))
  File "/private/var/tmp/_bazel_rohansatapathy/8ef8466f9ff240a4ad7ad21906dbbed7/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/external/hedron_compile_commands~/refresh_all.runfiles/hedron_compile_commands~/refresh_all.py", line 1278, in _get_commands
    yield from _convert_compile_commands(parsed_aquery_output)
  File "/private/var/tmp/_bazel_rohansatapathy/8ef8466f9ff240a4ad7ad21906dbbed7/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/external/hedron_compile_commands~/refresh_all.runfiles/hedron_compile_commands~/refresh_all.py", line 1158, in _convert_compile_commands
    for source_files, header_files, compile_command_args in outputs:
  File "/private/var/tmp/_bazel_rohansatapathy/8ef8466f9ff240a4ad7ad21906dbbed7/external/rules_python~~python~python_3_11_aarch64-apple-darwin/lib/python3.11/concurrent/futures/_base.py", line 619, in result_iterator
    yield _result_or_cancel(fs.pop())
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/_bazel_rohansatapathy/8ef8466f9ff240a4ad7ad21906dbbed7/external/rules_python~~python~python_3_11_aarch64-apple-darwin/lib/python3.11/concurrent/futures/_base.py", line 317, in _result_or_cancel
    return fut.result(timeout)
           ^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/_bazel_rohansatapathy/8ef8466f9ff240a4ad7ad21906dbbed7/external/rules_python~~python~python_3_11_aarch64-apple-darwin/lib/python3.11/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/_bazel_rohansatapathy/8ef8466f9ff240a4ad7ad21906dbbed7/external/rules_python~~python~python_3_11_aarch64-apple-darwin/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/private/var/tmp/_bazel_rohansatapathy/8ef8466f9ff240a4ad7ad21906dbbed7/external/rules_python~~python~python_3_11_aarch64-apple-darwin/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/_bazel_rohansatapathy/8ef8466f9ff240a4ad7ad21906dbbed7/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/external/hedron_compile_commands~/refresh_all.runfiles/hedron_compile_commands~/refresh_all.py", line 1122, in _get_cpp_command_for_files
    source_files, header_files = _get_files(compile_action)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/_bazel_rohansatapathy/8ef8466f9ff240a4ad7ad21906dbbed7/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/external/hedron_compile_commands~/refresh_all.runfiles/hedron_compile_commands~/refresh_all.py", line 626, in _get_files
    assert source_file_candidates, f"No source files found in compile args: {compile_action.arguments}.\nPlease file an issue with this information!"
           ^^^^^^^^^^^^^^^^^^^^^^
AssertionError: No source files found in compile args: ['external/bazel_tools~cc_configure_extension~local_config_cc/cc_wrapper.sh', '-xc++-header', '-fsyntax-only', '-U_FORTIFY_SOURCE', '-fstack-protector', '-Wall', '-Wthread-safety', '-Wself-assign', '-Wunused-but-set-parameter', '-Wno-free-nonheap-object', '-fcolor-diagnostics', '-fno-omit-frame-pointer', '-std=c++14', '-MD', '-MF', 'bazel-out/darwin_arm64-fastbuild/bin/external/boost.smart_ptr~/_objs/boost.smart_ptr/atomic_count.h.d', '-iquote', 'external/boost.smart_ptr~', '-iquote', 'bazel-out/darwin_arm64-fastbuild/bin/external/boost.smart_ptr~', '-iquote', 'external/boost.assert~', '-iquote', 'bazel-out/darwin_arm64-fastbuild/bin/external/boost.assert~', '-iquote', 'external/boost.config~', '-iquote', 'bazel-out/darwin_arm64-fastbuild/bin/external/boost.config~', '-iquote', 'external/boost.core~', '-iquote', 'bazel-out/darwin_arm64-fastbuild/bin/external/boost.core~', '-iquote', 'external/boost.static_assert~', '-iquote', 'bazel-out/darwin_arm64-fastbuild/bin/external/boost.static_assert~', '-iquote', 'external/boost.throw_exception~', '-iquote', 'bazel-out/darwin_arm64-fastbuild/bin/external/boost.throw_exception~', '-iquote', 'external/boost.move~', '-iquote', 'bazel-out/darwin_arm64-fastbuild/bin/external/boost.move~', '-iquote', 'external/boost.type_traits~', '-iquote', 'bazel-out/darwin_arm64-fastbuild/bin/external/boost.type_traits~', '-isystem', 'external/boost.smart_ptr~/include', '-isystem', 'bazel-out/darwin_arm64-fastbuild/bin/external/boost.smart_ptr~/include', '-isystem', 'external/boost.assert~/include', '-isystem', 'bazel-out/darwin_arm64-fastbuild/bin/external/boost.assert~/include', '-isystem', 'external/boost.config~/include', '-isystem', 'bazel-out/darwin_arm64-fastbuild/bin/external/boost.config~/include', '-isystem', 'external/boost.core~/include', '-isystem', 'bazel-out/darwin_arm64-fastbuild/bin/external/boost.core~/include', '-isystem', 'external/boost.static_assert~/include', '-isystem', 'bazel-out/darwin_arm64-fastbuild/bin/external/boost.static_assert~/include', '-isystem', 'external/boost.throw_exception~/include', '-isystem', 'bazel-out/darwin_arm64-fastbuild/bin/external/boost.throw_exception~/include', '-isystem', 'external/boost.move~/include', '-isystem', 'bazel-out/darwin_arm64-fastbuild/bin/external/boost.move~/include', '-isystem', 'external/boost.type_traits~/include', '-isystem', 'bazel-out/darwin_arm64-fastbuild/bin/external/boost.type_traits~/include', '-mmacosx-version-min=14.5', '-std=c++14', '-Wall', '-Werror', '-Wpedantic', '-Wextra', '-no-canonical-prefixes', '-Wno-builtin-macro-redefined', '-D__DATE__="redacted"', '-D__TIMESTAMP__="redacted"', '-D__TIME__="redacted"', '-c', 'external/boost.smart_ptr~/include/boost/detail/atomic_count.hpp', '-o', 'bazel-out/darwin_arm64-fastbuild/bin/external/boost.smart_ptr~/_objs/boost.smart_ptr/atomic_count.h.processed'].
Please file an issue with this information!
ftiasch commented 1 day ago

+1 to this. I encountered the same issue building against @boost.property_tree.

Yuki-cpp commented 1 day ago

This looks like #199. You can use #219 for a fix while waiting for it to be merged