Analyzer can't find autoconf.h

Must-share information (formatted with Markdown):

  • Our setup:
    SonarQube server 9.1, GitLab CI, compilation database (compile_commands.json generated by CMake). Since we build several compile_commands.json for each sample in repository - in the end we merge them together to be analysed as one compilation database.

  • We want to achieve:
    GitLab CI analysis on CI built our docker image.

  • Current situation:
    For each built code sample our build system generates “autoconf.h” file which consists of #define macros. Therefore, several files “autoconf.h” exist each in different directory.
    GitLab CI analysis works, however we get the following warning:

14:11:19.276 WARN: 
The analyzer was not able to find file
  tdf/autoconf.h
  included from file ...path/tdf/trace_api.h
  included from file ...other_path/app_main.c
This impacts the quality of the analysis and leads to inaccurate results.
Please check that the file exists on your machine during the analysis:
* if it doesn't, find a way to persist it after your build;
  all the files accessed during the build should be accessible during the analysis
* if it does, please contact SonarSource support providing
  the full path to the file
    tdf/autoconf.h
  and the file
    another_path/sonar-cfamily-reproducer.zip

Moreover, ...path/tdf/trace_api.h and ...different_path/tdf/autoconf.h are in different paths.

During local analysis docker image analysis in WSL2 we do not receive this error.

  • What we have tried:
    We have checked that “autoconf.h” files do exist. We pass them as artifacts with the same parents directories structure into another stage. However, the warning persists.

If this sounds too complicated I will try to explain in more detailed way.
I can provide logs in private.

Ovidijus

In GitLab CI we build code in build stage and pass all needed files as artifacts to analysis stage.

Today I have found that this error does not occur when cache is disabled sonar.cfamily.cache.enabled=false .

Can we somehow use cache to speed up analysis and be able to include autoconf.h files as artifacts from previous stage?

I think one option would be to join build and analysis stages into one.

Ovidijus

Hi @Ovidijus ,

I don’t think that cache is actually the cause here.

Are you running the build and the analysis in the same environment?
I just want to make sure that you are not using the sonar-scanner docker image. You should use the sonar-scanner-cli right after your build, in the same environment, in order to allow the analyzer to access all build files.

As stated in the documentation the sonar-scanner docker image is not supported for C++:

The Build Wrapper collects information about the build including absolute file paths (source files, standard headers, libraries, etc…). Later on, SonarScanner uses this information and needs to access those paths. Whereas this is straightforward while running these 2 steps on the same host, it is worth some consideration when using any sort of containerization. A consequence of this is that C / C++ / Objective-C analysis is NOT supported by SonarScanner CLI Docker image .

Hello @mpaladin ,

Are you running the build and the analysis in the same environment?

Build and analysis CI stages are separate. Therefore, they can be run by a different runner (depends on runners availability) on the same machine. That means analysis is being done in a different environment.

I just want to make sure that you are not using the sonar-scanner docker image

We use Linux 64-bit CLI.

You should use the sonar-scanner-cli right after your build, in the same environment, in order to allow the analyzer to access all build files.

It felt like we have figured out how to perform analysis on different runners i.e. different environment despite the fact that Sonar documentation states to use same environment. We almost got it working. Looks like sonar-scanner can’t see only “autoconf.h” files. We tried uploading “autoconf.h” files to CI artifacts but without luck.

The only solution I see would be to join build and analysis stages together. Do you have other any ideas?