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

Bear Incorrect Handling of Ccache v4.3 #377

Closed Jacobfaib closed 3 years ago

Jacobfaib commented 3 years ago

Describe the bug Bear calls ccache v4.3 incorrectly by not telling ccache which compiler to use. From ccache --help:

$ ccache --help
Usage:
    ccache [options]
    ccache compiler [compiler options]
    compiler [compiler options]          (via symbolic link)
...

But Bear does the following:

[12:03:01.579423, wr, 78502, ppid: 78493] Process spawned. \
[pid: 78503, command: [/usr/local/Cellar/ccache/4.3/bin/ccache, bearTest.c,  -o, bearTest]]

resulting in

ccache: error: Could not find compiler "bearTest.c" in PATH

To Reproduce bearTest.c:

int main(int argc, char **argv)
{                                                                                                   
  return 0;
}

Then setup system like so

// ccache was installed long before bear on my system, so do in this order to simulate this if it matters
brew install ccache
export PATH="/usr/local/opt/ccache/libexec:$PATH"
brew install bear
bear -- make bearTest

Expected behavior Bear should invoke the compiler after "ccache":

/path/to/ccache clang [compiler options]

Environment:

Additional context

So you might not actually get the exact form of the output I show above, but I am almost certain this is what is happening under the hood. My real test case is compiling the PETSc library. Here you actually see the bad call:

[12:03:01.579423, wr, 78502, ppid: 78493] Process spawned. [pid: 78503, command: \
[/usr/local/Cellar/ccache/4.3/bin/ccache, -fPIC, -fstack-protector, -fno-stack-check, \
-Qunused-arguments, -g3, -Wno-implicit-function-declaration, -E, \
-I/Users/jacobfaibussowitsch/NoSync/petsc/include, \
-I/Users/jacobfaibussowitsch/NoSync/petsc/arch-darwin-c-debug/include, \
-I/Users/jacobfaibussowitsch/NoSync/petscpackages/include, \
/var/folders/9w/7dlszmmn6q1gd5yf3r9n79bc0000gn/T/petscmpi-XXXXXXXX.pf9kuOzY/mpitest.c, \
-I/Users/jacobfaibussowitsch/NoSync/petscpackages/include]]

which makes ccache produce the following complaint:

ccache: invalid option -- f

Since it thinks -fPIC is an option intended for it. However the above case is also more complex, as I use ccache to wrap mpi compiler wrappers. Not sure if this is more complicated to handle for bear or not. Note that disabling ccache (by removing /usr/local/opt/ccache/libexec from my $PATH) makes all of this work.

This may possibly be related to #372

rizsotto commented 3 years ago

Thanks @Jacobfaib , this is a good report I can work on... Hope I can have some free time this weekend to put up a fix for it.

Jacobfaib commented 3 years ago

Let me know if you need me to provide you with any other info! I tried getting the full output of bear --verbose by doing

bear --verbose -- make bearTest > ./bearLog.txt

however this only put the compile command (i.e. cc bearTest.c -o bearTest) into the file while still printing bears logging output to stdout. Even redirecting via 2>&1 didn't change things. Is there another way it is supposed to be done? Worst case I can copy paste from terminal into a file but then this would include a bunch of bogus line-breaks.

rizsotto commented 3 years ago

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

rizsotto commented 3 years ago

I believe this is fixed on latest master.

Jacobfaib commented 3 years ago

Sorry for late reply, yes I can confirm this is fixed! Thanks.