rizsotto / Bear

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

compilation_database.json is empty #476

Closed SoloAs closed 1 year ago

SoloAs commented 1 year ago

Describe the bug Compilation database JSON has no content, just "[]"

To Reproduce Steps to reproduce the behavior: running bear to build sources via Makefile right after cleaning up previous build artifacts.

Expected behavior compile_database.json contains all the necessary data. Environment:

Additional context

Also I'm using *nix shell to setup all the necessary environment and packages. SELinux is disabled:

[nix-shell:~/projects/pro-av-clean/modules/mint/test]$ sestatus | grep 'SELinux status'
SELinux status:                 disabled

Compilers seem to be set up correctly:

[nix-shell:~/projects/pro-av-clean/modules/mint/test]$ which cc
/nix/store/74kv08wjf06ifgk4dxrnra4qhzr5s1w4-gcc-wrapper-10.3.0/bin/cc
[nix-shell:~/projects/pro-av-clean/modules/mint/test]$ which g++
/nix/store/74kv08wjf06ifgk4dxrnra4qhzr5s1w4-gcc-wrapper-10.3.0/bin/g++

Please tell me if you need any additional info.

Before you send...

SoloAs commented 1 year ago

Bump!

BeeBreeze commented 1 year ago

i have the same problem. the only difference is that, if compiling via cmake, bear produces empty JSON, while if compiling via makefile without cmake, bear works well.

rizsotto commented 1 year ago

Hey @SoloAs , sorry for the delay... You've been running the bear --verbose --force-wrapper -- make command, which is using compiler wrappers to intercept the compiler calls. This needs the build system to respect the CC and CXX environment variables.

From the log I see it was calling the /nix/store/74kv08wjf06ifgk4dxrnra4qhzr5s1w4-gcc-wrapper-10.3.0/bin/gcc directly and not using the CC variable (which was set to cc).

My suggestion would be to try to change the build system (make file) to use CC for compiling the sources. (But remove this line CC=gcc at the top of the Makefile.)

You can also try to run without the --force-wrapper flag. (That works better on linux. Not sure about NIX. :))