c++arduinocode-coveragecoverityarduino-cli

Setting up Coverity Check for Arduino Codebase


We have a repository that we build using Arduino IDE and we're trying to setup Coverity Checks for it. I tried using arduino-cli for cov-build but it gives the error "No files were emitted". Here are the commands I executed and their outputs:

Command

(cov_venv) npy:~/coverity_checker/coverity-checker$ "${COVERITY}/bin/cov-configure" --compiler "${AVR_GCC_PATH}/avr-g++" --comptype gcc --config "${COVERITY_CONFIG_PATH}"

Output

[WARNING] A template configuration is recommended for this compiler.
Template configuration will become the default for this compiler in a future release.
Add "--template" to your command line, or use one of the
template configuration shortcut command lines below:

  cov-configure --gcc      # GNU C/C++ compiler (gcc/g++)
  cov-configure --msvc     # Microsoft C/C++ compiler (cl)
  cov-configure --java     # Oracle Java compiler (javac)

You must remove the specific configuration before re-running with "--template".
* Configuring /home/npyetheendra/coverity_checker/coverity-checker/bin/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ as a C compiler
[WARNING] Config gcc-config-0 already exists for avr-g++ as gcc and will be reused. 
* Configuring /home/npyetheendra/coverity_checker/coverity-checker/bin/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ as a C++ compiler
[WARNING] Config g++-config-0 already exists for avr-g++ as g++ and will be reused. 
* Configuring /home/npyetheendra/coverity_checker/coverity-checker/bin/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ as a C compiler
[WARNING] Config g++cc-config-0 already exists for avr-g++ as g++cc and will be reused. 

Generated coverity_config.xml at location /home/npyetheendra/coverity_checker/coverity-checker/config/coverity_config/coverity_config.xml
Successfully generated configuration for the compilers: avr-g++

Command

(cov_venv) npy:~/coverity_checker/coverity-checker$ ${COVERITY}/bin/cov-build --dir "${COV_WORKSPACE}"     ${COV_PARENT_DIR}/bin/arduino-cli compile     --fqbn SparkFun:avr:promicro     --verbose     --build-path "${OUTPUT_DIR}"     "${sketch_to_compile}"     --config-file "${COV_PARENT_DIR}/bin/.arduino15/arduino-cli.yaml"

Output

Coverity Build Capture (64-bit) version 2024.9.0 on Linux 5.4.0-169-generic x86_64
Internal version numbers: 950e903b4e p-2024.9-push-30


Sketch uses 26294 bytes (91%) of program storage space. Maximum is 28672 bytes.
Global variables use 988 bytes (38%) of dynamic memory, leaving 1572 bytes for local variables. Maximum is 2560 bytes.
Attempting to detect unconfigured compilers in build
|0----------25-----------50----------75---------100|
****************************************************
[WARNING] No files were emitted. This may be due to a problem with your configuration
or because no files were actually compiled by your build command.
Please make sure you have configured the compilers actually used in the compilation.
 For more details, please look at: 
    /home/npyetheendra/coverity_checker/coverity-checker/CoverityWorkspace/build-log.txt
(cov_venv) npyetheendra@build-npyetheendra-jammy-20250506:~/coverity_checker/coverity-checker$ ${COVERITY}/bin/cov-build --dir "${COV_WORKSPACE}"     ${COV_PARENT_DIR}/bin/arduino-cli compile     --fqbn SparkFun:avr:promicro  --build-path "${OUTPUT_DIR}"     "${sketch_to_compile}"     --config-file "${COV_PARENT_DIR}/bin/.arduino15/arduino-cli.yaml"
Coverity Build Capture (64-bit) version 2024.9.0 on Linux 5.4.0-169-generic x86_64
Internal version numbers: 950e903b4e p-2024.9-push-30


Sketch uses 26294 bytes (91%) of program storage space. Maximum is 28672 bytes.
Global variables use 988 bytes (38%) of dynamic memory, leaving 1572 bytes for local variables. Maximum is 2560 bytes.
Attempting to detect unconfigured compilers in build
|0----------25-----------50----------75---------100|
****************************************************
[WARNING] No files were emitted. This may be due to a problem with your configuration
or because no files were actually compiled by your build command.
Please make sure you have configured the compilers actually used in the compilation.
 For more details, please look at: 
    /home/npyetheendra/coverity_checker/coverity-checker/CoverityWorkspace/build-log.txt

