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

compileCommands do not work when ccache is used #7616

Closed
PucklaJ opened this issue May 28, 2021 · 11 comments
Closed

compileCommands do not work when ccache is used #7616

PucklaJ opened this issue May 28, 2021 · 11 comments
Assignees
Labels
bug Feature: Compile Commands fixed Check the Milestone for the release in which the fix is or will be available. Language Service regression A bug that didn't exist in a previous release
Milestone

Comments

@PucklaJ
Copy link

PucklaJ commented May 28, 2021

Bug type: Language Service

Describe the bug

  • OS and Version: Garuda Linux
  • VS Code Version: 1.56.2
  • C/C++ Extension Version: 1.4.0
  • Other extensions you installed (and if the issue persists after disabling them):
  • If using SSH remote, specify OS of remote machine:
  • A clear and concise description of what the bug is, including information about the workspace (i.e. is the workspace a single project or multiple projects, size of the project, etc).

Im am working on a C++17 project using xmake. This build system creates a compile_commands.json. If it detects ccache on the system it will use it instead of just gcc. This is also written into the compile_commands.json file. In previous versions the extension could retrieve all necessary information, but since 1.4.0 it can't and almost all types are not detected including the standard library.

Steps to reproduce

  1. Either use xmake to create compile_commands.json or just create it manually including ccache
  2. Create any xmake project
  3. Type xmake project -k compile_commands
  4. Insert path to json file into C++ settings
  5. Reload window
  6. See the errors

Expected behavior

All types should be detected as normal. I tried out removing all ccache entries of compile_commands.json, to see if it would work. And as I expected removing it made it work.

Code sample and logs

  • Code sample

  • Configurations in c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "compileCommands": "${workspaceFolder}/compile_commands.json"
        }
    ],
    "version": 4
}
  • compile_commands.json snippet:
{
  "directory": "/run/media/user/Daten/Project",
  "arguments": ["/usr/bin/ccache", "/usr/bin/gcc", "-c", "-m64", "-std=c++17", "-I", "~/.xmake/packages/g/glm/0.9.9+8/65b1ad153bda4a43b0454eba7969327f/include", "-o", "build/.objs/Project/linux/x86_64/debug/src/main.cpp.o", "src/main.cpp"],
  "file": "src/main.cpp"
},

Screenshots

Additional context

@sean-mcmanus sean-mcmanus added bug Feature: Compile Commands Language Service regression A bug that didn't exist in a previous release labels May 28, 2021
@sean-mcmanus sean-mcmanus added this to the 1.5.0 milestone May 28, 2021
@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented May 28, 2021

Hmm, I don't see it working with 1.3.1 either -- I see it fail to query /usr/bin/ccache because the /usr/bin/gcc argument is removed. What version worked for you? UPDATE: I see it work for 1.0.1 (we changed our behavior to strip unexpected arguments in some version in between).

You may be able to workaround the issue via setting compilerPath to "/usr/bin/gcc" and compilerArgs to "["-c", "-m64", "-std=c++17", "-I", "~/.xmake/packages/g/glm/0.9.9+8/65b1ad153bda4a43b0454eba7969327f/include"].

@sean-mcmanus sean-mcmanus added the more info needed The issue report is not actionable in its current state label May 28, 2021
@Colengms Colengms removed the more info needed The issue report is not actionable in its current state label May 28, 2021
@Colengms
Copy link
Contributor

I think the issue here is that we're expecting a command line to a gcc-like compiler. The path to gcc is getting stripped out because any args that appear to refer to files (i.e. to compile) need to be removed when we probe a compiler for system includes and system defines. . We will need to find a way to handle this scenario, possibly with specific handling for ccache.

@PucklaJ
Copy link
Author

PucklaJ commented May 29, 2021

What version worked for you?

I have been working with this extension for a long time now and up until now I never had any issues. Before automatically updating to 1.4.0 I was working with 1.3.0 and this was working fine for me.

@PucklaJ
Copy link
Author

PucklaJ commented May 29, 2021

