https://github.com/MathiasMagnus created 
https://github.com/llvm/llvm-project/pull/114078

The trampoline script used on Windows (due to the absence of shebang support) 
doesn't properly expand the path to the Python script, as it leaves out the 
drive letter.

Functionally equivalent reproducer in action
```
PS C:\Users\mate> gc (gcm git-clang-formatish.bat).Source
@ECHO OFF
echo "%~pn0" %*
PS C:\Users\mate> git-clang-formatish
"\Users\mate\git-clang-formatish"
```

Adding `d` to the variable modifiers [as per the 
docs](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/for)
 the drive letter is added. Even in the magical cases when it works.

(I couldn't reproduce, but I suspect it's only tested from some bash/cygwin 
variant, where the path becomes `/c/Program Files/...`, but the drive letter is 
needed. Without it, I also observed cases when used via `git clang-format` 
(without the inital dash) it tries to infer the drive letter based on the 
current working directory. In that case it fails to find `D:\Program 
Files\LLVM\bin\clang-format.exe`, which naturally fails, because `Program 
Files` is on `C:`)

From 9a6a029cc06596ad020963a3d453df757e194120 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A1t=C3=A9=20Ferenc=20Nagy-Egri?= <m...@rastergrid.com>
Date: Tue, 29 Oct 2024 16:57:57 +0100
Subject: [PATCH] [clang-format] Expand drive letter in trampoline

---
 clang/tools/clang-format/git-clang-format.bat | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/clang-format/git-clang-format.bat 
b/clang/tools/clang-format/git-clang-format.bat
index 19c82d8a04132b..a40276e63c5848 100644
--- a/clang/tools/clang-format/git-clang-format.bat
+++ b/clang/tools/clang-format/git-clang-format.bat
@@ -1 +1 @@
-py -3 "%~pn0" %*
+py -3 "%~dpn0" %*

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to