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

--query-driver validation check does not understand shorthands like PROGRA~1 #1518

Open
ReasonJinMing opened this issue Feb 27, 2023 · 3 comments
Labels
windows Mostly or entirely affects windows users

Comments

@ReasonJinMing
Copy link

ReasonJinMing commented Feb 27, 2023

In Windows 10, It looks like clangd can't cope with spaces or some special symbol in the --query-driver path for system include extraction. I use mingw in windows, and the path to mingw is set under the Program Files folder. Here is a comparison, the gcc paths are the same, but one has spaces and the other does not.
I hope clangd can do the path replacement automatically in windows.

Logs
--query-driver with spaces clangd report System include extraction: not allowed driver

C:\Program Files\clangd_15.0.6\bin>clangd --check=C:\Users\lenovo\helloc\main.c --query-driver="C:\Program Files\RedPanda-Cpp\MinGW64\bin\gcc.exe" --log=verbose
I[09:52:18.655] clangd version 15.0.6 (https://github.com/llvm/llvm-project 088f33605d8a61ff519c580a71b1dd57d16a03f8)
I[09:52:18.657] Features: windows+grpc
I[09:52:18.658] PID: 6416
I[09:52:18.659] Working directory: C:\Program Files\clangd_15.0.6\bin
I[09:52:18.660] argv[0]: clangd
I[09:52:18.661] argv[1]: --check=C:\Users\lenovo\helloc\main.c
I[09:52:18.661] argv[2]: --query-driver=C:\Program Files\RedPanda-Cpp\MinGW64\bin\gcc.exe
I[09:52:18.662] argv[3]: --log=verbose
V[09:52:18.670] User config file is C:\Users\lenovo\AppData\Local\clangd\config.yaml
I[09:52:18.672] Entering check mode (no LSP server)
I[09:52:18.672] Testing on source file C:\Users\lenovo\helloc\main.c
I[09:52:18.687] Loading compilation database...
I[09:52:18.692] Loaded compilation database from C:\Users\lenovo\helloc\build/compile_commands.json
V[09:52:18.693] Broadcasting compilation database from C:\Users\lenovo\helloc
V[09:52:18.694] System include extraction: not allowed driver C:\PROGRA~1\REDPAN~1\MinGW64\bin\gcc.exe
I[09:52:18.696] Compile command from CDB is: "C:\\Program Files\\RedPanda-Cpp\\MinGW64\\bin\\gcc.exe" -g -std=gnu99 -o "CMakeFiles\\helloc.dir\\main.c.obj" -c "-resource-dir=C:\\Program Files\\clangd_15.0.6\\lib\\clang\\15.0.6" -- "C:\\Users\\lenovo\\helloc\\main.c"

--query-driver without spaces clangd report System includes extractor: successfully executed

C:\Program Files\clangd_15.0.6\bin>clangd --check=C:\Users\lenovo\helloc\main.c --query-driver="C:\PROGRA~1\REDPAN~1\MinGW64\bin\gcc.exe" --log=verbose
I[10:00:32.309] clangd version 15.0.6 (https://github.com/llvm/llvm-project 088f33605d8a61ff519c580a71b1dd57d16a03f8)
I[10:00:32.311] Features: windows+grpc
I[10:00:32.312] PID: 1116
I[10:00:32.313] Working directory: C:\Program Files\clangd_15.0.6\bin
I[10:00:32.314] argv[0]: clangd
I[10:00:32.314] argv[1]: --check=C:\Users\lenovo\helloc\main.c
I[10:00:32.315] argv[2]: --query-driver=C:\PROGRA~1\REDPAN~1\MinGW64\bin\gcc.exe
I[10:00:32.316] argv[3]: --log=verbose
V[10:00:32.328] User config file is C:\Users\lenovo\AppData\Local\clangd\config.yaml
I[10:00:32.330] Entering check mode (no LSP server)
I[10:00:32.331] Testing on source file C:\Users\lenovo\helloc\main.c
I[10:00:32.335] Loading compilation database...
I[10:00:32.340] Loaded compilation database from C:\Users\lenovo\helloc\build/compile_commands.json
V[10:00:32.341] Broadcasting compilation database from C:\Users\lenovo\helloc
V[10:00:32.372] System include extraction: target extracted: "x86_64-w64-mingw32"
V[10:00:32.373] System include extraction: adding  C:/PROGRA~1/REDPAN~1/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/include
V[10:00:32.375] System include extraction: adding  C:/PROGRA~1/REDPAN~1/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/include-fixed
V[10:00:32.377] System include extraction: adding  C:/PROGRA~1/REDPAN~1/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/include
I[10:00:32.378] System includes extractor: successfully executed C:\PROGRA~1\REDPAN~1\MinGW64\bin\gcc.exe
        got includes: "C:/PROGRA~1/REDPAN~1/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/include, C:/PROGRA~1/REDPAN~1/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/include-fixed, C:/PROGRA~1/REDPAN~1/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/include"
        got target: "x86_64-w64-mingw32"
I[10:00:32.383] Compile command from CDB is: "C:\\Program Files\\RedPanda-Cpp\\MinGW64\\bin\\gcc.exe" -g -std=gnu99 -o "CMakeFiles\\helloc.dir\\main.c.obj" -c -isystem C:/PROGRA~1/REDPAN~1/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/include -isystem C:/PROGRA~1/REDPAN~1/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/include-fixed -isystem C:/PROGRA~1/REDPAN~1/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/include --target=x86_64-w64-mingw32 "-resource-dir=C:\\Program Files\\clangd_15.0.6\\lib\\clang\\15.0.6" -- "C:\\Users\\lenovo\\helloc\\main.c"
I[10:00:32.384] Parsing command...

if I remove spaces and keep the symbol -, I also have the same problem.

C:\Program Files\clangd_15.0.6\bin>clangd --check=C:\Users\lenovo\helloc\main.c --query-driver="C:\PROGRA~1\RedPanda-Cpp\MinGW64\bin\gcc.exe" --log=verbose
I[10:48:24.066] clangd version 15.0.6 (https://github.com/llvm/llvm-project 088f33605d8a61ff519c580a71b1dd57d16a03f8)
I[10:48:24.068] Features: windows+grpc
I[10:48:24.069] PID: 612
I[10:48:24.071] Working directory: C:\Program Files\clangd_15.0.6\bin
I[10:48:24.073] argv[0]: clangd
I[10:48:24.075] argv[1]: --check=C:\Users\lenovo\helloc\main.c
I[10:48:24.079] argv[2]: --query-driver=C:\PROGRA~1\RedPanda-Cpp\MinGW64\bin\gcc.exe
I[10:48:24.080] argv[3]: --log=verbose
V[10:48:24.086] User config file is C:\Users\lenovo\AppData\Local\clangd\config.yaml
I[10:48:24.087] Entering check mode (no LSP server)
I[10:48:24.088] Testing on source file C:\Users\lenovo\helloc\main.c
I[10:48:24.091] Loading compilation database...
I[10:48:24.096] Loaded compilation database from C:\Users\lenovo\helloc\build/compile_commands.json
V[10:48:24.096] Broadcasting compilation database from C:\Users\lenovo\helloc
V[10:48:24.097] System include extraction: not allowed driver C:\PROGRA~1\REDPAN~1\MinGW64\bin\gcc.exe
I[10:48:24.099] Compile command from CDB is: "C:\\Program Files\\RedPanda-Cpp\\MinGW64\\bin\\gcc.exe" -g -std=gnu99 -o "CMakeFiles\\helloc.dir\\main.c.obj" -c "-resource-dir=C:\\Program Files\\clangd_15.0.6\\lib\\clang\\15.0.6" -- "C:\\Users\\lenovo\\helloc\\main.c"
I[10:48:24.102] Parsing command...

System information
Win10 LTSC 2019 in vmware

Output of clangd --version:

clangd version 15.0.6 (https://github.com/llvm/llvm-project 088f33605d8a61ff519c580a71b1dd57d16a03f8)
Features: windows+grpc
Platform: x86_64-pc-windows-msvc

Editor/LSP plugin:
vscode + clangd + cmake tools
Operating system:

@ReasonJinMing ReasonJinMing changed the title the path for --query-driver can't have spaces in Windows the path for --query-driver can't have spaces int it on Windows Feb 27, 2023
@ReasonJinMing ReasonJinMing changed the title the path for --query-driver can't have spaces int it on Windows the path for --query-driver can't have spaces in it on Windows Feb 27, 2023
@HighCommander4
Copy link

The issue isn't so much that the argument to --query-driver can't have spaces in it, it's that this line from the logs:

V[09:52:18.694] System include extraction: not allowed driver C:\PROGRA~1\REDPAN~1\MinGW64\bin\gcc.exe

tells us that the actual driver path that clangd is trying to use, which it gets from the compilation database, is C:\PROGRA~1\REDPAN~1\MinGW64\bin\gcc.exe. It is this path that clangd then tries to compare against the argument of --query-driver, and the comparison fails.

The comparison is currently a plain string comparison, it's not aware of the fact that e.g. PROGRA~1 is a shorthand for Program Files.

Could the comparison be reworked to understand that? Probably, though I'm not familiar with the relevant path-related APIs (possibly Windows-specific APIs would need to be used).

Anyways, a workaround is to look in the logs for "not allowed driver" message, and use the path from there in --query-driver. You can also use a glob, e.g. --query-driver=C:\**\MinGW64\bin\gcc.exe.

@HighCommander4 HighCommander4 changed the title the path for --query-driver can't have spaces in it on Windows --query-driver validation check does not understand shorthands like PROGRA~1 Feb 27, 2023
@HighCommander4 HighCommander4 added the windows Mostly or entirely affects windows users label Feb 27, 2023
@ReasonJinMing
Copy link
Author

The issue isn't so much that the argument to --query-driver can't have spaces in it, it's that this line from the logs:

V[09:52:18.694] System include extraction: not allowed driver C:\PROGRA~1\REDPAN~1\MinGW64\bin\gcc.exe

tells us that the actual driver path that clangd is trying to use, which it gets from the compilation database, is C:\PROGRA~1\REDPAN~1\MinGW64\bin\gcc.exe. It is this path that clangd then tries to compare against the argument of --query-driver, and the comparison fails.

The comparison is currently a plain string comparison, it's not aware of the fact that e.g. PROGRA~1 is a shorthand for Program Files.

Could the comparison be reworked to understand that? Probably, though I'm not familiar with the relevant path-related APIs (possibly Windows-specific APIs would need to be used).

Anyways, a workaround is to look in the logs for "not allowed driver" message, and use the path from there in --query-driver. You can also use a glob, e.g. --query-driver=C:\**\MinGW64\bin\gcc.exe.

Thank you for your precise answers.
I think the problem is that the not allowed driver hint might give us the wrong information.When I first met it, my immediate thoughts were that I had the wrong compiler.I can hardly imagine that the problem is the mismatch of path of complier between compilation database and --query-driver.

@dogtopus
Copy link

dogtopus commented Mar 18, 2023

The comparison is currently a plain string comparison, it's not aware of the fact that e.g. PROGRA~1 is a shorthand for Program Files.

This also causes other issues like patterns with mixed forward/backward slashes fail to match anything, breaks setup that invokes toolchain from a workspace-relative directory under vscode. (e.g. ${workspaceFolder}/toolchain/bin/arm-none-eabi-* on vscode-clangd matches fine on *NIX but fails on Windows due to ${workspaceFolder} being expanded to something like C:\Users\user\Documents\my_project causing the whole pattern to be interpreted as something like C:\Users\user\Documents\my_project/toolchain/bin/arm-none-eabi-* when the actual compile DB contains canonical paths only, causing the match to fail).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
windows Mostly or entirely affects windows users
Projects
None yet
Development

No branches or pull requests

3 participants