Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake.copyCompileCommands fails if the destination already exists #4207

Closed
k0zmo opened this issue Dec 8, 2024 · 2 comments
Closed

cmake.copyCompileCommands fails if the destination already exists #4207

k0zmo opened this issue Dec 8, 2024 · 2 comments
Labels
bug a bug in the product

Comments

@k0zmo
Copy link
Contributor

k0zmo commented Dec 8, 2024

Brief Issue Summary

I set cmake.copyCompileCommands to be ${workspaceFolder}/build/compile_commands.json to have the compile_commands.json always in build directory, even if the project/preset uses another subdirectory for build directory (like build/${presetName}). This works fine for such scenarios but fails if the project uses just build directory and compile_commands.json is saved in this directory, originally. vscode-cmake-tools still tries to make a copy, effectively overwriting the source and ending up with the empty file - leading to an exception parsing this file.

The problem stems from how the paths are compared (as strings) and how they are normalized before that. In

const compdbPath = util.lightNormalizePath(path.join(await this.binaryDir, 'compile_commands.json'));
we call lightNormalizePath instead of platformNormalizePath which would also normalize the case. this.binaryDir that depends on ${sourceDir} always have a drive letter in uppercase:
if (process.platform === 'win32' && result.length > 1 && result.charCodeAt(0) > 97 && result.charCodeAt(0) <= 122 && result[1] === ':') {
// Windows drive letter should be uppercase, for consistency with other tools like Visual Studio.
result = result[0].toUpperCase() + result.slice(1);
}
but ${workspaceFolder} is always lowercase leading to source and destination copy target comparison to fail

Debug Log

[main] Configuring project: Sandbox-cmake 
[main] Saving open files before configure/build
[driver] Removing D:/Projects/Sandbox-cmake/build/CMakeCache.txt
[driver] Removing D:\Projects\Sandbox-cmake\build\CMakeFiles
[driver] Start configure 
[driver] Running pre-configure checks and steps
[cmakefileapi-driver] Configuring using preset
[cmakefileapi-driver] Invoking CMake D:\cmake\bin\cmake.EXE with arguments ["-DCMAKE_EXPORT_COMPILE_COMMANDS=ON","-DCMAKE_COLOR_DIAGNOSTICS=ON","-DCMAKE_PREFIX_PATH=D:/vcpkg/installed/x64-windows;D:\\\pkgs\\boost","-Dnlohmann_json_ROOT=F:\\AmppStreamingSDK\\vendor\\nlohmann_json","-DCMAKE_CXX_COMPILER=cl","-DCMAKE_PROJECT_INCLUDE_BEFORE=D:/Projects/Sandbox-cmake/cmake/compilers/msvc.cmake","-DCMAKE_BUILD_TYPE=Debug","-DCMAKE_INSTALL_PREFIX=D:/Projects/Sandbox-cmake/install/msvc-debug","-SD:/Projects/Sandbox-cmake","-BD:/Projects/Sandbox-cmake/build","-G","Ninja"]
[proc] Executing command: D:\cmake\bin\cmake.EXE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_COLOR_DIAGNOSTICS=ON "-DCMAKE_PREFIX_PATH=D:/vcpkg/installed/x64-windows;D:\pkgs\boost" -Dnlohmann_json_ROOT=F:\AmppStreamingSDK\vendor\nlohmann_json -DCMAKE_CXX_COMPILER=cl -DCMAKE_PROJECT_INCLUDE_BEFORE=D:/Projects/Sandbox-cmake/cmake/compilers/msvc.cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=D:/Projects/Sandbox-cmake/install/msvc-debug -SD:/Projects/Sandbox-cmake -BD:/Projects/Sandbox-cmake/build -G Ninja
[proc]   with environment: {}
[cmake] -- The CXX compiler identification is MSVC 19.42.34433.0
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.42.34433/bin/Hostx64/x64/cl.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Configuring done (0.4s)
[cmake] -- Generating done (0.0s)
[cmake] CMake Warning:
[cmake]   Manually-specified variables were not used by the project:
[cmake] 
[cmake]     nlohmann_json_ROOT
[cmake] 
[cmake] 
[cmake] -- Build files have been written to: D:/Projects/Sandbox-cmake/build
[cmakefileapi-parser] Read reply folder: D:\Projects\Sandbox-cmake\build\.cmake\api\v1\reply
[cmakefileapi-parser] Found index files: ["cache-v2-02dada6e8eb837c2c53a.json","cmakeFiles-v1-6543304ca09bbecdd167.json","codemodel-v2-57a76536722f0c88d6c9.json","directory-.-Debug-d0094a50bb2071803777.json","index-2024-12-08T09-30-37-0154.json","target-Sandbox-Debug-9524e5fc23ef1fcab208.json","toolchains-v1-f6606081e28ce464668e.json"]
[extension] Not updating the configuration provider because "C_Cpp.intelliSenseEngine" is set to "Disabled"
[expand] expanded ${workspaceFolder}/build/compile_commands.json
[main] Copying compile_commands.json from D:\Projects\Sandbox-cmake\build\compile_commands.json to d:/Projects/Sandbox-cmake/build/compile_commands.json
[compdb] Error parsing compilation database "D:\Projects\Sandbox-cmake\build\compile_commands.json": 
	SyntaxError: Unexpected end of JSON input
	at JSON.parse (<anonymous>)
	at CompilationDatabase.fromFilePaths (c:\Users\k0zmo\.vscode\extensions\ms-vscode.cmake-tools-1.19.52\dist\main.js:88439:38)
	at async CMakeProject.refreshCompileDatabase (c:\Users\k0zmo\.vscode\extensions\ms-vscode.cmake-tools-1.19.52\dist\main.js:85840:31)
	at async c:\Users\k0zmo\.vscode\extensions\ms-vscode.cmake-tools-1.19.52\dist\main.js:85985:33
	at async CMakeProject.doConfigure (c:\Users\k0zmo\.vscode\extensions\ms-vscode.cmake-tools-1.19.52\dist\main.js:86131:24)
[extension] [8483] cmake.cleanConfigure finished (returned {"result":0,"resultType":0})

Additional Information

No response

@gcampbell-msft
Copy link
Collaborator

@k0zmo Thanks for the bug, we're happy to take a contribution if you want to make a PR!

@k0zmo
Copy link
Contributor Author

k0zmo commented Dec 9, 2024

Sure. I just made the PR.

@Yingzi1234 Yingzi1234 added bug a bug in the product and removed triage labels Dec 11, 2024
@github-project-automation github-project-automation bot moved this from Blocked to Completed in CMake Tools Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug a bug in the product
Projects
Status: Completed
Development

No branches or pull requests

3 participants