I am using SonarCloud via GitLab CI to analyse a C++ project. This project will be a template library so it’s important that the headers are scanned. I cannot, however, get the header files to show up in the analysis; they are completely ignored. I have a dummy.cpp file that I intend to use just to include the header files needing analysed but this does not appear to solve anything. Currently my branch “main” has nothing as I have been working on this feature in a merge request and thus all links below will point to the relevant tree and merge request.
CI System
GitLab CICD
Expectations
SonarCloud displays header files with analysis results
I’ve done a little more digging in the logs and I definitely see references to dummy.h being scanned and there is nothing about this file being excluded. I am genuinely stumped. For example, I have compared with https://github.com/Hamdor/task which is also a C++ project using SonarCloud. While I can find no meaningful differences in the CI configurations this project has managed to have it’s header files displayed in the Sonar UI.
Is there anyone that can find something obvious that I am missing?
It was the inline keyword… Compiler inclined the function and it disappeared from all TUs. Non-inlined and function template versions yield a header file in the UI. Marking as solved…
I’lm glad that you managed to sort out your issue. I’d just like to mention that you may have missed a part of the UI that might have helped you:
It’s possible to list all indexed files in the project, by clicking on code:
I’m think you are wrong. The content of a header file shouldn’t impact if it is part of the anlysis or the “Code” Display.
A header file is analyzed if it is included in one of the translation units compiled by the build-wrapper command.
If a file(including header) show up in the analysis result depends on the type of the analysis(main branch/pull reques/short-lived).
I think the issue is just a misunderstanding of what kind of issue/code is displayed with “merge request” and short-lived branch.
So for these the “Code” display show “new code” and new code is:
For short-lived branches, the new code consists of all those files which have been modified or added relative to the target branch. Modified files are determined by comparing checksums between the sonar.branch.target branch and the short-lived branch to be analyzed.
In your case your target branch is the “main” branch.
I believe in your first try dummy.h was not modified compared to the main branch and that why it didn’t show up. and you actually “fix” it by modfying it (removing the inline keyword) which made it show up since it now contains new code.
Note: you have to analyze the main branch so that only issues in the Merge request but not in the main branch appear.