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

clangd --query-driver doesn't seem to work with double slashes #62506

Closed
JoseGuilhermeCR opened this issue May 3, 2023 · 7 comments
Closed
Labels
clangd question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

Comments

@JoseGuilhermeCR
Copy link

JoseGuilhermeCR commented May 3, 2023

Hello there!

I've got some issues on setting up clangd on Windows and I've read a lot of issues, the clangd documentation itself and even the source code to try and figure out what is happening. This doesn't happen on Linux, it works flawlessly everytime there.

I'm using the arm-none-eabi toolchain, together with CMake and Ninja.
CMake is generating the following paths, found in compile_commands.json.

{
  "directory": "C:/Desenvolvimento",
  "command": "C:\\Programas\\arm-gnu-toolchain\\bin\\arm-none-eabi-gcc.exe <...>,
  "file": <...>,
  "output": <...>
},

The command key has a value with the path of the compiler, using \\.

My clangd is set up as:

I[22:52:39.070] clangd version 16.0.0
I[22:52:39.071] Features: windows
I[22:52:39.071] PID: 920
I[22:52:39.071] Working directory: c:\Desenvolvimento
I[22:52:39.071] argv[0]: C:\Programas\LLVM\bin\clangd.EXE
I[22:52:39.071] argv[1]: --log=verbose
I[22:52:39.071] argv[2]: --query-driver="C:\\Programas\\arm-gnu-toolchain\\bin\\arm-none-eabi-g*"

That seems about right... I'm using two backwards slashes in compile_commands.json (which is generated for me), and I literally copied the path and placed it in the query-driver adding a glob at the end. However, it doesn't work:

I[22:52:39.257] <-- textDocument/didOpen
V[22:52:39.257] System include extraction: driver clang expanded to C:\Programas\LLVM\bin\clang.exe
V[22:52:39.257] System include extraction: not allowed driver C:\Programas\LLVM\bin\clang.exe
V[22:52:39.261] <<< {"jsonrpc":"2.0","method":"$/setTrace","params":{"value":"off"}}

I[22:52:39.261] <-- $/setTrace
I[22:52:39.261] unhandled notification $/setTrace
I[22:52:39.261] Loaded compilation database from c:\Desenvolvimento\build/compile_commands.json
V[22:52:39.261] Broadcasting compilation database from c:\Desenvolvimento
V[22:52:39.262] System include extraction: not allowed driver C:\Programas\arm-gnu-toolchain\bin\arm-none-eabi-g++.exe

As you can see, it says the driver is not allowed and then prints the driver using only one backward slash... and that's my guess as to why it isn't working.

Line 299 at SystemIncludeExtractor.cpp is where things go wrong.

Can I get some help on this? I don't know if it's a mistake or it's a bug. The thing is that in the end of the day I can't get it to work on Windows.

edit: Note that the letter C from C:\ is capitalized in some paths, while not capitalized in others... Don't know if that could be the source of the problem too.

edit2: Can confirm that by changing the \\ slashes in compile_commands.json to / and setting the query-driver to use / as well, it works, but that makes the configuration manual.

@JoseGuilhermeCR
Copy link
Author

Ok, so using \\ instead of \ in the query-driver solves the problem Which... well.. isn't well documented anywhere. All everyone says is that it should match exactly what exists in compile_commands.json... which is \\.

For anyone that got here. Don't double the backward slashes in --query-driver. Use only one backward slash.
Like:

--query-driver=C:\Programas\arm-gnu-toolchain\bin\arm-none-eabi-g*

Not Like:

--query-driver=C:\\Programas\\arm-gnu-toolchain\\bin\\arm-none-eabi-g*

@EugeneZelenko EugeneZelenko added question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! clangd and removed new issue labels May 3, 2023
@llvmbot
Copy link
Member

llvmbot commented May 3, 2023

@llvm/issue-subscribers-clangd

@HighCommander4
Copy link
Collaborator

Some similar issues are clangd/clangd#1518 and clangd/clangd#1605. Basically, clangd should ideally perform some sort of path normalization on the value of --query-driver before comparing it to the path of the actual driver, rather than doing a plain string comparison.

@JoseGuilhermeCR
Copy link
Author

Yes, I'm aware there are issues with both solutions: doing more than a plain string comparison and doing only it. However, I do think it's a good idea to give an example of a Windows path in the query-driver section.

That's because, in Windows, copying the path found in compile_commands.json is not enough. That path uses \ as a escape character for \, and this isn't needed in the query-driver option itself. If someone were to take a look at the example, they would find it out in an faster way.

@HighCommander4
Copy link
Collaborator

I do think it's a good idea to give an example of a Windows path in the query-driver section.

I'm supportive of adding such an example.

Are you interested in submitting a documentation patch? The source file is https://github.com/llvm/clangd-www/blob/main/guides/system-headers.md

@JoseGuilhermeCR
Copy link
Author

I most definitely am! I will take a look at the contribution guide as soon as I have the time and try to submit a documentation patch. Thank you for the source file reference.

@sam-mccall
Copy link
Collaborator

All everyone says is that it should match exactly what exists in compile_commands.json... which is \.

For the record, the command string described by your compile_commands.json has only a single backslash.
The second one is just the escaping required for strings in the JSON format.
If this is confusing, better to open compile_commands.json in a GUI JSON editor, rather than a text editor, before copying strings out of it.

That said, #66757 will accidentally make the C:\\foo\\bar work, because along with removing . and .. we'll also drop duplicate path separators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clangd question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Projects
None yet
Development

No branches or pull requests

5 participants