Skip to content

Fix bazel refresh_compile_commands#3729

Merged
nycrat merged 2 commits into
masterfrom
avah/fix_compile_commands_workaround
May 22, 2026
Merged

Fix bazel refresh_compile_commands#3729
nycrat merged 2 commits into
masterfrom
avah/fix_compile_commands_workaround

Conversation

@nycrat
Copy link
Copy Markdown
Member

@nycrat nycrat commented May 21, 2026

Description

The bazel run //:refresh_compile_commands command is currently not working on MacOS due to a bug hedronvision/bazel-compile-commands-extractor#199 that doesn't allow targets with only header files. hedronvision/bazel-compile-commands-extractor#219 fixes that issue but has not been merged because of some stability reason for hedronvision's internal usage of the tool. So, this PR just changes the source of the hedron_compile_commands dependency in MODULE.bazel to a fork which contains the fix for this bug. NOTE: I have no idea why it is only an issue on MacOS; it seems like it should be an issue on Ubuntu as well.

LOGS BEFORE FIX:

❯ bazel run //:refresh_compile_commands
INFO: Invocation ID: 928cc7fd-2406-476a-9a3b-6dae020205e5
INFO: Analyzed target //:refresh_compile_commands (105 packages loaded, 1483 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.503s, Critical Path: 0.01s
INFO: 12 processes: 2 disk cache hit, 10 internal.
INFO: Build completed successfully, 12 total actions
INFO: Running command line: bazel-bin/refresh_compile_commands
>>> Analyzing commands used in //software/...
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: software/embedded/velocity_controller/pid_controller_test.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_avah/e8ab241f4ad621b3c5fd12a59f9a954c/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_avah/e8ab241f4ad621b3c5fd12a59f9a954c/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/refresh_compile_commands.runfiles/_main/refresh_compile_commands.py", line 1420, in main
    compile_command_entries.extend(_get_commands(target, flags))
  File "/private/var/tmp/_bazel_avah/e8ab241f4ad621b3c5fd12a59f9a954c/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/refresh_compile_commands.runfiles/_main/refresh_compile_commands.py", line 1279, in _get_commands
    yield from _convert_compile_commands(parsed_aquery_output)
  File "/private/var/tmp/_bazel_avah/e8ab241f4ad621b3c5fd12a59f9a954c/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/refresh_compile_commands.runfiles/_main/refresh_compile_commands.py", line 1159, in _convert_compile_commands
    for source_files, header_files, compile_command_args in outputs:
                                                            ^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.13/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/_base.py", line 619, in result_iterator
    yield _result_or_cancel(fs.pop())
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.13/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/_base.py", line 317, in _result_or_cancel
    return fut.result(timeout)
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.13/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.13/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/opt/homebrew/Cellar/python@3.12/3.12.13/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/_bazel_avah/e8ab241f4ad621b3c5fd12a59f9a954c/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/refresh_compile_commands.runfiles/_main/refresh_compile_commands.py", line 1123, in _get_cpp_command_for_files
    source_files, header_files = _get_files(compile_action)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/_bazel_avah/e8ab241f4ad621b3c5fd12a59f9a954c/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/refresh_compile_commands.runfiles/_main/refresh_compile_commands.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/rules_cc++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++17', '-mmacosx-version-min=14.5', '-MD', '-MF', 'bazel-out/darwin_arm64-fastbuild/bin/external/abseil-cpp+/absl/strings/_objs/string_view/string_view.h.d', '-iquote', 'external/abseil-cpp+', '-iquote', 'bazel-out/darwin_arm64-fastbuild/bin/external/abseil-cpp+', '-isystem', 'external/abseil-cpp+', '-isystem', 'bazel-out/darwin_arm64-fastbuild/bin/external/abseil-cpp+', '-DCURRENT_ROBOT_VERSION=2026', '-std=c++2a', '-DG3_DYNAMIC_LOGGING', '-Wall', '-Wextra', '-Wc++98-compat-extra-semi', '-Wcast-qual', '-Wconversion', '-Wdeprecated-pragma', '-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', '-Wvla', '-c', 'external/abseil-cpp+/absl/strings/string_view.h', '-o', 'bazel-out/darwin_arm64-fastbuild/bin/external/abseil-cpp+/absl/strings/_objs/string_view/string_view.h.processed', '-no-canonical-prefixes', '-Wno-builtin-macro-redefined', '-D__DATE__="redacted"', '-D__TIMESTAMP__="redacted"', '-D__TIME__="redacted"'].

LOGS AFTER FIX:

❯ bazel run //:refresh_compile_commands
INFO: Invocation ID: 10e12b0a-c453-43c0-8f05-9b7503945653
WARNING: Build options --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 (105 packages loaded, 1483 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: 1.188s, Critical Path: 0.00s
INFO: 2 processes: 10 action cache hit, 2 internal.
INFO: Build completed successfully, 2 total actions
INFO: Running command line: bazel-bin/refresh_compile_commands
>>> Analyzing commands used in //software/...
WARNING: Build options --features and --host_features have changed, discarding analysis cache (this can be expensive, see https://bazel.build/advanced/performance/iteration-speed).
>>> Finished extracting commands for //software/...
>>> Analyzing commands used in //proto/...
>>> Finished extracting commands for //proto/...
>>> Analyzing commands used in //extlibs/...
>>> Finished extracting commands for //extlibs/...
>>> Analyzing commands used in //shared/...
>>> Finished extracting commands for //shared/...

Testing Done

  • On master, ran bazel run //:refresh_compile_commands and compile_commands.json was generated successfully Ubuntu but not MacOS.
  • After change, ran bazel run //:refresh_compile_commands and compile_commands.json was generated successfully on both MacOS and Ubuntu.

Resolved Issues

(didn't make an issue for this small fix)

Length Justification and Key Files to Review

N/A

Review Checklist

It is the reviewers responsibility to also make sure every item here has been covered

  • Function & Class comments: All function definitions (usually in the .h file) should have a javadoc style comment at the start of them. For examples, see the functions defined in thunderbots/software/geom. Similarly, all classes should have an associated Javadoc comment explaining the purpose of the class.
  • Remove all commented out code
  • Remove extra print statements: for example, those just used for testing
  • Resolve all TODO's: All TODO (or similar) statements should either be completed or associated with a github issue

Copy link
Copy Markdown
Contributor

@Andrewyx Andrewyx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, can you make sure this works on both thunderscope & the robots as well?

@nycrat
Copy link
Copy Markdown
Member Author

nycrat commented May 21, 2026

Nice catch, can you make sure this works on both thunderscope & the robots as well?

@Andrewyx I'm a bit confused. This command just generates a compile_commands.json file, primarily for lsp support when using neovim. Not sure what working on thunderscope/robots would mean

@nycrat nycrat merged commit a239399 into master May 22, 2026
6 checks passed
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

Successfully merging this pull request may close these issues.

4 participants