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 with xcodebuild #375

Closed lah64 closed 3 years ago

lah64 commented 3 years ago

Verbose:

** BUILD SUCCEEDED **

[03:50:56.328103, ic, 1170] Process wait request: done. [pid: 1171]
[03:50:56.328123, ic, 1170] Running command. [Exited with 0]
[03:50:56.328128, ic, 1170] Stopping gRPC server.
[03:50:56.328365, ic, 1170] succeeded with: 0
[03:50:56.328714, br, 1169] Process wait request: done. [pid: 1170]
[03:50:56.328727, br, 1169] Running intercept finished. [Exited with 0]
[03:50:56.328945, br, 1169] Process spawned. [pid: 1289, command: [/opt/homebrew/Cellar/bear/3.0.11_2/bin/citnames, --input, compile_commands.db, --output, compile_commands.json, --run-checks, --verbose]]
[03:50:56.328954, br, 1169] Process wait requested. [pid: 1289]
[03:50:56.337650, cs, 1289] citnames: 3.0.11
[03:50:56.337800, cs, 1289] arguments: ["/opt/homebrew/Cellar/bear/3.0.11_2/bin/citnames", "--input", "compile_commands.db", "--output", "compile_commands.json", "--run-checks", "--verbose"]
[03:50:56.337807, cs, 1289] environment: ["HOME=/Users/ask", "HOMEBREW_CELLAR=/opt/homebrew/Cellar", "HOMEBREW_PREFIX=/opt/homebrew", "HOMEBREW_REPOSITORY=/opt/homebrew", "INFOPATH=/opt/homebrew/share/info:", "LC_CTYPE=UTF-8", "LESS=-R", "LOGNAME=ask", "LSCOLORS=Gxfxcxdxbxegedabagacad", "MANPATH=/opt/homebrew/share/man::", "OLDPWD=/Users/ask/Downloads/test/Examples/IPlugEffect/projects", "PAGER=less", "PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin", "PWD=/Users/ask/Downloads/test/Examples/IPlugEffect", "SHELL=/bin/zsh", "SHLVL=1", "SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.llDdnChIYH/Listeners", "TERM=xterm-256color", "TERM_PROGRAM=Apple_Terminal", "TERM_PROGRAM_VERSION=440", "TERM_SESSION_ID=54C9BBFF-CAC9-4C2F-921D-D7AC1DCE502B", "TMPDIR=/var/folders/hb/rqr8x_qj71n_t6b1ykly5tsm0000gn/T/", "USER=ask", "XPC_FLAGS=0x0", "XPC_SERVICE_NAME=0", "ZSH=/Users/ask/.oh-my-zsh", "_=/opt/homebrew/bin/bear", "__CFBundleIdentifier=com.apple.Terminal"]
[03:50:56.337865, cs, 1289] sysname: Darwin
[03:50:56.337866, cs, 1289] release: 20.4.0
[03:50:56.337866, cs, 1289] version: Darwin Kernel Version 20.4.0: Fri Mar  5 01:14:02 PST 2021; root:xnu-7195.101.1~3/RELEASE_ARM64_T8101
[03:50:56.337867, cs, 1289] machine: arm64
[03:50:56.337875, cs, 1289] arguments parsed: {program: /opt/homebrew/Cellar/bear/3.0.11_2/bin/citnames, arguments: [{--input: [compile_commands.db]}, {--output: [compile_commands.json]}, {--run-checks: []}, {--verbose: []}]}
[03:50:56.337936, cs, 1289] Configuration: {"compilation":null,"output":{"content":{"include_only_existing_source":true},"format":{"command_as_array":true,"drop_output_field":false}}}
[03:50:56.337971, cs, 1289] compilation entries created. [size: 0]
[03:50:56.337973, cs, 1289] compilation entries to output. [size: 0]
[03:50:56.338099, cs, 1289] compilation entries written. [size: 0]
[03:50:56.338109, cs, 1289] succeeded with: 0
[03:50:56.338341, br, 1169] Process wait request: done. [pid: 1289]
[03:50:56.338350, br, 1169] Running citnames finished. [Exited with 0]
[03:50:56.338390, br, 1169] succeeded with: 0

Screenshot 2021-05-09 at 03 52 14

Somebody, please give me a gun...

How to repeat it:

  1. Clone: https://github.com/iPlug2/iPlug2
  2. Got to .../Examples/IPlugEffect/
  3. Run:

bear --verbose -- xcodebuild -workspace IPlugEffect.xcworkspace -scheme "macOS-VST3"

lah64 commented 3 years ago

A common default project such as Hello World C++ by XCode got the same problem...

rizsotto commented 3 years ago

Hey @SKyzZz , thanks for this report. I can't reproduce this (have no access to macOS), so I need some more logs in order to help. The output is empty, because the intercept process failed to capture the compiler calls. It is done by compiler wrappers. Let's find out why that failed. I need more log lines from the start of the build, including the command you've typed to run the build.

lah64 commented 3 years ago

@rizsotto

-> % bear --verbose -- xcodebuild -workspace IPlugEffect.xcworkspace -scheme "macOS-VST3"

Log.zip

rizsotto commented 3 years ago

Thanks @SKyzZz , from the logs I see the followings:

Currently there is no way to tell to intercept (the program bear internally calls) which compiler to wrap around. It uses the first one it founds in the PATH. As a workaround try to put the /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin directory into the front of the directory list.

lah64 commented 3 years ago
ask@ASKs-Mac-mini [15:12:19] [~/Downloads/test/Examples/IPlugEffect] 
-> % which clang
/usr/bin/clang

ask@ASKs-Mac-mini [15:42:26] [~/Downloads/test/Examples/IPlugEffect] 
-> % echo $PATH
/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin

PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin 
ask@ASKs-Mac-mini [15:44:58] [~/Downloads/test/Examples/IPlugEffect]

-> % echo $PATH
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin

ask@ASKs-Mac-mini [15:45:18] [~/Downloads/test/Examples/IPlugEffect]
-> % which clang
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang

-> % bear --verbose -- xcodebuild -workspace IPlugEffect.xcworkspace -scheme "macOS-VST2"

Log 2.zip

Output: []

rizsotto commented 3 years ago

This looks much better to me, but can understand your frustration that it's still not working. :)

It looks like the build system uses the absolute path of the compilers. This case intercept can't interpose the compiler wrappers. I don't know xcode how to configure which compiler to use or is there a configure step before you run the build.

In a make project the build file would contains the build rules as $CC -c source.c -Wall ... where the value of the CC is either can be set manually. Or it is captured by a ./configure script that you run before the build. The first case Bear would handle automatically, and in the second case you would need to run bear -- ./configure to capture the compiler wrappers for the build, throw away the created compile_commands.json file, and run bear -- make ... which will now use the wrappers... If the make file would have been written like /usr/local/somewhere/not/common/bin/cc -c source.c -Wall ... the compiler wrapper can't be replaced.

Sorry about it, but this is a limitation of the compiler wrapper technique. Will document it better in the wiki.

lah64 commented 3 years ago

xcodebuild -workspace IPlugEffect.xcworkspace -scheme "macOS-VST3" | xcpretty -r json-compilation-database -o compile_commands.json

compile_commands.json.zip

rizsotto commented 3 years ago

So xcodebuild can generate the compilation database without Bear?

lah64 commented 3 years ago

It seems that it is, but the only requirement is that it should always be a clean project and for each scheme separately.

rizsotto commented 3 years ago

Great! I'll close this ticket. There is not much I do here.

orikad commented 1 year ago

fwiw, doing CC=clang bear -- xcodebuild <...> CC=$CC works