microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.46k stars 446 forks source link

copyCompileCommands to the original path still leaves a corrupted CDB on Windows #3874

Open recursivenomad opened 2 months ago

recursivenomad commented 2 months ago

This bug was initially identified on all platforms in #3214, and was resolved for non-Windows platforms in #3500. However, the problem still persists on Windows due to differences in path separators. Example:

"cmake.buildDirectory": "${workspaceFolder}/firmware/build"

on Windows gets sanitized to your/path/to/firmware/build/compile_commands.json. But:

"cmake.copyCompileCommands": "${workspaceFolder}/firmware/build/compile_commands.json"

does not get sanitized on Windows, and results in your\path\to/firmware/build/compile_commands.json. I can confirm this is the problem by manually entering the absolute path with identical path separators as the sanitized input, and the feature will work as intended. The result is there is still CDB corruption on Windows when using ${workspaceFolder}.

Originally posted by @recursivenomad in https://github.com/microsoft/vscode-cmake-tools/issues/3214#issuecomment-2198199560

Evelyn-001 commented 1 month ago

Thanks for reporting this issue. Today we verify your issue using a simple CMake project, and after running the command CMake:Build, in the OUTPUT window, it displays SyntaxError: Unexpected end of JSON input. Is it your issue? Please see the below video. Could you please help check our repro steps if it is same as yours? If we miss or misunderstand anything, please let us know. We are looking forward to hearing from you. Thanks.

ENV: Visual Studio Code version: 1.91.0 CMake Tools Extension version: v1.18.42 070905

OUTPUT: _[main] Building folder: MyCMakeProject [build] Starting build [proc] Executing command: "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.EXE" --build c:/Users/v-evelynyou/Desktop/MyCMakeProject/build --config Debug --target all -- [build] ninja: no work to do. [driver] Build completed: 00:00:00.115 [build] Build finished with exit code 0 [compdb] Error parsing compilation database "c:\Users\v-evelynyou\Desktop\MyCMakeProject\build\compilecommands.json": SyntaxError: Unexpected end of JSON input at JSON.parse () at CompilationDatabase.fromFilePaths (c:\Users\v-evelynyou.vscode\extensions\ms-vscode.cmake-tools-1.18.42\dist\main.js:47310:38) at async CMakeProject.refreshCompileDatabase (c:\Users\v-evelynyou.vscode\extensions\ms-vscode.cmake-tools-1.18.42\dist\main.js:44762:31) at async c:\Users\v-evelynyou.vscode\extensions\ms-vscode.cmake-tools-1.18.42\dist\main.js:45243:21

recursivenomad commented 1 month ago

Yes, this is the same issue I am experiencing - this is a very thorough reproduction!

You can also achieve this bug by calling CMake: Configure instead of CMake: Build. With the CMake logging level set to debug, it outputs the exact path it is copying from & to. It copies from a path with \s, so if you want to resolve the corruption, you can use lower case drive letters and \\ to separate directories. You will need to delete the corrupted compile_commands.json to succeed.

I expect the fix should be quite straightforward, as it would appear to be a missing sanitization step (or adding more edge-cases to the file path comparison, like capitalization and path separators)