microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.52k stars 1.55k forks source link

compileCommands do not work when ccache is used #7616

Closed PucklaJ closed 1 year ago

PucklaJ commented 3 years ago

Bug type: Language Service

Describe the bug

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

Screenshots

Additional context

sean-mcmanus commented 3 years ago

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"].

Colengms commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

Yes, this seems to fix the issue

xclaesse commented 1 year ago

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.

sean-mcmanus commented 1 year ago

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

xclaesse commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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