Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No source files found in compile args error #199

Open
davidzchen opened this issue Jun 13, 2024 · 18 comments · May be fixed by #209 or #219
Open

No source files found in compile args error #199

davidzchen opened this issue Jun 13, 2024 · 18 comments · May be fixed by #209 or #219

Comments

@davidzchen
Copy link

I recently started getting a No source files found in compile args error while running refresh_compile_commands. The error message told me to file an issue for this.

Repository is here: https://github.com/davidzchen/bazel-ycm-test

bazel run :refresh_compile_commands
WARNING: Build options --cxxopt, --features, and --host_features have changed, discarding analysis cache (this can be expensive, see https://bazel.build/advanced/performance/iteration-speed).
INFO: Analyzed target //:refresh_compile_commands (0 packages loaded, 3077 targets configured).
INFO: Found 1 target...
Target //:refresh_compile_commands up-to-date:
  bazel-bin/refresh_compile_commands
  bazel-bin/refresh_compile_commands.check_python_version.py
  bazel-bin/refresh_compile_commands.py
INFO: Elapsed time: 0.252s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/refresh_compile_commands
>>> Analyzing commands used in //...
WARNING: Build options --cxxopt, --features, and --host_features have changed, discarding analysis cache (this can be expensive, see https://bazel.build/advanced/performance/iteration-speed).
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_dzc/ca3f78bcbc408bb12abbe25f7a083ec0/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/refresh_compile_commands.runfiles/_main/refresh_compile_commands.check_python_version.py", line 15, in <module>
    refresh_compile_commands.main()
  File "/private/var/tmp/_bazel_dzc/ca3f78bcbc408bb12abbe25f7a083ec0/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/refresh_compile_commands.runfiles/_main/refresh_compile_commands.py", line 1422, in main
    compile_command_entries.extend(_get_commands(target, flags))
  File "/private/var/tmp/_bazel_dzc/ca3f78bcbc408bb12abbe25f7a083ec0/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/refresh_compile_commands.runfiles/_main/refresh_compile_commands.py", line 1284, in _get_commands
    yield from _convert_compile_commands(parsed_aquery_output)
  File "/private/var/tmp/_bazel_dzc/ca3f78bcbc408bb12abbe25f7a083ec0/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/refresh_compile_commands.runfiles/_main/refresh_compile_commands.py", line 1164, in _convert_compile_commands
    for source_files, header_files, compile_command_args in outputs:
  File "/private/var/tmp/_bazel_dzc/ca3f78bcbc408bb12abbe25f7a083ec0/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_dzc/ca3f78bcbc408bb12abbe25f7a083ec0/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_dzc/ca3f78bcbc408bb12abbe25f7a083ec0/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_dzc/ca3f78bcbc408bb12abbe25f7a083ec0/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_dzc/ca3f78bcbc408bb12abbe25f7a083ec0/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_dzc/ca3f78bcbc408bb12abbe25f7a083ec0/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/refresh_compile_commands.runfiles/_main/refresh_compile_commands.py", line 1128, in _get_cpp_command_for_files
    source_files, header_files = _get_files(compile_action)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/_bazel_dzc/ca3f78bcbc408bb12abbe25f7a083ec0/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/refresh_compile_commands.runfiles/_main/refresh_compile_commands.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/abseil-cpp~/absl/strings/_objs/strings/ascii.h.d', '-iquote', 'external/abseil-cpp~', '-iquote', 'bazel-out/darwin_arm64-fastbuild/bin/external/abseil-cpp~', '-mmacosx-version-min=14.4', '-std=c++20', '-Wall', '-Wextra', '-Wcast-qual', '-Wconversion', '-Wfloat-overflow-conversion', '-Wfloat-zero-conversion', '-Wfor-loop-analysis', '-Wformat-security', '-Wgnu-redeclared-enum', '-Winfinite-recursion', '-Winvalid-constexpr', '-Wliteral-conversion', '-Wmissing-declarations', '-Woverlength-strings', '-Wpointer-arith', '-Wself-assign', '-Wshadow-all', '-Wshorten-64-to-32', '-Wsign-conversion', '-Wstring-conversion', '-Wtautological-overlap-compare', '-Wtautological-unsigned-zero-compare', '-Wundef', '-Wuninitialized', '-Wunreachable-code', '-Wunused-comparison', '-Wunused-local-typedefs', '-Wunused-result', '-Wvla', '-Wwrite-strings', '-Wno-float-conversion', '-Wno-implicit-float-conversion', '-Wno-implicit-int-float-conversion', '-Wno-unknown-warning-option', '-DNOMINMAX', '-no-canonical-prefixes', '-Wno-builtin-macro-redefined', '-D__DATE__="redacted"', '-D__TIMESTAMP__="redacted"', '-D__TIME__="redacted"', '-c', 'external/abseil-cpp~/absl/strings/ascii.h', '-o', 'bazel-out/darwin_arm64-fastbuild/bin/external/abseil-cpp~/absl/strings/_objs/strings/ascii.h.processed'].
Please file an issue with this information!

System Info

OS: macOS 14.4.1 Sonoma

Bazel/Bazelisk version:

$ bazel version
Bazelisk version: 1.20.0
Build label: 7.2.0
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Mon Jun 10 13:04:55 2024 (1718024695)
Build timestamp: 1718024695
Build timestamp as int: 1718024695

Python version:

$ python3 --version
Python 3.12.3
@xiedeacc
Copy link

same error

@ehuang3
Copy link

ehuang3 commented Jun 16, 2024

I also have this issue. The logic in _get_files(compile_action) does not seem to support a header only compile command. There are no source files because the command is attempting to precompile a header file.

@ehuang3
Copy link

ehuang3 commented Jun 16, 2024

diff --git a/refresh.template.py b/refresh.template.py
index 3b33701..acc5f90 100644
--- a/refresh.template.py
+++ b/refresh.template.py
@@ -615,6 +615,11 @@ def _get_files(compile_action):
 
     # Getting the source file is a little trickier than it might seem.
 
+    is_precompiled_header = any([arg == "-xc++-header" for arg in compile_action.arguments])
+    if is_precompiled_header:
+        header_files = [arg for arg in compile_action.arguments if not arg.startswith('-') and arg.endswith(".h")]
+        return set(), set(header_files)
+
     # First, we do the obvious thing: Filter args to those that look like source files.
     source_file_candidates = [arg for arg in compile_action.arguments if not arg.startswith('-') and arg.endswith(_get_files.source_extensions)]
     assert source_file_candidates, f"No source files found in compile args: {compile_action.arguments}.\nPlease file an issue with this information!"

This patch works for me.

@davidzchen
Copy link
Author

That's odd. I had cc_library targets that only had headers in the past, and the tool ran just fine. Something caused this error to come up recently, but I do not know what changed on my system, aside from maybe Bazel getting updated (I am using bazelisk but I don't have Bazel pinned to a specific version in my repo).

davidzchen added a commit to davidzchen/bazel-compile-commands-extractor that referenced this issue Jun 16, 2024
@davidzchen
Copy link
Author

In any case, this patched worked for me as well. @ehuang3 can you open a PR?

agegechkori added a commit to agegechkori/bazel-compile-commands-extractor that referenced this issue Jun 24, 2024
@tolikzinovyev
Copy link

I started having the same problem in my project. The error also triggers on abseil's header file. I created a small repository so that reproducing is easier. https://github.com/tolikzinovyev/hedron-fail

Arch Linux, Bazel 7.2.0

@xiedeacc
Copy link

I started having the same problem in my project. The error also triggers on abseil's header file. I created a small repository so that reproducing is easier. https://github.com/tolikzinovyev/hedron-fail

Arch Linux, Bazel 7.2.0
use
https://github.com/xiedeacc/bazel-compile-commands-extractor

@davidzchen
Copy link
Author

Can someone please open a PR for this?

@cpsauer
Copy link
Contributor

cpsauer commented Jun 29, 2024

Hey guys--I'm seeing this and will engage with it shortly, aiming for this weekend. Sorry to be only getting to this now; I've been underwater with other things.

Seems like bazel added a new type of header-only compile action, when formerly they only issued them for source files. I think the first step is to understand what's going on in those actions to make sure there aren't other problems and figure out if there's another way to distinguish them (in case the problem happens also with, e.g. c (not c++) headers, breaking the solution above).

Awesome to have a minimal reproduction case and know the Bazel version that broke it--thanks guys.

If anyone is willing to help in the meantime, I think the next steps would be

  1. Try to dig up the context behind this Bazel change.
  2. Make sure it's still happening in Bazel rolling, if we can't find that context.
  3. Look at the aquery output for those actions to try to understand them better.

@rockwotj
Copy link

rockwotj commented Aug 1, 2024

Likely Related PR: bazelbuild/bazel#22369

@rockwotj
Copy link

rockwotj commented Aug 1, 2024

I've also confirmed this still happens in Bazel rolling at least for abseil in my repo

andrenbrandao added a commit to andrenbrandao/bazel-cpp-boilerplate that referenced this issue Aug 3, 2024
Had to downgrade Bazel to 7.1.2 because it was crashing when building
abseil.
See issue: hedronvision/bazel-compile-commands-extractor#199
@helly25
Copy link

helly25 commented Aug 18, 2024

I ran into the same issue on one of my repos. And got it working with #209

The problem is that the source file a header (.h) cannot be found as it is not in the list of source files. There is a PR out that addresses the exact combination: #205

That one also adds support for .h.processed as a target.

However, it does not support all header extension variants ('.hh', '.hpp', '.hxx' and whatnot). So it might be necessary to adding them all and to only use .processed as additional target extension.

@helly25 helly25 linked a pull request Aug 18, 2024 that will close this issue
@rockwotj
Copy link

@fmeum sorry to pull you into this, but I believe that bazelbuild/bazel#22369 caused this (because downgrading to Bazel 7.1.0 makes this error go away). Do you know the details of the purpose of the .processed headers are for? Since they are new in 7.2.0, I presume it's safe for a compilation database to just skip adding compilation commands for clangd for these .processed headers. Thanks!

@fmeum
Copy link

fmeum commented Aug 20, 2024

The .processed file is just a synthetic output file that's always empty: Bazel can't run actions that produce no outputs, so the way we get it to run on headers is to wrap the compiler with a script that produces this empty file.

While the file itself isn't interesting, the action very well could be. For a header-only library with no consumers, it does provide flags with which the library at least parses correctly. That makes an approach such as #209 look reasonable to me.

I am working on adding a new action that supports C headers (via -xc-header), but this hasn't been merged yet.

@helly25
Copy link

helly25 commented Aug 20, 2024

Thanks for confirming @fmeum. The header only libraries get their own entries this way. Which imo is a clear improvement.

@andreiavrammsd
Copy link

I have this issue if I use boost.move:

MODULE.bazel

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

BUILD

cc_library(
    name = "lib",
    hdrs = [
        "include/lib.hpp",
    ],
    includes = ["include"],
    visibility = ["//visibility:public"],
    deps = [
        "@boost.move",
    ],
)

bazel-compile-commands-extractor commit:

1e08f8e0507b6b6b1f4416a9a22cf5c28beaba93

Error

Traceback (most recent call last):
  File "/home/user/.cache/bazel/_bazel_user/eab0d61a99b6696edb3d2aff87b585e8/execroot/_main/bazel-out/k8-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 "/home/user/.cache/bazel/_bazel_user/eab0d61a99b6696edb3d2aff87b585e8/execroot/_main/bazel-out/k8-fastbuild/bin/external/hedron_compile_commands~/refresh_all.py", line 1417, in main
    compile_command_entries.extend(_get_commands(target, flags))
  File "/home/user/.cache/bazel/_bazel_user/eab0d61a99b6696edb3d2aff87b585e8/execroot/_main/bazel-out/k8-fastbuild/bin/external/hedron_compile_commands~/refresh_all.py", line 1279, in _get_commands
    yield from _convert_compile_commands(parsed_aquery_output)
  File "/home/user/.cache/bazel/_bazel_user/eab0d61a99b6696edb3d2aff87b585e8/execroot/_main/bazel-out/k8-fastbuild/bin/external/hedron_compile_commands~/refresh_all.py", line 1159, in _convert_compile_commands
    for source_files, header_files, compile_command_args in outputs:
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 621, in result_iterator
    yield _result_or_cancel(fs.pop())
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 319, in _result_or_cancel
    return fut.result(timeout)
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/user/.cache/bazel/_bazel_user/eab0d61a99b6696edb3d2aff87b585e8/execroot/_main/bazel-out/k8-fastbuild/bin/external/hedron_compile_commands~/refresh_all.py", line 1123, in _get_cpp_command_for_files
    source_files, header_files = _get_files(compile_action)
  File "/home/user/.cache/bazel/_bazel_user/eab0d61a99b6696edb3d2aff87b585e8/execroot/_main/bazel-out/k8-fastbuild/bin/external/hedron_compile_commands~/refresh_all.py", line 627, 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', '-g', '-std=c++14', '-MD', '-MF', 'bazel-out/k8-dbg/bin/external/boost.move~/_objs/boost.move/adl_move_swap.h.d', '-iquote', 'external/boost.move~', '-iquote', 'bazel-out/k8-dbg/bin/external/boost.move~', '-iquote', 'external/boost.config~', '-iquote', 'bazel-out/k8-dbg/bin/external/boost.config~', '-isystem', 'external/boost.move~/include', '-isystem', 'bazel-out/k8-dbg/bin/external/boost.move~/include', '-isystem', 'external/boost.config~/include', '-isystem', 'bazel-out/k8-dbg/bin/external/boost.config~/include', '-g', '-O0', '-no-canonical-prefixes', '-Wno-builtin-macro-redefined', '-D__DATE__="redacted"', '-D__TIMESTAMP__="redacted"', '-D__TIME__="redacted"', '-c', 'external/boost.move~/include/boost/move/adl_move_swap.hpp', '-o', 'bazel-out/k8-dbg/bin/external/boost.move~/_objs/boost.move/adl_move_swap.h.processed'].
Please file an issue with this information!

@mikael-s-persson mikael-s-persson linked a pull request Sep 18, 2024 that will close this issue
@mikael-s-persson
Copy link

I've been using the following patch for this issue: #219
That's been working pretty well for us.

@andreiavrammsd
Copy link

I've been using the following patch for this issue: #219 That's been working pretty well for us.

I confirm it works in my case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
10 participants