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

copyCompileCommands to the original path makes the file empty #3214

Closed
tocic opened this issue Jun 20, 2023 · 3 comments
Closed

copyCompileCommands to the original path makes the file empty #3214

tocic opened this issue Jun 20, 2023 · 3 comments
Labels
bug a bug in the product Feature: language services help wanted we currently are not planning work on this and would like help from the open source community
Milestone

Comments

@tocic
Copy link

tocic commented Jun 20, 2023

Brief Issue Summary

I'm using cmake.copyCompileCommands as a workaround to support clangd (see #654):

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

But if the ${workspaceFolder}/build directory is the original compile_commands.json's directory then the extension makes the file empty. I expect it to either not copy the file or overwrite the file with its original contents.

CMake Tools Diagnostics

{
  "os": "linux",
  "vscodeVersion": "1.79.2",
  "cmtVersion": "1.14.33",
  "configurations": [
    {
      "folder": "/home/tocic/test",
      "cmakeVersion": "3.26.4",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": false,
      "compilers": {
        "C": "/usr/bin/gcc",
        "CXX": "/usr/bin/g++"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": false,
    "hasCodeModel": false,
    "activeBuildType": "",
    "buildTypesSeen": [],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 0,
    "executablesCount": 0,
    "librariesCount": 0,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": false
    }
  ]
}

Debug Log

[main] Copying compile_commands.json from /home/tocic/test/build/compile_commands.json to /home/tocic/test/build/compile_commands.json
[compdb] Error parsing compilation database "/home/tocic/test/build/compile_commands.json": 
	SyntaxError: Unexpected end of JSON input
	at JSON.parse (<anonymous>)
	at CompilationDatabase.fromFilePaths (/home/tocic/.vscode-oss/extensions/ms-vscode.cmake-tools-1.14.33-universal/dist/main.js:37178:38)
	at async CMakeProject.refreshCompileDatabase (/home/tocic/.vscode-oss/extensions/ms-vscode.cmake-tools-1.14.33-universal/dist/main.js:34944:27)
	at async /home/tocic/.vscode-oss/extensions/ms-vscode.cmake-tools-1.14.33-universal/dist/main.js:35056:33
	at async CMakeProject.doConfigure (/home/tocic/.vscode-oss/extensions/ms-vscode.cmake-tools-1.14.33-universal/dist/main.js:35145:24)

Additional Information

No response

@gcampbell-msft
Copy link
Collaborator

@tocic Thanks for the bug report! We will put this on the backlog and assess when we can get to it. In the meantime, we are happy to take open source contributions!

@gcampbell-msft gcampbell-msft added bug a bug in the product help wanted we currently are not planning work on this and would like help from the open source community Feature: language services labels Jun 22, 2023
@gcampbell-msft gcampbell-msft added this to the 1.16 milestone Jun 22, 2023
@gcampbell-msft gcampbell-msft modified the milestones: 1.16, 1.17 Oct 4, 2023
@gcampbell-msft gcampbell-msft modified the milestones: 1.17, On Deck Nov 29, 2023
parniere added a commit to parniere/vscode-cmake-tools that referenced this issue Dec 18, 2023
copyCompileCommands is equal to default db path microsoft#3214
parniere added a commit to parniere/vscode-cmake-tools that referenced this issue Dec 18, 2023
    - if copyCompileCommands is equal to default db path,
    we need to avoid the copy otherwise it would  copy on itself
@parniere
Copy link
Contributor

parniere commented Dec 18, 2023

Hi, I just hit the same bug, I think the pull request just posted above fix it
the symptom was a bit hard to see at first, I was on a very large project with clangd configured, and some of my files were not properly analyzed.

After some investigation, I noticed that the compilation db located in workspace/build had a very strange size (65536)
Monitoring this size during cmake generation, and it appeared that the size was corrupted after being properly generated.

parniere added a commit to parniere/vscode-cmake-tools that referenced this issue Jan 26, 2024
    - if copyCompileCommands is equal to default db path,
    we need to avoid the copy otherwise it would  copy on itself
parniere added a commit to parniere/vscode-cmake-tools that referenced this issue Jan 26, 2024
    - if copyCompileCommands is equal to default db path,
    we need to avoid the copy otherwise it would  copy on itself
gcampbell-msft pushed a commit that referenced this issue Jan 29, 2024
- if copyCompileCommands is equal to default db path,
    we need to avoid the copy otherwise it would  copy on itself
@gcampbell-msft gcampbell-msft modified the milestones: On Deck, 1.17 Jan 29, 2024
@recursivenomad
Copy link

I'd like to re-open this issue, as the current solution does not account for differences in path separators on Windows. 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}.

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 Feature: language services help wanted we currently are not planning work on this and would like help from the open source community
Projects
Status: Completed
Development

No branches or pull requests

4 participants