rizsotto / Bear

Bear is a tool that generates a compilation database for clang tooling.
GNU General Public License v3.0
4.79k stars 314 forks source link

Empty compile_commands.json when using ccache #372

Closed kdkasad closed 3 years ago

kdkasad commented 3 years ago

Describe the bug When using ccache as a compiler wrapper, the resulting compile_commands.json file is empty. When I remove the cc override symlink from my path, it works fine.

To Reproduce Steps to reproduce the behavior:

  1. Add a symlink from cc -> /usr/bin/ccache
  2. Add that symlink to the beginning of your $PATH

Expected behavior The compile_commands.json file should contain the compile commands.

Environment:

Additional context

Various useful info: This is the value of $PATH that results in an empty compile_commands.json file:

$ echo $PATH
/usr/lib/ccache/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl

The first directory in the PATH overrides cc, c++, etc. with symlinks to the ccache binary:

$ ls -lah /usr/lib/ccache/bin
total 8.0K
drwxr-xr-x 2 root root 4.0K Apr 27 11:39 .
drwxr-xr-x 3 root root 4.0K Aug  2  2020 ..
lrwxrwxrwx 1 root root   15 Apr 26 16:25 c++ -> /usr/bin/ccache
lrwxrwxrwx 1 root root   15 Apr 26 16:25 cc -> /usr/bin/ccache
lrwxrwxrwx 1 root root   15 Apr 26 16:25 clang -> /usr/bin/ccache
lrwxrwxrwx 1 root root   15 Apr 26 16:25 clang++ -> /usr/bin/ccache
lrwxrwxrwx 1 root root   15 Apr 26 16:25 g++ -> /usr/bin/ccache
lrwxrwxrwx 1 root root   15 Apr 26 16:25 gcc -> /usr/bin/ccache
lrwxrwxrwx 1 root root   15 Apr 26 16:25 x86_64-pc-linux-gnu-c++ -> /usr/bin/ccache
lrwxrwxrwx 1 root root   15 Apr 26 16:25 x86_64-pc-linux-gnu-g++ -> /usr/bin/ccache
lrwxrwxrwx 1 root root   15 Apr 26 16:25 x86_64-pc-linux-gnu-gcc -> /usr/bin/ccache

When I remove that directory from the PATH, everything works fine. Here's the resulting compile_commands.json when not using ccache: compile_commands.json.zip

rizsotto commented 3 years ago

@kdkasad could you try the new version on fixes branch? I have a fix that works with the test harness running with ccache.

kdkasad commented 3 years ago

@kdkasad could you try the new version on fixes branch? I have a fix that works with the test harness running with ccache.

The problem doesn't happen when using the fixes branch

rizsotto commented 3 years ago

Thanks @kdkasad for the quick feedback. Will make a new release in this month.