rizsotto / Bear

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

Empty comile_commands.json for Scons builds on Mac #463

Closed bneradt closed 2 years ago

bneradt commented 2 years ago

Describe the bug When I compile https://github.com/yahoo/proxy-verifier.git, which is built via the scons-parts build system on my Mac via Bear, I get an empty compile_commands.json:

$ cat compile_commands.json 
[]

I am building from scratch and I see the clang calls in the output (verbose logs attached).

To Reproduce

Install developer tools to get llvm and use brew to install various package dependencies. pkg-config, autoconf, automake, libtool, pipenv, and python3 will be necessary. Bear is also necesasry. :) Here is my list of installed brew packages:

$ brew list
==> Formulae
abseil                  ca-certificates         gettext                 libtermkey              luv                     neovim                  pipenv                  readline                the_silver_searcher     zlib
autoconf                cmake                   git                     libtool                 m4                      nlohmann-json           pkg-config              ruby                    tmux
automake                cscope                  grpc                    libuv                   macvim                  node                    protobuf                six                     tree-sitter
bear                    docker                  icu4c                   libyaml                 mpdecimal               openssl@1.1             python@3.10             spdlog                  unibilium
brotli                  fmt                     libevent                lua                     msgpack                 pcre                    python@3.9              sqlite                  utf8proc
c-ares                  gdbm                    libnghttp2              luajit-openresty        ncurses                 pcre2                   re2                     swig                    xz

Once this is installed, then the following should reproduce the behavior:

git clone git@github.com:yahoo/proxy-verifier.git
cd proxy-verifier

# The following pipenv install will install scons-parts to build Proxy Verifier.
pipenv install

# Build and install the openssl and HTTP library dependencies:
bash tools/build_library_dependencies.sh /opt

# Now build proxy-verifier through bear:
bear -- pipenv run scons -j4 --with-libs=/opt

This results in an empty compile_commands.json:

$ cat compile_commands.json 
[]

Expected behavior

The compile_commands.json should be populated with the build output. As a point of comparison, I get the expected compile_commands.json when I build Proxy Verifier on Centos 7 using GCC devtoolset-9:

bear_pv_works_centos_7.txt

Here is some sample, healthy compile_commands.json output:

$ grep 'file":' compile_commands.json  | head
    "file": "/home/bneradt/repos/proxy-verifier/.sconf_temp/conftest_d4efa789addd7bf9e71f629ac86897a2_0.c",
    "file": "/home/bneradt/repos/proxy-verifier/.sconf_temp/conftest_d41a916d4ed964113d4ac62b6b3ce6c3_0.c",
    "file": "/home/bneradt/repos/proxy-verifier/.sconf_temp/conftest_df0e1703bbe19b5ff27a979bea85065d_0.c",
    "file": "/home/bneradt/repos/proxy-verifier/.sconf_temp/conftest_64fcaf32dd3ecf40202267df35500bc3_0.c",
    "file": "/home/bneradt/repos/proxy-verifier/_scm/libswoc-8bbe/code/src/TextView.cc",
    "file": "/home/bneradt/repos/proxy-verifier/_scm/libswoc-8bbe/code/src/ArenaWriter.cc",
    "file": "/home/bneradt/repos/proxy-verifier/local/src/core/ProxyVerifier.cc",
    "file": "/home/bneradt/repos/proxy-verifier/local/src/core/http3.cc",
    "file": "/home/bneradt/repos/proxy-verifier/local/src/core/verification.cc",
    "file": "/home/bneradt/repos/proxy-verifier/local/src/core/https.cc",

By contrast, my Mac Scons build via Bear of proxy-verifier has an empty compile_commands.json:

$ cat compile_commands.json 
[]

Environment:

$ uname -a
Darwin TGW26GQPQ3 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:46:32 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T6000 arm64

Additional context

Before you send...


Thank you for working on this wonderful tool. I'm sorry if I'm missing something obvious.

rizsotto commented 2 years ago

Hey @bneradt, thanks for your kind words.

For your problem, here is a little background information... Bear works differently on Linux and Mac. On Linux it intercept the process executions with a preloaded shared object. This trick does not work on Mac. Instead it use compiler wrapper, which reports the process executions... The compiler wrapper interposing only works with builds, which are open to override the compiler. (See these tickets: #460, #401, #375, #364, #360, or a common troubleshooting page for this kind of errors.)

From the logs you've attached, I did noticed:

My suggestion would be:

bneradt commented 2 years ago

I see. Thank you for the quick reply @rizsotto. This is very helpful. I actually work with one of the contributors for Scons. I'll work with him to see if there is a way to get it to use the wrapper and report back on what I find.

rizsotto commented 2 years ago

I am closing it, because not much I can do with it... As we discussed this is more like the build system needs to respect the variables, or the Bear executed commands does not reset the environment variables.

bneradt commented 2 years ago

Yes, that is fine to close @rizsotto. Thank you again for your previous feedback. I want to contribute to the project by documenting what can be done with scons-parts to it to use bear's wrapper scripts.

My scons-parts contact has been very busy with other build issues so I have not had the opportunity yet dig into this yet with him. I still plan to pursue this in the future and add comments here.