Unexpanded response file error when using Sonarlint for VSCode

System information:

  • Operating system: Windows
  • SonarLint plugin version: 4.0.5
  • Programming language you’re coding in: C/C++
  • Is connected mode used: Yes
    • Connected to SonarCloud or SonarQube (and which version): SonarQube - Enterprise Edition - Version 9.9 (build 65466)

I am trying to use Sonarlint but I am getting the following error:

[Debug - 14:34:17.507] Time to parse Compilation Database: 38ms
[Error - 14:34:17.518] Error executing sensor: 'CFamily'
[Error - 14:34:17.518] java.lang.IllegalStateException: unexpanded response file
	at com.sonar.cpp.analyzer.ClangDriver.onCapture(ClangDriver.java:532)
	at com.sonar.cpp.analyzer.CompilerDrivers.onCapture(CompilerDrivers.java:36)
	at com.sonar.cpp.plugin.SonarLintSensor.lambda$processCompileCommands$1(SonarLintSensor.java:164)
	at java.base/java.util.HashMap.forEach(Unknown Source)
	at com.sonar.cpp.plugin.SonarLintSensor.processCompileCommands(SonarLintSensor.java:158)
	at com.sonar.cpp.plugin.SonarLintSensor.process(SonarLintSensor.java:144)
	at com.sonar.cpp.plugin.SonarLintSensor.execute(SonarLintSensor.java:104)
	at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:222)
	at org.sonarsource.sonarlint.core.analysis.container.analysis.sensor.SensorsExecutor.executeSensor(SensorsExecutor.java:75)
	at org.sonarsource.sonarlint.core.analysis.container.analysis.sensor.SensorsExecutor.execute(SensorsExecutor.java:66)
	at org.sonarsource.sonarlint.core.analysis.container.analysis.AnalysisContainer.doAfterStart(AnalysisContainer.java:122)
	at org.sonarsource.sonarlint.core.plugin.commons.container.SpringComponentContainer.startComponents(SpringComponentContainer.java:182)
	at org.sonarsource.sonarlint.core.plugin.commons.container.SpringComponentContainer.execute(SpringComponentContainer.java:161)
	at org.sonarsource.sonarlint.core.analysis.container.module.ModuleContainer.analyze(ModuleContainer.java:71)
	at org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand.execute(AnalyzeCommand.java:58)
	at org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand.execute(AnalyzeCommand.java:32)
	at org.sonarsource.sonarlint.core.analysis.AnalysisEngine$AsyncCommand.execute(AnalysisEngine.java:153)
	at org.sonarsource.sonarlint.core.analysis.AnalysisEngine.executeQueuedCommands(AnalysisEngine.java:71)
	at java.base/java.lang.Thread.run(Unknown Source)

I using the extension Makefile on VS Code to automatically generate the compile_commands.json file. I don’t know if it matters, but I also have installed the extensions C/C++.

My compile_commands.json looks like this:

{
        "command": "arm-none-eabi-gcc -std=c99 -Wall -g -ggdb --specs=nosys.specs -O0 -mcpu=cortex-m4 -mthumb -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -munaligned-access -c -fmessage-length=0 -DXMC4700_F144x2048 -DNAND_RECORD_CHECK_ON -DNAND_DEBUG -DDEBUGMSG_INFO -DLOG_VIA_SEGGER_RTT  -Dmalloc=pvPortMalloc -Dfree=vPortFree -Dcalloc=xvPortCalloc -Drealloc=xvPortRealloc -MMD -MP -MF Bin/Debug/Obj/.deps/main.d project_sonarlint_test/./main.c -o Bin/Debug/Obj/project_sonarlint_test/./main.o @Bin/Debug/Obj/include_list.txt\r",
        "directory": "c:/Users/user/project_sonarlint_test",
        "file": "c:\\Users\\user\\project_sonarlint_test\\main.c"
},

My c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.18362.0",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe",
            "cStandard": "${default}",
            "cppStandard": "${default}",
            "intelliSenseMode": "windows-msvc-x64"
        }
    ],
    "version": 4
}

And settings.json looks like this:

{
    "makefile.compileCommandsPath": "${workspaceFolder}\\.vscode\\compile_commands.json",
    "sonarlint.connectedMode.project": {
        "connectionId": "https-sonarqube-mycompany-com",
        "projectKey": "project_sonarlint_test"
    },
    "sonarlint.pathToCompileCommands": "${workspaceFolder}\\.vscode\\compile_commands.json"
}

I saw a similar question in the community, I tried to replicate the solution but it didn’t work.
All other programming languages are checking correctly, only C/C++ is not working.

I also enabled the rule c:S2260/cpp:S2260, strangely it worked, but when I closed VS Code and opened it again it didn’t work anymore (the rule was still in the user’s settings.json file). I tried to reset everything and started again, but without success.

hi @clima6,

In your compilation database, you have @Bin/Debug/Obj/include_list.txt. This is an unexpanded response file that we don’t support.

If you are using CMake, you can fix this issue by setting these two CMAKE variables in your CMakeLists.txt and cleanly regenerating the compilation database:

set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 0)
set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES 0)

After doing that you should see that you no longer have unexpanded files.
If you use other tools to generate a compilation database, lookup there documentation to see if there is a way to get rid of unexpanded response files.

Thanks,

1 Like

We changed all paths on our compile_commands.json file from "Bin/Debug/Obj/include_list.txt" to "./*.h ./*/*.h ./*/*/*.h". Now it works!

Thank you for the insight.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.