Hi All,
I have a C/C++ program which can compilable with .NET’s “CL” command(which known as command line compiler) in developer command prompt.
However this program does not have any “.sln” file. It is not easy to create a “.sln” file because of there is may C/C++ files(nearly ~900) and some special command line parameters(they are not easy to configure those in solution as well). That is why I have to continue to use “CL” command with special parameters(I snippet this part from batch file, you will see them below).
(SNIPPET PART FROM BATCH FILE)
rem Compile files into .obj files in current directory
cl /I"…\testcasesupport" /W3 /MT /GS /RTC1 /bigobj /EHsc /nologo /c main.cpp CWE*.cpp CWE*.c …\testcasesupport\io.c …\testcasesupport\std_thread.c
rem Link all .obj file into a exe
cl /FeCWE416 *.obj /I"…\testcasesupport" /W3 /MT /GS /RTC1 /bigobj /EHsc /nologo
When I try to execute commands which are suggested by SonarCloud for “C/C++ language” and “Visual C++” compiler are shown below(with their outputs). Last and I guess the important information is that, I used CL command with parameters by replacing “MSBuild /t:Rebuil” part on build-wrapper step.
STEP 1
D:\Tolun\CWE416_Use_After_Free>SonarScanner.MSBuild.exe begin /k:“tolunardahanli_hello-suit” /d:sonar.organization=“tolunardahanli-github” /d:sonar.cfamily.build-wrapper-output=bw-output /d:sonar.host.url=“https://sonarcloud.io” /d:sonar.login=""
SonarScanner for MSBuild 4.4.2
Using the .NET Framework version of the Scanner for MSBuild
Default properties file was found at c:\sonarscanner-msbuild\SonarQube.Analysis.xml
Loading analysis properties from c:\sonarscanner-msbuild\SonarQube.Analysis.xml
Pre-processing started.
Preparing working directories…
05:29:07.905 Updating build integration targets…
05:29:07.925 Fetching analysis configuration settings…
05:29:09.255 Provisioning analyzer assemblies for cs…
05:29:09.265 Installing required Roslyn analyzers…
05:29:09.745 Provisioning analyzer assemblies for vbnet…
05:29:09.745 Installing required Roslyn analyzers…
05:29:09.775 Pre-processing succeeded.
STEP 2
D:\Tolun\CWE416_Use_After_Free>build-wrapper-win-x86-64.exe --out-dir bw-output cl /I"…\testcasesupport" /W3 /MT /GS /RTC1 /bigobj /EHsc /nologo /c main.cpp CWE.cpp CWE.c …\testcasesupport\io.c …\testcasesupport\std_thread.c**
main.cpp
CWE416_Use_After_Free__malloc_free_char_43.cpp
CWE416_Use_After_Free__malloc_free_char_62a.cpp
CWE416_Use_After_Free__malloc_free_char_62b.cpp
…
…
Generating Code…
Compiling…
…
…
CWE416_Use_After_Free__return_freed_ptr_16.c
CWE416_Use_After_Free__return_freed_ptr_17.c
CWE416_Use_After_Free__return_freed_ptr_18.c
io.c
std_thread.c
Generating Code…
STEP 3
D:\Tolun\CWE416_Use_After_Free>SonarScanner.MSBuild.exe end /d:sonar.login=""
SonarScanner for MSBuild 4.4.2
Using the .NET Framework version of the Scanner for MSBuild
Default properties file was found at c:\sonarscanner-msbuild\SonarQube.Analysis.xml
Loading analysis properties from c:\sonarscanner-msbuild\SonarQube.Analysis.xml
Post-processing started.
The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
Possible causes:
- The project has not been built - the project must be built in between the begin and end steps
- An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0 and 15.0 are supported
- The begin, build and end steps have not all been launched from the same folder
- None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)
Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.
05:40:10.992 Creating a summary markdown file…
05:40:10.992 Post-processing failed. Exit code: 1
My further investigation(of course not deep dive) shows that some files and folders which are special for Sonar are creted.
D:\Tolun\CWE416_Use_After_Free>tree /F
└───.sonarqube
│ ├───bin
│ │ │ SonarScanner.MSBuild.Common.dll
│ │ │ SonarScanner.MSBuild.Tasks.dll
│ │ │
│ │ └───targets
│ │ SonarQube.Integration.targets
│ │
│ ├───conf
│ │ │ SonarQubeAnalysisConfig.xml
│ │ │ SonarQubeRoslyn-cs.ruleset
│ │ │ SonarQubeRoslyn-vbnet.ruleset
│ │ │
│ │ ├───cs
│ │ │ SonarLint.xml
│ │ │
│ │ └───vbnet
│ │ SonarLint.xml
│ │
│ └───out
└───bw-output
build-wrapper-dump.json
build-wrapper.log
Any help and/or suggession will be appreciated.
Sincerely,
