Hello,
we tried to setup Sonar and try the Sonar Scanner tool to work with compile_commands.json generated by our project, but it doesn’t recognize our compiler. It is the GCC compiler for RiscV platform (shipped with the Zephyr SDK by default).
The sonar-scanner command fails with multiple errors (for each source file) such as:
14:00:32.273 WARN Provided compiler is not compatible.
Invalid probe found, skip analysis of files: [/home/xx/xx/xx/xx/src/main.c]
The compiler probe ‘stdout’ is expected to contain at least one’#define’ directive:
Then the tool eventually fails with:
14:00:32.767 INFO Detected compilers: riscv64-zephyr-elf-gcc=174
14:00:32.769 INFO Number of compilation units in the provided Compilation Database: 174
14:00:32.771 INFO Number of skipped unsupported compilation units: 174
14:00:32.777 INFO Number of skipped non-indexed compilation units: 0
14:00:32.777 INFO Number of skipped duplicate compilation units: 0
14:00:32.778 INFO Number of remaining compilation units to be analyzed: 0
14:00:32.780 INFO Detected standards:
14:00:32.787 INFO 236/262 files marked as unchanged
14:00:32.789 INFO Analysis cache: 0/0 hits, 125 bytes
14:00:32.789 INFO Incremental symbolic execution cache: 0 hits out of 0 total analyzed targets (hit rate 0%)
14:00:32.848 ERROR Error during SonarScanner Engine execution
java.lang.IllegalStateException: The Compilation Database JSON file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that:
* you are correctly invoking the scanner with correct configuration
* your compiler is supported
* you are providing the path to the correct Compilation Database JSON
* you are building and analyzing the same source checkout, absolute paths must be identical in build and analysis steps
at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:304)
at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:199)
at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:68)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:75)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:51)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:64)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:211)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:207)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:170)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
at org.sonar.scanner.bootstrap.ScannerContainer.doAfterStart(ScannerContainer.java:464)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:128)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
at org.sonar.scanner.bootstrap.ScannerMain.runScannerEngine(ScannerMain.java:143)
at org.sonar.scanner.bootstrap.ScannerMain.run(ScannerMain.java:58)
at org.sonar.scanner.bootstrap.ScannerMain.main(ScannerMain.java:42)
14:00:33.379 INFO EXECUTION FAILURE
Our compile_commands.json contains multiple entries such as (I replaced sensitive data with “xx”)
{
"directory": "/home/xx/xx/xx/xx",
"command": "
/home/xx/zephyr-sdk-0.17.0/riscv64-zephyr-elf/bin/riscv64-zephyr-elf-gcc
-DKERNEL
-DK_HEAP_MEM_POOL_SIZE=0
-DXX_XX_XX
-DXX_XX_XX
-DXX_XX_XX
-DPICOLIBC_MINIMAL_PRINTF_SCANF
-D__LINUX_ERRNO_EXTENSIONS__
-D__ZEPHYR__=1
-I/home/xx/xx/xx/xx/xx/src/xx
-I/home/xx/xx/xx/xx/xx/src/xx/xx
-I/home/xx/xx/xx/xx/xx/src/xx/xx/xx
-I/home/xx/xx/xx/xx/xx/src/xx/xx/xx/xx
-I/home/xx/xx/xx/xx/xx/src/xx/xx/xx/xx
-I/home/xx/xx/xx/xx/xx/src/xx/xx/xx/xx
-I/home/xx/xx/xx/xx/xx/src/xx/xx
-I/home/xx/xx/xx/xx/xx/src/xx/xx/xx
-I/home/xx/xx/xx/xx/xx/src/xx/xx/xx/xx/xx
-I/home/xx/xx/xx/xx/xx/src/xx/xx/xx/xx
-I/home/xx/xx/xx/xx/xx/src/xx/xx
-I/home/xx/xx/xx/xx/xx/src/xx/xx
-I/home/xx/xx/xx/xx/xx/src/xx
-I/home/xx/xx/xx/xx/xx/src/xx
-I/home/xx/xx/xx/xx/xx/src/xx
-I/home/xx/xx/xx/xx/zephyr/include/generated/zephyr
-I/home/xx/xx/zephyr/include
-I/home/xx/xx/xx/xx/zephyr/include/generated
-I/home/xx/xx/zephyr/soc/common/riscv-privileged/.
-isystem
/home/xx/xx/zephyr/lib/libc/common/include
-fno-strict-aliasing
-Os
-imacros
/home/xx/xx/xx/xx/zephyr/include/generated/zephyr/autoconf.h
-fno-printf-return-value
-fno-common
-g
-gdwarf-4
-fdiagnostics-color=always
-mabi=ilp32e
-march=rv32emc_zicsr
--sysroot=/home/xx/zephyr-sdk-0.17.0/riscv64-zephyr-elf/riscv64-zephyr-elf
-imacros
/home/xx/xx/zephyr/include/zephyr/toolchain/zephyr_stdint.h
-Wall
-Wformat
-Wformat-security
-Wno-format-zero-length
-Wdouble-promotion
-Wno-pointer-sign
-Wpointer-arith
-Wexpansion-to-defined
-Wno-unused-but-set-variable
-Werror=implicit-int
-fno-pic
-fno-pie
-fno-asynchronous-unwind-tables
-ftls-model=local-exec
-fno-reorder-functions
--param=min-pagesize=0
-fno-defer-pop
-fmacro-prefix-map=/home/xx/xx/xx/xx/xx/src=CMAKE_SOURCE_DIR
-fmacro-prefix-map=/home/xx/xx/zephyr=ZEPHYR_BASE
-fmacro-prefix-map=/home/xx/xx=WEST_TOPDIR
-ffunction-sections
-fdata-sections
-specs=picolibc.specs
-std=c99
-Werror
-o
CMakeFiles/app.dir/main.c.obj
-c
/home/xx/xx/xx/xx/xx/src/main.c",
"file": "/home/xx/xx/xx/xx/xx/src/main.c",
"output": "CMakeFiles/app.dir/main.c.obj"
},
It seems, that sonar-scanner’s compiler probe tries to pass some incorrect parameters to our compiler, thus causing the fail. Running strace on sonar-scanner reveals, that the probe runs the compiler with the following set of params:
-E -quiet -v -march=rv32emc_zicsr -mabi=ilp32 -misa-spec=20191213 -march=rv32emc_zicsr -std=c99 -dM -dumpbase
but some of them are not correct for this particular GCC version:
riscv64-zephyr-elf-gcc: error: unrecognized command-line option ‘-quiet’
Are there ways to solve this issue?
Thank you