I haven't used Coverity before, so I don't know much about it. I read coverity has to be specifically configured using a xml config file for builds not natively supported. I'm not sure if this configuration can be done if we're trying to build using arduino-cli. Does anyone have experience working on something similar before?

Edit:

I tried removing the config directory and creating the config again with a template config, but it still shows no files were emitted.

Commands and output: https://gist.github.com/NXPY123/63e4cd1d065b3778087855f197ecbf87

build-log.txt: https://gist.github.com/NXPY123/e3861672e25445623e4a3f351ac66efe


Solution

  • For the moment, this is only a partial answer because a working solution has not been confirmed.

    Problem

    The main problem here is that arduino-cli invokes cc1plus (the portion of the compiler that parses C++ and turns it into object code) directly rather than avr-g++ (the "driver" that inteprets command line arguments). The Coverity build interception system expects to see invocations of avr-g++ rather than cc1plus.

    We can see this in the build-log.txt file. First, there is the EXECUTING line for arduino-cli compile:

    [425415] EXECUTING: /home/npyetheendra/coverity_checker/coverity-checker/bin/arduino-cli compile --fqbn SparkFun:avr:promicro --verbose --build-path /home/npyetheendra/coverity_checker/coverity-checker/output /home/npyetheendra/coverity_checker/arduino/P3584/P3584.ino --config-file /home/npyetheendra/coverity_checker/coverity-checker/bin/.arduino15/arduino-cli.yaml
    

    Next is the EXECUTING line for cc1plus:

    [425448] EXECUTING: /home/npyetheendra/coverity_checker/coverity-checker/bin/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/../libexec/gcc/avr/7.3.0/cc1plus -E -quiet -CC -I /home/npyetheendra/coverity_checker/coverity-checker/bin/.arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino -I /home/npyetheendra/coverity_checker/coverity-checker/bin/.arduino15/packages/SparkFun/hardware/avr/1.1.13/variants/promicro -imultilib avr5 -iprefix /home/npyetheendra/coverity_checker/coverity-checker/bin/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/../lib/gcc/avr/7.3.0/ -D__AVR_ATmega32U4__ -D__AVR_DEVICE_NAME__=atmega32u4 -D F_CPU=8000000L -D ARDUINO=10607 -D ARDUINO_AVR_PROMICRO -D ARDUINO_ARCH_AVR -D USB_VID=0x1b4f -D USB_PID=0x9204 -D USB_MANUFACTURER="Unknown" -D "USB_PRODUCT="SparkFun Pro Micro"" /home/npyetheendra/coverity_checker/coverity-checker/output/sketch/P3584.ino.cpp -o /dev/null -mn-flash=1 -mno-skip-bug -mmcu=avr5 -std=gnu++11 -w -w -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -g -fworking-directory -Os -mn-flash=1 -mno-skip-bug -fno-rtti -fno-enforce-eh-specs -fno-exceptions
    

    But, crucially, there is no COMPILING line for the above since cc1plus is not recognized as a compiler by cov-build. There are some COMPILING lines later on, but they are for tools like ar and ld which do not matter to Coverity, so those are effectively ignored by cov-build.

    Consequently, cov-build does not see (recognize) any compilation commands, so No files were emitted. ("Emitted" is Coverity-speak for "compiled", essentially.)

    For completeness, I should also note that I don't see any explicit support for arduino-cli listed at Coverity 2024.6.0: Supported Platforms, Languages, and Compilers for Coverity on Polaris, so what you're trying to do is probably officially unsupported (although I could be missing something or looking in the wrong place).

    Solution candidate

    Ideally, arduino-cli compile could be told to invoke avr-g++ instead of cc1plus, but based on its documentation, that does not appear possible.

    The other alternative is to configure cc1plus, which I think should look something like this:

    $ cov-configure --comptype gcc --compiler cc1plus --template
    

    The above is extrapolated from these two support articles:

    If this works, then the build log will show COMPILING after the EXECUTING for cc1plus, and hopefully (!) will interpret the command line arguments properly, leading to files "emitted" and therefore subsequently available to analyze.

    (Again, this answer is for the moment incomplete as I don't have the required tools to test it.)