Skip to content

[Windows] Add git-clang-format wrapper bat file #69228

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

Merged
merged 1 commit into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions clang/tools/clang-format/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ install(FILES clang-format.py
install(PROGRAMS git-clang-format
DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT clang-format)

if (WIN32 AND NOT CYGWIN)
install(PROGRAMS git-clang-format.bat
DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT clang-format)
endif()
1 change: 1 addition & 0 deletions clang/tools/clang-format/git-clang-format.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
py -3 git-clang-format %*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is py? I have no program called py on my machine (Windows with msys2), so you would possibly break that? Why not write python or python3?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

py.exe is the Windows python launcher. It comes with Python for Windows (not msys2 or cygwin where the shebang line would work). It is the Windows way of choosing which python version you want. You need to use this approach because the standard Python for Windows install always installs python.exe regardless of version because Windows generally doesn't version binaries.

[1] Python for Windows docs
[2] Microsoft docs

I'm going to go take a long shower now to try and forget that I learned this much about Windows.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@llvm-beanz This doesn't seem to work if git-clang-format is run from another directory:

C:\Users\Owen\llvm-project>clang\tools\clang-format\git-clang-format

C:\Users\Owen\llvm-project>py -3 git-clang-format
C:\Users\Owen\AppData\Local\Programs\Python\Python39\python.exe: can't open file 'C:\Users\Owen\llvm-project\git-clang-format': [Errno 2] No such file or directory

C:\Users\Owen\llvm-project>