Vscode-cmake-tools: "Failed to copy "/workspace/NewMask-Layout/build/compile_commands.json" to ".": {2}"

Created on 3 Jun 2020  路  7Comments  路  Source: microsoft/vscode-cmake-tools

In the configuration stage, it shows error "Failed to copy "/workspace/NewMask-Layout/build/compile_commands.json" to ".": {2}"

  • Operating System: Ubuntu
  • CMake Version: 3.7.3
  • VSCode Version: 1.45.3
  • CMake Tools Extension Version: 1.40.0
  • Compiler/Toolchain: GCC 9
configure settings quick fix tweak

Most helpful comment

It seems we could auto-add compile_commands.json to the path provided if the user specifies a folder. Any objections to that behavior? Is there a reason anyone would want to call the compile_commands.json file anything other than compile_commands.json?

The fix would go around here: https://github.com/microsoft/vscode-cmake-tools/blob/89b9ec8b12ee6d6138cc8865b14e6d0f0ae37d02/src/cmake-tools.ts#L646

All 7 comments

Who is attempting to copy compile_commands.json? Do you have a task?
Is this a regression with 1.4.0? When did this last work for you, with what previous release?

The CMake Tools extension generates this file as one alternative for getting IntelliSense from CppTools extension but the preferred way is to set in the workspace .vscode\settings.json: "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools". If you are not already using that, try it and let us know if you need anything else in your workflow.

Thanks for the information. Yes, it is the latest CMake-tool version of 1.4.0. I made a typo.
I am using clangd for the IntelliSense, which I think need to copy the compile_commands.json to the root of the workspace. Hence, I set the option "Cmake: Copy Compile Commands" and set to the directory of my workspace. However, it seems cmake-tools attempts to copy the compile_commands.json to the right path but fails every time. So I have to manually copy this file after the cmake configuration stage. I was wondering if you have any solution for this?

Thank you.

Same here, I'm trying to set up ccls or clangd.
OS: Ubuntu 16.04

$ cmake --version
cmake version 3.5.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).
$ code --version
1.46.1
cd9ea6488829f560dc949a8b2fb789f3cdc05f5d
x64
$ code --list-extensions --show-versions | grep -F cmake-tools
[email protected]

User settings:

    "cmake.copyCompileCommands": "${workspaceFolder}",

Who is attempting to copy compile_commands.json? Do you have a task?

I'm launching "CMake: Configure" from _Command Palette_.

Is this a regression with 1.4.0? When did this last work for you, with what previous release?

I haven't used VS Code for this project before. I believe it worked as expected once. Then I've opened the copy of compile_commands.json in VS Code to have a look, wasn't happy about its contents, tweaked cmake-kits.json, launched "CMake: Configure" command again and got the error:

Failed to copy "/home/developer/disks/foo/bar/build/clang/Release/compile_commands.json" to "/home/developer/disks/foo/bar": {2}

And it has been failing since then. I've tried to remove destination file assuming CMake Tools can't overwrite it for some reason - no success. VS Code restart did not help as well.

@andreeis, please let me know if I can provide more information.

Fixed. One needs to specify the file name. See the setting below:
"cmake.copyCompileCommands": "${workspaceFolder}/compile_commands.json".

@yuanliuus, thank you for sharing the solution! Works for me. I hope you will keep this issue open, there is clearly some room for improvement (error message, parameter description).

It seems we could auto-add compile_commands.json to the path provided if the user specifies a folder. Any objections to that behavior? Is there a reason anyone would want to call the compile_commands.json file anything other than compile_commands.json?

The fix would go around here: https://github.com/microsoft/vscode-cmake-tools/blob/89b9ec8b12ee6d6138cc8865b14e6d0f0ae37d02/src/cmake-tools.ts#L646

It seems we could auto-add compile_commands.json to the path provided if the user specifies a folder. Any objections to that behavior?

No objections, sounds reasonable.

Is there a reason anyone would want to call the compile_commands.json file anything other than compile_commands.json?

I'm not aware of any. compile_commands.json is a convention. Many tools generating (e.g. CMake) and using (e.g. Clang-Tidy) compilation database don't even support alternative names. Some generators (e.g. Build EAR) can output differently named compilation database, but I am not aware if any consumer of compilation database that takes file name as argument, usually it's directory where compile_commands.json is located.

Was this page helpful?
0 / 5 - 0 ratings