rizsotto / Bear

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

No entries inside `compile_commands.json`. #496

Closed GowthamKudupudi closed 1 year ago

GowthamKudupudi commented 1 year ago

Describe the bug On macOS with bear 3.0.20, the generated compile_commands.json doesn't have any entries.

To Reproduce Steps to reproduce the behavior: bear -- clang -o print_mpz print_mpz.c -lgmp -ggdb -O0

Expected behavior A compile_commands.json with entries in it should be created.

Environment:

Additional context

#$
bear --verbose -- clang -o print_mpz print_mpz.c -lgmp -ggdb -O0
: <<'OUTPUT'
[11:28:54.333515, br, 1620] bear: 3.0.20
[11:28:54.334201, br, 1620] arguments: ["bear", "--verbose", "--", "clang", "-o", "print_mpz", "print_mpz.c", "-lgmp", "-ggdb", "-O0"]
[11:28:54.334243, br, 1620] environment: ["TERM_PROGRAM=iTerm.app", "TERM=xterm-256color", "SHELL=/bin/bash", "TMPDIR=/var/folders/ys/lvnl08g9475952gxg729tvhw0000z8/T/", "TERM_PROGRAM_VERSION=3.4.15", "OLDPWD=/", "TERM_SESSION_ID=w0t2p0:BE5561F0-C8D7-4F9B-9F99-71CF5E3AEDE4", "USER=Gowtham", "COMMAND_MODE=unix2003", "SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.M1FXiGYuRB/Listeners", "__CF_USER_TEXT_ENCODING=0x0:0:2", "PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin", "LaunchInstanceID=6377369B-E05A-4304-BB6B-0BDF85E45D37", "__CFBundleIdentifier=com.googlecode.iterm2", "PWD=/Users/Gowtham/workspace/Puddle/GMP/tests", "ITERM_PROFILE=Default", "XPC_FLAGS=0x0", "XPC_SERVICE_NAME=0", "SHLVL=1", "HOME=/Users/Gowtham", "COLORFGBG=7;0", "LC_TERMINAL_VERSION=3.4.15", "ITERM_SESSION_ID=w0t2p0:BE5561F0-C8D7-4F9B-9F99-71CF5E3AEDE4", "LOGNAME=Gowtham", "LC_CTYPE=UTF-8", "LC_TERMINAL=iTerm2", "SECURITYSESSIONID=186a4", "COLORTERM=truecolor", "_=/usr/local/bin/bear"]
[11:28:54.334281, br, 1620] sysname: Darwin
[11:28:54.334336, br, 1620] release: 21.6.0
[11:28:54.334341, br, 1620] version: Darwin Kernel Version 21.6.0: Sun Nov  6 23:31:16 PST 2022; root:xnu-8020.240.14~1/RELEASE_X86_64
[11:28:54.334343, br, 1620] machine: x86_64
[11:28:54.334360, br, 1620] arguments parsed: {program: bear, arguments: [{--: [clang, -o, print_mpz, print_mpz.c, -lgmp, -ggdb, -O0]}, {--citnames: [/usr/local/Cellar/bear/3.0.20_7/bin/citnames]}, {--interceptor: [/usr/local/Cellar/bear/3.0.20_7/bin/intercept]}, {--library: [/usr/local/Cellar/bear/3.0.20_7/lib/bear/libexec.dylib]}, {--output: [compile_commands.json]}, {--verbose: []}, {--wrapper: [/usr/local/Cellar/bear/3.0.20_7/lib/bear/wrapper]}, {--wrapper-dir: [/usr/local/Cellar/bear/3.0.20_7/lib/bear/wrapper.d]}]}
[11:28:54.335681, br, 1620] Process spawned. [pid: 1621, command: ["/usr/local/Cellar/bear/3.0.20_7/bin/intercept", "--library", "/usr/local/Cellar/bear/3.0.20_7/lib/bear/libexec.dylib", "--wrapper", "/usr/local/Cellar/bear/3.0.20_7/lib/bear/wrapper", "--wrapper-dir", "/usr/local/Cellar/bear/3.0.20_7/lib/bear/wrapper.d", "--output", "compile_commands.events.json", "--verbose", "--", "clang", "-o", "print_mpz", "print_mpz.c", "-lgmp", "-ggdb", "-O0"]]
[11:28:54.335741, br, 1620] Process wait requested. [pid: 1621]
[11:28:54.390342, ic, 1621] intercept: 3.0.20
[11:28:54.390616, ic, 1621] arguments: ["/usr/local/Cellar/bear/3.0.20_7/bin/intercept", "--library", "/usr/local/Cellar/bear/3.0.20_7/lib/bear/libexec.dylib", "--wrapper", "/usr/local/Cellar/bear/3.0.20_7/lib/bear/wrapper", "--wrapper-dir", "/usr/local/Cellar/bear/3.0.20_7/lib/bear/wrapper.d", "--output", "compile_commands.events.json", "--verbose", "--", "clang", "-o", "print_mpz", "print_mpz.c", "-lgmp", "-ggdb", "-O0"]
[11:28:54.390642, ic, 1621] environment: ["COLORFGBG=7;0", "COLORTERM=truecolor", "COMMAND_MODE=unix2003", "HOME=/Users/Gowtham", "ITERM_PROFILE=Default", "ITERM_SESSION_ID=w0t2p0:BE5561F0-C8D7-4F9B-9F99-71CF5E3AEDE4", "LC_CTYPE=UTF-8", "LC_TERMINAL=iTerm2", "LC_TERMINAL_VERSION=3.4.15", "LOGNAME=Gowtham", "LaunchInstanceID=6377369B-E05A-4304-BB6B-0BDF85E45D37", "OLDPWD=/", "PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin", "PWD=/Users/Gowtham/workspace/Puddle/GMP/tests", "SECURITYSESSIONID=186a4", "SHELL=/bin/bash", "SHLVL=1", "SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.M1FXiGYuRB/Listeners", "TERM=xterm-256color", "TERM_PROGRAM=iTerm.app", "TERM_PROGRAM_VERSION=3.4.15", "TERM_SESSION_ID=w0t2p0:BE5561F0-C8D7-4F9B-9F99-71CF5E3AEDE4", "TMPDIR=/var/folders/ys/lvnl08g9475952gxg729tvhw0000z8/T/", "USER=Gowtham", "XPC_FLAGS=0x0", "XPC_SERVICE_NAME=0", "_=/usr/local/bin/bear", "__CFBundleIdentifier=com.googlecode.iterm2", "__CF_USER_TEXT_ENCODING=0x3E8:0x0:0x0"]
[11:28:54.390711, ic, 1621] sysname: Darwin
[11:28:54.390744, ic, 1621] release: 21.6.0
[11:28:54.390748, ic, 1621] version: Darwin Kernel Version 21.6.0: Sun Nov  6 23:31:16 PST 2022; root:xnu-8020.240.14~1/RELEASE_X86_64
[11:28:54.390751, ic, 1621] machine: x86_64
[11:28:54.390762, ic, 1621] arguments parsed: {program: /usr/local/Cellar/bear/3.0.20_7/bin/intercept, arguments: [{--: [clang, -o, print_mpz, print_mpz.c, -lgmp, -ggdb, -O0]}, {--library: [/usr/local/Cellar/bear/3.0.20_7/lib/bear/libexec.dylib]}, {--output: [compile_commands.events.json]}, {--verbose: []}, {--wrapper: [/usr/local/Cellar/bear/3.0.20_7/lib/bear/wrapper]}, {--wrapper-dir: [/usr/local/Cellar/bear/3.0.20_7/lib/bear/wrapper.d]}]}
[11:28:54.391853, ic, 1621] session initialized with: wrapper_dir: /usr/local/Cellar/bear/3.0.20_7/lib/bear/wrapper.d
[11:28:54.391887, ic, 1621] session initialized with: mapping: {"ar": "/usr/bin/ar", "as": "/usr/bin/as", "bison": "/usr/bin/bison", "c++": "/usr/bin/c++", "cc": "/usr/bin/cc", "clang": "/usr/bin/clang", "clang++": "/usr/bin/clang++", "cpp": "/usr/bin/cpp", "flex": "/usr/bin/flex", "g++": "/usr/bin/g++", "gcc": "/usr/bin/gcc", "ld": "/usr/bin/ld", "lex": "/usr/bin/lex", "makeinfo": "/usr/bin/makeinfo", "nm": "/usr/bin/nm", "objdump": "/usr/bin/objdump", "ranlib": "/usr/bin/ranlib", "strip": "/usr/bin/strip", "yacc": "/usr/bin/yacc"}
[11:28:54.391893, ic, 1621] session initialized with: override: {}
[11:28:54.393678, ic, 1621] Running gRPC server. dns:///localhost:51534
[11:28:54.394168, ic, 1621] Process spawned. [pid: 1622, command: ["clang", "-o", "print_mpz", "print_mpz.c", "-lgmp", "-ggdb", "-O0"]]
[11:28:54.394201, ic, 1621] Process wait requested. [pid: 1622]
[11:28:54.603578, ic, 1621] Process wait request: done. [pid: 1622]
[11:28:54.603649, ic, 1621] Running command. [Exited with 0]
[11:28:54.603664, ic, 1621] Stopping gRPC server.
[11:28:54.604372, ic, 1621] succeeded with: 0
[11:28:54.605362, br, 1620] Process wait request: done. [pid: 1621]
[11:28:54.605413, br, 1620] Running intercept finished. [Exited with 0]
[11:28:54.606552, br, 1620] Process spawned. [pid: 1626, command: ["/usr/local/Cellar/bear/3.0.20_7/bin/citnames", "--input", "compile_commands.events.json", "--output", "compile_commands.json", "--run-checks", "--verbose"]]
[11:28:54.606596, br, 1620] Process wait requested. [pid: 1626]
[11:28:54.657838, cs, 1626] citnames: 3.0.20
[11:28:54.658489, cs, 1626] arguments: ["/usr/local/Cellar/bear/3.0.20_7/bin/citnames", "--input", "compile_commands.events.json", "--output", "compile_commands.json", "--run-checks", "--verbose"]
[11:28:54.658622, cs, 1626] environment: ["COLORFGBG=7;0", "COLORTERM=truecolor", "COMMAND_MODE=unix2003", "HOME=/Users/Gowtham", "ITERM_PROFILE=Default", "ITERM_SESSION_ID=w0t2p0:BE5561F0-C8D7-4F9B-9F99-71CF5E3AEDE4", "LC_CTYPE=UTF-8", "LC_TERMINAL=iTerm2", "LC_TERMINAL_VERSION=3.4.15", "LOGNAME=Gowtham", "LaunchInstanceID=6377369B-E05A-4304-BB6B-0BDF85E45D37", "OLDPWD=/", "PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin", "PWD=/Users/Gowtham/workspace/Puddle/GMP/tests", "SECURITYSESSIONID=186a4", "SHELL=/bin/bash", "SHLVL=1", "SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.M1FXiGYuRB/Listeners", "TERM=xterm-256color", "TERM_PROGRAM=iTerm.app", "TERM_PROGRAM_VERSION=3.4.15", "TERM_SESSION_ID=w0t2p0:BE5561F0-C8D7-4F9B-9F99-71CF5E3AEDE4", "TMPDIR=/var/folders/ys/lvnl08g9475952gxg729tvhw0000z8/T/", "USER=Gowtham", "XPC_FLAGS=0x0", "XPC_SERVICE_NAME=0", "_=/usr/local/bin/bear", "__CFBundleIdentifier=com.googlecode.iterm2", "__CF_USER_TEXT_ENCODING=0x3E8:0x0:0x0"]
[11:28:54.658659, cs, 1626] sysname: Darwin
[11:28:54.658665, cs, 1626] release: 21.6.0
[11:28:54.658667, cs, 1626] version: Darwin Kernel Version 21.6.0: Sun Nov  6 23:31:16 PST 2022; root:xnu-8020.240.14~1/RELEASE_X86_64
[11:28:54.658670, cs, 1626] machine: x86_64
[11:28:54.658683, cs, 1626] arguments parsed: {program: /usr/local/Cellar/bear/3.0.20_7/bin/citnames, arguments: [{--input: [compile_commands.events.json]}, {--output: [compile_commands.json]}, {--run-checks: []}, {--verbose: []}]}
[11:28:54.659054, cs, 1626] Configuration: {"compilation":null,"output":{"content":{"include_only_existing_source":true},"format":{"command_as_array":true,"drop_output_field":false}}}
[11:28:54.659207, cs, 1626] compilation entries created. [size: 0]
[11:28:54.659214, cs, 1626] compilation entries to output. [size: 0]
[11:28:54.659525, cs, 1626] compilation entries written. [size: 0]
[11:28:54.659563, cs, 1626] succeeded with: 0
[11:28:54.660480, br, 1620] Process wait request: done. [pid: 1626]
[11:28:54.660524, br, 1620] Running citnames finished. [Exited with 0]
[11:28:54.660673, br, 1620] succeeded with: 0
OUTPUT
#$
cat compile_commands.json
: <<'OUTPUT'
[]
OUTPUT

The compile command works fine without bear.

rizsotto commented 1 year ago

Sorry @GowthamKudupudi this is a not supported use case.

On MacOS, the compiler warppers are used to intercept the compiler calls. The best thing I can recommend is to write a simple makefile, which uses the CC environment variable. And you can call Bear as CC=clang bear -- make.

print_mpz: print_mpz.c
        $(CC) -o $@ $< -lgmp -ggdb -O3