You may be able to workaround the issue via setting compilerPath to "/usr/bin/gcc"

Yes, this seems to fix the issue

@xclaesse
Copy link

We will need to find a way to handle this scenario, possibly with specific handling for ccache

This is still an issue, any update? I think it should be as easy as:

if args[0].endswith('ccache'):
  args = args[1:]

Note that using CC=/usr/lib/ccache/gcc works around this issue, but that's not a practical solution.

xclaesse added a commit to xclaesse/meson that referenced this issue Mar 31, 2023
It confuses vscode's intellisense, causing it to not understand GNUC
syntaxes for example. The bug was reported upstream with not much
activity: microsoft/vscode-cpptools#7616.
xclaesse added a commit to xclaesse/vscode-meson that referenced this issue Mar 31, 2023
It confuses vscode's intellisense, causing it to not understand GNUC
syntaxes for example. The bug was reported upstream:
microsoft/vscode-cpptools#7616
xclaesse added a commit to xclaesse/vscode-meson that referenced this issue Mar 31, 2023
It confuses vscode's intellisense, causing it to not understand GNUC
syntaxes for example. The bug was reported upstream:
microsoft/vscode-cpptools#7616
xclaesse added a commit to xclaesse/vscode-meson that referenced this issue Mar 31, 2023
It confuses vscode's intellisense, causing it to not understand GNUC
syntaxes for example. The bug was reported upstream:
microsoft/vscode-cpptools#7616
xclaesse added a commit to xclaesse/vscode-meson that referenced this issue Mar 31, 2023
It confuses vscode's intellisense, causing it to not understand GNUC
syntaxes for example. The bug was reported upstream:
microsoft/vscode-cpptools#7616

Write the patched file into vscode_compile_commands.json to not modify a
file that could be used by other programs. Make sure C/C++ extension
uses the file we create.
dcbaker pushed a commit to mesonbuild/vscode-meson that referenced this issue Mar 31, 2023
It confuses vscode's intellisense, causing it to not understand GNUC
syntaxes for example. The bug was reported upstream:
microsoft/vscode-cpptools#7616

Write the patched file into vscode_compile_commands.json to not modify a
file that could be used by other programs. Make sure C/C++ extension
uses the file we create.
@Colengms Colengms self-assigned this Mar 31, 2023
@Colengms Colengms removed this from the On Deck milestone Mar 31, 2023
@Colengms Colengms added this to the 1.15.2 milestone Mar 31, 2023
@Colengms Colengms added the fixed Check the Milestone for the release in which the fix is or will be available. label Apr 3, 2023
@sean-mcmanus
Copy link
Contributor

Fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/v1.15.2 .

@xclaesse
Copy link

@sean-mcmanus Out of curiousity, the fix is in the extension, or vscode itself? Because I did not switch the cpptools extension to pre-release but I can't reproduce the problem with ccache anymore. In any case, thanks a lot!

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Apr 13, 2023

The fix should only be in the 1.15.2 (pre-release) of our C/C++ extension and not with VS Code itself (i.e. with 1.14.5 of the C/C++ extension).

@lieser
Copy link

lieser commented Apr 17, 2023

@sean-mcmanus Nice to see this getting fixed. I did a small test just now and unfortunately the fix in 1.15.2 only works for ccache/ccache.exe, but not if sccache/sccache.exe (https://github.com/mozilla/sccache) is used instead.

@xclaesse
Copy link

xclaesse commented Apr 17, 2023

That's why my snippet above suggested args[0].endswith('ccache'), it covers sccache too. I should have pointed it out explicitly. And it also deal with /usr/lib/ccache/gcc, a simple 'ccache' in argv[0] is not good either.

@sean-mcmanus
Copy link
Contributor

The sccache case is fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/v1.15.3 .

@github-actions github-actions bot locked and limited conversation to collaborators Jun 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Feature: Compile Commands fixed Check the Milestone for the release in which the fix is or will be available. Language Service regression A bug that didn't exist in a previous release
Projects
None yet
Development

No branches or pull requests

5 participants