https://github.com/mayanksinha17 updated https://github.com/llvm/llvm-project/pull/224925
>From 76b8efcbb8b92652d704b7cd6975ef3d2fb40008 Mon Sep 17 00:00:00 2001 From: Mayank Kumar Sinha <[email protected]> Date: Sun, 20 Sep 2026 18:09:49 +0530 Subject: [PATCH] Fix git-clang-format Python launcher on Windows --- .../test/Format/git-clang-format-windows.test | 19 +++++++++++++++++++ clang/tools/clang-format/git-clang-format.bat | 8 +++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 clang/test/Format/git-clang-format-windows.test diff --git a/clang/test/Format/git-clang-format-windows.test b/clang/test/Format/git-clang-format-windows.test new file mode 100644 index 0000000000000..b20e803deee56 --- /dev/null +++ b/clang/test/Format/git-clang-format-windows.test @@ -0,0 +1,19 @@ +// REQUIRES: system-windows + +// RUN: rm -rf %t.dir +// RUN: mkdir -p %t.dir/mock_bin + +// Case 1: python is in PATH, py and python3 are unavailable. +// RUN: echo @echo MOCK_PYTHON %%* > %t.dir/mock_bin/python.bat +// RUN: cmd /c "set PATH=%t.dir\mock_bin;%SystemRoot%\System32& \"%S/../../tools/clang-format/git-clang-format.bat\" --style=\"{BasedOnStyle: LLVM}\" \"test file.cpp\"" | FileCheck --check-prefix=CHECK-PYTHON %s +// CHECK-PYTHON: MOCK_PYTHON "{{.*}}git-clang-format" --style="{BasedOnStyle: LLVM}" "test file.cpp" + +// Case 2: python is unavailable, fallback to py -3. +// RUN: rm -f %t.dir/mock_bin/python.bat +// RUN: echo @echo MOCK_PY %%* > %t.dir/mock_bin/py.bat +// RUN: cmd /c "set PATH=%t.dir\mock_bin;%SystemRoot%\System32& \"%S/../../tools/clang-format/git-clang-format.bat\" --style=\"{BasedOnStyle: LLVM}\" \"test file.cpp\"" | FileCheck --check-prefix=CHECK-PY %s +// CHECK-PY: MOCK_PY -3 "{{.*}}git-clang-format" --style="{BasedOnStyle: LLVM}" "test file.cpp" + +// Case 3: Error exit code preservation (ensuring fallback is not executed on failure). +// RUN: echo @exit /b 42 > %t.dir/mock_bin/python.bat +// RUN: not cmd /c "set PATH=%t.dir\mock_bin;%SystemRoot%\System32& \"%S/../../tools/clang-format/git-clang-format.bat\"" diff --git a/clang/tools/clang-format/git-clang-format.bat b/clang/tools/clang-format/git-clang-format.bat index a40276e63c584..b6bd7c992561f 100644 --- a/clang/tools/clang-format/git-clang-format.bat +++ b/clang/tools/clang-format/git-clang-format.bat @@ -1 +1,7 @@ -py -3 "%~dpn0" %* +@echo off +where /q python +if not errorlevel 1 ( + python "%~dpn0" %* +) else ( + py -3 "%~dpn0" %* +) _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
