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 · 9 comments
Open

No source files found in compile args error #199

davidzchen opened this issue Jun 13, 2024 · 9 comments

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.

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

No branches or pull requests

5 participants