Open recursivenomad opened 2 months 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
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 (
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)
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:
on Windows gets sanitized to
your/path/to/firmware/build/compile_commands.json
. But: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