rizsotto / Bear

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

Bear generates empty compilation database for cross-compilation on OSX 10.15.7 #359

Closed rochaferraz closed 3 years ago

rochaferraz commented 3 years ago

Describe the bug Bear generates an empty compilation database when using arm-none-eabi toolchain. Already tried to --force-wrapper, but same result. Also tried to name the C/CXX compiler (using a Bear 2). SIP is off.

I'm not sure how to name the compiler in Bear 3. Bear 2 installed from macports used to work in this project about a year back when I first used it.

To Reproduce Steps to reproduce the behavior:

Sample Log

[00:45:34.939690, br, 3004] bear: 3.0.9
[00:45:34.940766, br, 3004] arguments: ["bear", "--verbose", "--", "make", "VERBOSE=1"]
[00:45:34.940800, br, 3004] environment: (ERASED)
[00:45:34.940898, br, 3004] sysname: Darwin
[00:45:34.940902, br, 3004] release: 19.6.0
[00:45:34.940906, br, 3004] version: Darwin Kernel Version 19.6.0: Tue Nov 10 00:10:30 PST 2020; root:xnu-6153.141.10~1/RELEASE_X86_64
[00:45:34.940908, br, 3004] machine: x86_64
[00:45:34.940926, br, 3004] arguments parsed: {program: bear, arguments: [{--: [make, VERBOSE=1]}, {--citnames: [/usr/local/bin/citnames]}, {--interceptor: [/usr/local/bin/intercept]}, {--libexec: [/usr/local/libexec/libexec.dylib]}, {--output: [compile_commands.json]}, {--verbose: []}, {--wrapper: [/usr/local/libexec/wrapper]}, {--wrapper-dir: [/usr/local/libexec/wrapper.d]}]}
[00:45:34.942666, br, 3004] Process spawned. [pid: 3005, command: [/usr/local/bin/intercept, --library, /usr/local/libexec/libexec.dylib, --wrapper, /usr/local/libexec/wrapper, --wrapper-dir, /usr/local/libexec/wrapper.d, --output, compile_commands.sqlite3, --verbose, --, make, VERBOSE=1]]
[00:45:34.942708, br, 3004] Process wait requested. [pid: 3005]
[00:45:35.002250, ic, 3005] intercept: 3.0.9
[00:45:35.003242, ic, 3005] arguments: ["/usr/local/bin/intercept", "--library", "/usr/local/libexec/libexec.dylib", "--wrapper", "/usr/local/libexec/wrapper", "--wrapper-dir", "/usr/local/libexec/wrapper.d", "--output", "compile_commands.sqlite3", "--verbose", "--", "make", "VERBOSE=1"]
[00:45:35.003271, ic, 3005] environment:  (ERASED)
[00:45:35.003363, ic, 3005] sysname: Darwin
[00:45:35.003367, ic, 3005] release: 19.6.0
[00:45:35.003369, ic, 3005] version: Darwin Kernel Version 19.6.0: Tue Nov 10 00:10:30 PST 2020; root:xnu-6153.141.10~1/RELEASE_X86_64
[00:45:35.003371, ic, 3005] machine: x86_64
[00:45:35.003425, ic, 3005] arguments parsed: {program: /usr/local/bin/intercept, arguments: [{--: [make, VERBOSE=1]}, {--library: [/usr/local/libexec/libexec.dylib]}, {--output: [compile_commands.sqlite3]}, {--verbose: []}, {--wrapper: [/usr/local/libexec/wrapper]}, {--wrapper-dir: [/usr/local/libexec/wrapper.d]}]}
[00:45:35.021096, ic, 3005] session initialized with: wrapper_dir: /usr/local/libexec/wrapper.d
[00:45:35.021126, ic, 3005] session initialized with: mapping: [{ "ar": "/opt/local/bin/ar" }, { "as": "/opt/local/bin/as" }, { "bison": "/usr/bin/bison" }, { "c++": "/usr/bin/clang++" }, { "cc": "/usr/bin/clang" }, { "clang": "/usr/bin/clang" }, { "clang++": "/usr/bin/clang++" }, { "cpp": "/usr/bin/cpp" }, { "flex": "/opt/local/bin/flex" }, { "g++": "/usr/bin/g++" }, { "gcc": "/usr/bin/gcc" }, { "ld": "/opt/local/libexec/ld64/ld-xcode" }, { "lex": "/usr/bin/lex" }, { "makeinfo": "/opt/local/bin/texi2any" }, { "nm": "/opt/local/bin/llvm-nm-mp-10" }, { "objdump": "/usr/bin/objdump" }, { "ranlib": "/opt/local/bin/libtool" }, { "strip": "/opt/local/bin/strip" }, { "yacc": "/usr/bin/yacc" }]
[00:45:35.021131, ic, 3005] session initialized with: override: []
[00:45:35.039016, ic, 3005] Running gRPC server. 127.0.0.1:51975
[00:45:35.040497, ic, 3005] Process spawned. [pid: 3006, command: [make, VERBOSE=1]]
[00:45:35.040537, ic, 3005] Process wait requested. [pid: 3006]
[00:45:35.094253, wr, 3008, ppid: 3007] wrapper: 3.0.9
[00:45:35.095332, wr, 3008, ppid: 3007] arguments: ["cc", "--version"]
[00:45:35.095360, wr, 3008, ppid: 3007] environment:  (ERASED)
[00:45:35.118670, wr, 3008, ppid: 3007] gRPC call requested: supervise::Supervisor::Resolve
[00:45:35.129046, ic, 3005] trying to resolve for wrapper: cc
[00:45:35.130387, wr, 3008, ppid: 3007] gRPC call [Resolve] finished: true
[00:45:35.130909, wr, 3008, ppid: 3007] Process spawned. [pid: 3010, command: [/usr/bin/clang, --version]]
[00:45:35.131199, wr, 3008, ppid: 3007] gRPC call requested: supervise::Interceptor::Register
[00:45:35.144764, wr, 3008, ppid: 3007] gRPC call [Register] finished: true
[00:45:35.144873, wr, 3008, ppid: 3007] Process wait requested. [pid: 3010]
[00:45:35.201445, wr, 3008, ppid: 3007] Process wait request: done. [pid: 3010]
[00:45:35.201482, wr, 3008, ppid: 3007] gRPC call requested: supervise::Interceptor::Register
[00:45:35.202687, wr, 3008, ppid: 3007] gRPC call [Register] finished: true
[00:45:35.203800, wr, 3008, ppid: 3007] succeeded with: 0
/Users/user/lw-pixel2/third-party/arm-toolchain/osx/7.2_2017q4/bin/arm-none-eabi-gcc -g3 -gdwarf-2 -mcpu=cortex-m33 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=hard  --specs=nosys.specs -u _printf_float  -Os -Wall -c -fmessage-length=0 -ffunction-sections -fdata-sections -DNULL_BTL -DPLATFORM_HEADER=\"platform/base/hal/micro/cortexm3/compiler/gcc.h\" -DNVIC_CONFIG=\"platform/base/hal/micro/cortexm3/efm32/nvic-config.h\" -DEFR32MG21A010F1024IM32 -DEFR32MG21 -DCORTEXM3 -DCORTEXM3_EFR32 -DCORTEXM3_EFR32_MICRO -DCORTEXM3_EFM32_MICRO -DEFR32_SERIES2_CONFIG1_MICRO -DLONGTOKEN_SIZE=0 -DLOCKBITS_IN_MAINFLASH_SIZE=0 -DHAL_CONFIG=1 -DEMBER_AF_USE_HWCONF -DMBEDTLS_CONFIG_FILE=\"mbedtls-config.h\" -DMBEDTLS_USER_CONFIG_FILE=\"efr32-mbedtls-config.h\" -DOPENTHREAD_CONFIG_FILE=\"openthread-config-generic.h\" -DOPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"openthread-core-efr32-config.h\" -DOPENTHREAD_CORE_CONFIG_PLATFORM_CHECK_FILE=\"openthread-core-efr32-config-check.h\" -DOPENTHREAD_CONFIG_COAP_API_ENABLE=1 -DOPENTHREAD_CONFIG_COMMISSIONER_ENABLE=1 -DOPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE=1 -DOPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE=1 -DOPENTHREAD_CONFIG_DNS_CLIENT_ENABLE=1 -DOPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE=0 -DOPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE=1 -DOPENTHREAD_POSIX=1 -DOPENTHREAD_FTD=1 -DOPENTHREAD_MTD=0 -DOPENTHREAD_CONFIG_JOINER_ENABLE=1 -DOPENTHREAD_CONFIG_IP6_SLAAC_ENABLE=1 -DOPENTHREAD_CONFIG_IP6_FRAGMENTATION_ENABLE=1 -DEMLIB_USER_CONFIG -DPHY_RAIL=1 -DNVM3_DEFAULT_NVM_SIZE=24576 -DBLE -DTHREAD -DHAP_THREAD -DMBEDTLS_CHACHAPOLY_C -DMBEDTLS_POLY1305_C -DMBEDTLS_CHACHA20_C -DMBEDTLS_SHA512_C -DMBEDTLS_SHA1_C -DMBEDTLS_ECDH_C -DMBEDTLS_HKDF_C -DMBEDTLS_ENTROPY_RAIL_C -DMBEDTLS_ENTROPY_ADC_C -DOPENTHREAD_CONFIG_HEAP_INTERNAL_SIZE=16384 -DMBEDTLS_ECP_DP_CURVE25519_ENABLED -DMBEDTLS_CIPHER_MODE_CTR -DHAP_ENABLE_BUFFER_LOGS=0 -DSL_SUPRESS_DEPRECATION_WARNINGS_SDK_2_7 -DHAVE_NFC=0 -DHAP_FEATURE_NFC=0 -DTHREAD_DEVKIT -DHAVE_THREAD=1 -DHAP_FEATURE_THREAD=1 -DHAVE_BLE=1 -DHAP_FEATURE_BLE=1 -DHAVE_CONCURRENT_BLE_THREAD=1 -DBLE_SIDE_CHANNEL -DTHREAD_STATIC_COMMISSIONING=0 -DOPENTHREAD_CONFIG_COMMISSIONER_ENABLE=1 -DOPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE=1 -DOPENTHREAD_CONFIG_COAP_API_ENABLE -DOPENTHREAD_CONFIG_MAX_STATECHANGE_HANDLERS=3 -DOPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS=64 -DOPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE -DMBEDTLS_PK_WRITE_C -DMBEDTLS_PEM_WRITE_C -DMBEDTLS_BASE64_C -DRADIO_CONFIG_DMP_SUPPORT=1 -DUSE_SE_IN_IRQ=1  -I. -I../../third-party/gecko-sdk/v2.7/protocol/bluetooth/ble_stack/inc/common -I../../closed/modules/sl_custom   -std=gnu99  ../../closed/modules/sl_custom/BLECustomGeckoEvent.c -o ../../closed/modules/sl_custom/BLECustomGeckoEvent.o
/Users/user/lw-pixel2/third-party/arm-toolchain/osx/7.2_2017q4/bin/arm-none-eabi-g++ -g3 -gdwarf-2 -mcpu=cortex-m33 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=hard  --specs=nosys.specs -u _printf_float  -T "../third-party/Applications/Common/Platform/SiliconLabs/EFR32MG21/efr32mg21.ld" -Xlinker --defsym="LONGTOKEN_SIZE=0" -Xlinker --defsym="LOCKBITS_IN_MAINFLASH_SIZE=0" -Xlinker --defsym="FLASH_SIZE=1048576" -Xlinker --defsym="RAM_SIZE=262144" -Xlinker --defsym="FLASH_PAGE_SIZE=2048" -Xlinker --defsym="NULL_BTL=1" -Xlinker --defsym="HEADER_SIZE=512" -Xlinker --gc-sections -Xlinker -Map="../build/pix.map" --specs=nano.specs -u _printf_float -o ../build/pix.out -Wl,--start-group -lgcc -lc -lnosys -Wl,--end-group -Wl,--start-group ../../third-party/gecko-sdk/v2.7/hardware/kit/common/bsp/bsp_init.o (a bunch of .o files omitted) ../../third-party/gecko-sdk/v2.7/protocol/bluetooth/lib/EFR32MG21/GCC/libbluetooth.a ../../third-party/gecko-sdk/v2.7/platform/radio/rail_lib/autogen/librail_release/librail_multiprotocol_efr32xg21_gcc_release.a ../../third-party/gecko-sdk/v2.7/platform/emdrv/nvm3/lib/libnvm3_CM33_gcc.a  -Wl,--end-group
Done.
[00:45:41.606004, ic, 3005] Process wait request: done. [pid: 3006]
[00:45:41.606041, ic, 3005] Running command. [Exited with 0]
[00:45:41.606063, ic, 3005] Stopping gRPC server.
[00:45:41.608880, ic, 3005] succeeded with: 0
[00:45:41.609755, br, 3004] Process wait request: done. [pid: 3005]
[00:45:41.609793, br, 3004] Running intercept finished. [Exited with 0]
[00:45:41.610978, br, 3004] Process spawned. [pid: 3051, command: [/usr/local/bin/citnames, --input, compile_commands.sqlite3, --output, compile_commands.json, --run-checks, --verbose]]
[00:45:41.611011, br, 3004] Process wait requested. [pid: 3051]
[00:45:41.635785, cs, 3051] citnames: 3.0.9
[00:45:41.636726, cs, 3051] arguments: ["/usr/local/bin/citnames", "--input", "compile_commands.sqlite3", "--output", "compile_commands.json", "--run-checks", "--verbose"]
[00:45:41.636752, cs, 3051] environment: []
[00:45:41.636835, cs, 3051] sysname: Darwin
[00:45:41.636837, cs, 3051] release: 19.6.0
[00:45:41.636838, cs, 3051] version: Darwin Kernel Version 19.6.0: Tue Nov 10 00:10:30 PST 2020; root:xnu-6153.141.10~1/RELEASE_X86_64
[00:45:41.636840, cs, 3051] machine: x86_64
[00:45:41.636851, cs, 3051] arguments parsed: {program: /usr/local/bin/citnames, arguments: [{--input: [compile_commands.sqlite3]}, {--output: [compile_commands.json]}, {--run-checks: []}, {--verbose: []}]}
[00:45:41.637307, cs, 3051] Configuration: {"compilation":null,"output":{"content":{"include_only_existing_source":true},"format":{"command_as_array":true,"drop_output_field":false}}}
[00:45:41.645400, cs, 3051] [pid: 3010] execution: {"executable":"/usr/bin/clang","arguments":["/usr/bin/clang","--version"],"workingDir":"/Users/lw-pixel2/closed/build_system","environment":
[00:45:41.677941, cs, 3051] [pid: 3010] recognized with: Clang
[00:45:41.677979, cs, 3051] [pid: 3010] recognized as: [Query]
[00:45:41.678029, cs, 3051] compilation entries created. [size: 0]
[00:45:41.678032, cs, 3051] compilation entries to output. [size: 0]
[00:45:41.678262, cs, 3051] compilation entries written. [size: 0]
[00:45:41.678341, cs, 3051] succeeded with: 0
[00:45:41.678742, br, 3004] Process wait request: done. [pid: 3051]
[00:45:41.678766, br, 3004] Running citnames finished. [Exited with 0]
[00:45:41.678884, br, 3004] succeeded with: 0

Expected behavior A clear and concise description of what you expected to happen.

Environment:

Observation I had to make the following change to build Bear in my system:

diff --git a/source/intercept/CMakeLists.txt b/source/intercept/CMakeLists.txt
index 19c1bbb..34a5cac 100644
--- a/source/intercept/CMakeLists.txt
+++ b/source/intercept/CMakeLists.txt
@@ -37,6 +36,7 @@ target_link_libraries(intercept_a PUBLIC result_a)
 target_link_libraries(intercept_a PUBLIC spdlog::spdlog)
 target_link_libraries(intercept_a PUBLIC PkgConfig::sqlite)

+
 # Create an executable from the sub projects.
 add_executable(intercept
         source/collect/main.cc
@@ -49,6 +49,8 @@ target_link_libraries(intercept rpc_a)
 target_link_libraries(intercept sys_a)
 target_link_libraries(intercept flags_a)
 target_link_libraries(intercept exec_a)
+find_library(CoreFoundation CoreFoundation)
+target_link_libraries(intercept "${CoreFoundation}")

 install(TARGETS intercept
         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
@@ -81,6 +83,9 @@ target_link_libraries(wrapper result_a)
 target_link_libraries(wrapper sys_a)
 target_link_libraries(wrapper rpc_a)
 target_link_libraries(wrapper spdlog::spdlog)
+find_library(CoreFoundation CoreFoundation)
+target_link_libraries(wrapper "${CoreFoundation}")
+

 install(TARGETS wrapper
         RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR})

Additional context This is a SiliconLabs ARM Cortex M33 project that uses ARM bare metal toolchain (arm-none-eabi), based on a makefile build.

When building a simple Makefile project for my own architecture (gcc), Bear works.

rizsotto commented 3 years ago

Hi @rochaferraz , thanks for the report.

I guess the compiler you run is the /Users/user/lw-pixel2/third-party/arm-toolchain/osx/7.2_2017q4/bin/arm-none-eabi-gcc? From the log I can see the wrappers are set up for /usr/bin/clang to intercept. So, what I would try is this:

CC=/Users/user/lw-pixel2/third-party/arm-toolchain/osx/7.2_2017q4/bin/arm-none-eabi-gcc bear --verbose -- make (use CXX for the C++ compiler) This is the easiest way to tell Bear what is the compiler to wrap around.

The new 3.0 bear on MacOS does only compiler wrappers. Passing --force-wrapper is not necessary.

rochaferraz commented 3 years ago

Hi @rizsotto. Thanks. I tried, but I have the same results

I tried used both absolute and relative paths

[19:51:53.134284, br, 68562] bear: 3.0.9
[19:51:53.135288, br, 68562] arguments: ["bear", "--verbose", "--", "make", "VERBOSE=1"]
[19:51:53.135323, br, 68562] environment: […, "CC=../third-party/arm-toolchain/osx/7.2_2017q4/bin/arm-none-eabi-gcc", "_=/usr/local/bin/bear"]
[19:51:53.135527, br, 68562] sysname: Darwin
[19:51:53.135533, br, 68562] release: 19.6.0
[19:51:53.135535, br, 68562] version: Darwin Kernel Version 19.6.0: Tue Nov 10 00:10:30 PST 2020; root:xnu-6153.141.10~1/RELEASE_X86_64
[19:51:53.135538, br, 68562] machine: x86_64
[19:51:53.135571, br, 68562] arguments parsed: {program: bear, arguments: [{--: [make, VERBOSE=1]}, {--citnames: [/usr/local/bin/citnames]}, {--interceptor: [/usr/local/bin/intercept]}, {--libexec: [/usr/local/libexec/libexec.dylib]}, {--output: [compile_commands.json]}, {--verbose: []}, {--wrapper: [/usr/local/libexec/wrapper]}, {--wrapper-dir: [/usr/local/libexec/wrapper.d]}]}
[19:51:53.138993, br, 68562] Process spawned. [pid: 68563, command: [/usr/local/bin/intercept, --library, /usr/local/libexec/libexec.dylib, --wrapper, /usr/local/libexec/wrapper, --wrapper-dir, /usr/local/libexec/wrapper.d, --output, compile_commands.sqlite3, --verbose, --, make, VERBOSE=1]]
[19:51:53.139059, br, 68562] Process wait requested. [pid: 68563]
[19:51:53.149425, ic, 68563] intercept: 3.0.9
[19:51:53.149841, ic, 68563] arguments: ["/usr/local/bin/intercept", "--library", "/usr/local/libexec/libexec.dylib", "--wrapper", "/usr/local/libexec/wrapper", "--wrapper-dir", "/usr/local/libexec/wrapper.d", "--output", "compile_commands.sqlite3", "--verbose", "--", "make", "VERBOSE=1"]
[19:51:53.149865, ic, 68563] environment: ["CC=../third-party/arm-toolchain/osx/7.2_2017q4/bin/arm-none-eabi-gcc", …]
[19:51:53.162179, ic, 68563] sysname: Darwin
[19:51:53.162186, ic, 68563] release: 19.6.0
[19:51:53.162188, ic, 68563] version: Darwin Kernel Version 19.6.0: Tue Nov 10 00:10:30 PST 2020; root:xnu-6153.141.10~1/RELEASE_X86_64
[19:51:53.162189, ic, 68563] machine: x86_64
[19:51:53.162226, ic, 68563] arguments parsed: {program: /usr/local/bin/intercept, arguments: [{--: [make, VERBOSE=1]}, {--library: [/usr/local/libexec/libexec.dylib]}, {--output: [compile_commands.sqlite3]}, {--verbose: []}, {--wrapper: [/usr/local/libexec/wrapper]}, {--wrapper-dir: [/usr/local/libexec/wrapper.d]}]}
[19:51:53.193537, ic, 68563] session initialized with: wrapper_dir: /usr/local/libexec/wrapper.d
[19:51:53.193564, ic, 68563] session initialized with: mapping: [{ "ar": "/opt/local/bin/ar" }, { "as": "/opt/local/bin/as" }, { "bison": "/usr/bin/bison" }, { "c++": "/usr/bin/clang++" }, { "cc": "/Users/user/lw-pixel2/third-party/arm-toolchain/osx/7.2_2017q4/bin/arm-none-eabi-gcc" }, { "clang": "/usr/bin/clang" }, { "clang++": "/usr/bin/clang++" }, { "cpp": "/usr/bin/cpp" }, { "flex": "/opt/local/bin/flex" }, { "g++": "/usr/bin/g++" }, { "gcc": "/usr/bin/gcc" }, { "ld": "/opt/local/libexec/ld64/ld-xcode" }, { "lex": "/usr/bin/lex" }, { "makeinfo": "/opt/local/bin/texi2any" }, { "nm": "/opt/local/bin/llvm-nm-mp-10" }, { "objdump": "/usr/bin/objdump" }, { "ranlib": "/opt/local/bin/libtool" }, { "strip": "/opt/local/bin/strip" }, { "yacc": "/usr/bin/yacc" }]
[19:51:53.203880, ic, 68563] session initialized with: override: [{ "CC": "cc" }]
[19:51:53.207824, ic, 68563] Running gRPC server. 127.0.0.1:60095
[19:51:53.208432, ic, 68563] Process spawned. [pid: 68564, command: [make, VERBOSE=1]]
[19:51:53.208484, ic, 68563] Process wait requested. [pid: 68564]
[19:51:53.226263, wr, 68566, ppid: 68565] wrapper: 3.0.9
[19:51:53.226897, wr, 68566, ppid: 68565] arguments: ["cc", "--version"]
[19:51:53.226924, wr, 68566, ppid: 68565] environment: [“…”]
[19:51:53.228347, wr, 68566, ppid: 68565] gRPC call requested: supervise::Supervisor::Resolve
[19:51:53.230611, ic, 68563] trying to resolve for wrapper: cc
[19:51:53.231183, wr, 68566, ppid: 68565] gRPC call [Resolve] finished: true
[19:51:53.232170, wr, 68566, ppid: 68565] Process spawned. [pid: 68569, command: [/Users/user/lw-pixel2/third-party/arm-toolchain/osx/7.2_2017q4/bin/arm-none-eabi-gcc, --version]]
[19:51:53.232874, wr, 68566, ppid: 68565] gRPC call requested: supervise::Interceptor::Register
[19:51:53.244227, wr, 68566, ppid: 68565] gRPC call [Register] finished: true
[19:51:53.244338, wr, 68566, ppid: 68565] Process wait requested. [pid: 68569]
[19:51:53.244349, wr, 68566, ppid: 68565] Process wait request: done. [pid: 68569]
[19:51:53.244364, wr, 68566, ppid: 68565] gRPC call requested: supervise::Interceptor::Register
[19:51:53.247621, wr, 68566, ppid: 68565] gRPC call [Register] finished: true
[19:51:53.248635, wr, 68566, ppid: 68565] succeeded with: 0
../third-party/arm-toolchain/osx/7.2_2017q4/bin/arm-none-eabi-gcc -g3 -gdwarf-2 -mcpu=cortex-m33 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=hard  --specs=nosys.specs -u _printf_float  -Os -Wall -c -fmessage-length=0 -ffunction-sections -fdata-sections -DNULL_BTL -DPLATFORM_HEADER=\"platform/base/hal/micro/cortexm3/compiler/gcc.h\" -DNVIC_CONFIG=\"platform/base/hal/micro/cortexm3/efm32/nvic-config.h\" -DEFR32MG21A010F1024IM32 -DEFR32MG21 -DCORTEXM3 -DCORTEXM3_EFR32 -DCORTEXM3_EFR32_MICRO -DCORTEXM3_EFM32_MICRO -DEFR32_SERIES2_CONFIG1_MICRO (…) -DOPENTHREAD_CONFIG_LOG_OUTPUT=OPENTHREAD_CONFIG_LOG_OUTPUT_APP -DHAP_LOG_LEVEL=3  -I../third-party/gecko-sdk/v2.7 -I../third-party/gecko-sdk/v2.7/hardware/kit/common/bsp -I../third-party/gecko-sdk/v2.7/hardware/kit/common/drivers -I../third-party/gecko-sdk/v2.7/hardware/kit/common/halconfig -I../third-party/gecko-sdk/v2.7/hardware/kit/EFR32MG21_BRD4180A/config -std=gnu99  ../modules/hk/App/App.c -o ../modules/hk/App/App.o
../third-party/arm-toolchain/osx/7.2_2017q4/bin/arm-none-eabi-g++ -g3 -gdwarf-2 -mcpu=cortex-m33 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=hard  --specs=nosys.specs -u _printf_float  -T "../build_system/efr32mg21.ld" -Xlinker --defsym="LONGTOKEN_SIZE=0" -Xlinker --defsym="LOCKBITS_IN_MAINFLASH_SIZE=0" -Xlinker --defsym="FLASH_SIZE=1048576" -Xlinker --defsym="RAM_SIZE=262144" -Xlinker --defsym="FLASH_PAGE_SIZE=2048" -Xlinker --defsym="NULL_BTL=1" -Xlinker --defsym="HEADER_SIZE=512" -Xlinker --gc-sections -Xlinker -Map="../build/pix.map" --specs=nano.specs -u _printf_float -o ../build/pix.out -Wl,--start-group -lgcc -lc -lnosys -Wl,--end-group -Wl,--start-group ../modules/hk/App/App.o ../modules/hk/App/Main.o ../modules/hk/App/AppBase.o ../modules/hk/DB/DB.o ../third-party/gecko-sdk/v2.7/platform/Device/SiliconLabs/EFR32MG21/Source/system_efr32mg21.o ../third-party/gecko-sdk/v2.7/platform/Device/SiliconLabs/EFR32MG21/Source/GCC/startup_efr32mg21.o ../modules/sl_custom/BLECustomGeckoEvent.o ../modules/sl_custom/gatt_db.o     ../third-party/gecko-sdk/v2.7/protocol/bluetooth/lib/EFR32MG21/GCC/libbluetooth.a ../third-party/gecko-sdk/v2.7/platform/radio/rail_lib/autogen/librail_release/librail_multiprotocol_efr32xg21_gcc_release.a ../third-party/gecko-sdk/v2.7/platform/emdrv/nvm3/lib/libnvm3_CM33_gcc.a ../lib/libpix.a  -Wl,--end-group
Done.
[19:51:56.789649, ic, 68563] Process wait request: done. [pid: 68564]
[19:51:56.789687, ic, 68563] Running command. [Exited with 0]
[19:51:56.789712, ic, 68563] Stopping gRPC server.
[19:51:56.790373, ic, 68563] succeeded with: 0
[19:51:56.791230, br, 68562] Process wait request: done. [pid: 68563]
[19:51:56.791266, br, 68562] Running intercept finished. [Exited with 0]
[19:51:56.792386, br, 68562] Process spawned. [pid: 68594, command: [/usr/local/bin/citnames, --input, compile_commands.sqlite3, --output, compile_commands.json, --run-checks, --verbose]]
[19:51:56.792446, br, 68562] Process wait requested. [pid: 68594]
[19:51:56.795958, cs, 68594] citnames: 3.0.9
[19:51:56.796537, cs, 68594] arguments: ["/usr/local/bin/citnames", "--input", "compile_commands.sqlite3", "--output", "compile_commands.json", "--run-checks", "--verbose"]
[19:51:56.796566, cs, 68594] environment: ["CC=../third-party/arm-toolchain/osx/7.2_2017q4/bin/arm-none-eabi-gcc", …]
[19:51:56.796739, cs, 68594] sysname: Darwin
[19:51:56.796742, cs, 68594] release: 19.6.0
[19:51:56.796744, cs, 68594] version: Darwin Kernel Version 19.6.0: Tue Nov 10 00:10:30 PST 2020; root:xnu-6153.141.10~1/RELEASE_X86_64
[19:51:56.796745, cs, 68594] machine: x86_64
[19:51:56.796760, cs, 68594] arguments parsed: {program: /usr/local/bin/citnames, arguments: [{--input: [compile_commands.sqlite3]}, {--output: [compile_commands.json]}, {--run-checks: []}, {--verbose: []}]}
[19:51:56.796975, cs, 68594] Configuration: {"compilation":{"compilers_to_recognize":[{"executable":"../third-party/arm-toolchain/osx/7.2_2017q4/bin/arm-none-eabi-gcc"}]},"output":{"content":{"include_only_existing_source":true},"format":{"command_as_array":true,"drop_output_field":false}}}
[19:51:56.801476, cs, 68594] [pid: 68569] execution: {"executable":"/Users/user/lw-pixel2/third-party/arm-toolchain/osx/7.2_2017q4/bin/arm-none-eabi-gcc","arguments":["/Users/user/lw-pixel2/third-party/arm-toolchain/osx/7.2_2017q4/bin/arm-none-eabi-gcc","--version"],"workingDir":"/Users/user/lw-pixel2/build_system","environment”:{…}
[19:51:56.801776, cs, 68594] [pid: 68569] recognized with: GCC
[19:51:56.801810, cs, 68594] [pid: 68569] recognized as: [Query]
[19:51:56.801845, cs, 68594] compilation entries created. [size: 0]
[19:51:56.801847, cs, 68594] compilation entries to output. [size: 0]
[19:51:56.802142, cs, 68594] compilation entries written. [size: 0]
[19:51:56.802208, cs, 68594] succeeded with: 0
[19:51:56.802672, br, 68562] Process wait request: done. [pid: 68594]
[19:51:56.802717, br, 68562] Running citnames finished. [Exited with 0]
[19:51:56.802853, br, 68562] succeeded with: 0
rizsotto commented 3 years ago

Thanks for the quick update... it looks better to me. :) Can see that intercept picks up the CC from the environment. The log also shows that it sets a new CC environment and points to the compiler wrapper. The build process now uses the cc wrapper for a single execution.

Is the build system respects the CC and CXX environments? (I only see the cc --version call, but the actual compilation is using the arm-none-eabi-gcc compiler.) Can you check the make file is the compiler called via CC or it's hardcoded location? Is there a way you can specify the compiler to the build?

rochaferraz commented 3 years ago

The makefile we use uses the following pattern: we first set the toolchain in there

  ARCH = $(STUDIO_ARM_GNU_DIR)/bin/arm-none-eabi-gcc-ar
  AS = $(STUDIO_ARM_GNU_DIR)/bin/arm-none-eabi-gcc
  CC = $(STUDIO_ARM_GNU_DIR)/bin/arm-none-eabi-gcc
  CXX = $(STUDIO_ARM_GNU_DIR)/bin/arm-none-eabi-g++
  ELFTOOL = $(STUDIO_ARM_GNU_DIR)/bin/arm-none-eabi-objcopy
  LD = $(STUDIO_ARM_GNU_DIR)/bin/arm-none-eabi-g++

then the compile calls are

$(COBJS): %.o: %.c
    @echo 'Building $(notdir $(@:%.o=%.c))...'
    @$(CC) $(CFLAGS) -o $@ $<

$(CPPOBJS): %.o: %.cpp
    @echo 'Building $(notdir $(@:%.o=%.cpp))...'
    @$(CXX) $(CXXFLAGS) -o $@ $<

I've tried calling w/ and w/o the "@" output suppressor, but it looks for new Bear 3 it doesn't make mush difference, correct?

rochaferraz commented 3 years ago

Hmm, interesting. I stopped reassigning the CC/CXX variables inside the makefile. And it seems it's working ;-)

rizsotto commented 3 years ago

That makes sense to me... Since you've been overriding the Bear set environments, it was not able to call the compiler wrappers, therefore could not intercept the calls, which ends up an empty output.

I'm closing this ticket.

rochaferraz commented 3 years ago

Thanks!