Skip to content

Commit eb05020

Browse files
committed
git (git-wrapper): use the built-time MSYSTEM value
The idea of the Git wrapper is that it is installed into various places (as part of the `mingw-w64-git-for-windows-addons` package), e.g. into `<msys64>\git-bash.exe`. This executable will then set up the required environment variables and spawn the actual `bash.exe`. Likewise, the Git wrapper is installed into `<msys64>\cmd\git.exe` where it can be called directly from, say, a PowerShell, without needing to add all the correct `PATH` entries and without setting `MSYSTEM`: the wrapper will do all that, and then spawn the actual `git.exe` in the correct subdirectory. Now, grace to Git for Windows' history, which started out before MSYS2 was invented and was based on MSys and MinGW instead, the actual logic grew organically. In the early days, when Git for Windows only supported i686 builds, all of those environment variable values were hardcoded. Later, when Git for Windows was moved on top of MSYS2, only two values were possible: "MINGW64" and "MINGW32". When timid steps were taken to support Windows/ARM64, a third option was added: "CLANGARM64". All this was unnecessary, though: The environment variable `MSYSTEM` is set when building the mingw-w64-git package, and it is guaranteed to be set to the very value the Git wrapper wants to use at run-time. So let's stop hard-coding the MINGW{32,64} values, and drop the hack we needed in Git for Windows while the clangarm64 builds were only experimental. Instead, just use the value in the environment variable `MSYSTEM` at build time, hard-coding _that_ into the binary. This will allow the Git wrapper to find the executables that were put into the corresponding `mingw-w64-git-*` packages. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent d799025 commit eb05020

File tree

3 files changed

+8
-61
lines changed

3 files changed

+8
-61
lines changed

mingw-w64-git/PKGBUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ sha256sums=('5f624e2511c445b832d9bbd65a74c27630be79994bf38dde4a4f8013d89e60e0'
6161
'a9dcba5aebc93ae7aacdee03275780fc6c0f15e88fda30c93041e75851e75090'
6262
'7e6c5f3dc6a4209dca0e1f38880b2978500a5c745c04bc60dbeda5fc48e8d3cb'
6363
'80b0b11efe5a2f9b4cd92f28c260d0b3aad8b809c34ed95237c59b73e08ade0b'
64-
'20613488bbd66bced2ef786448dc335c9cc7a5ef8be800e0d5bab83e36faf584'
64+
'26b54e0d45fc172424d941fe7b8b87ec8b5b81f15a71954ca212f4fc9887c8fb'
6565
'dab3e41e935a33f443a4ff4ef4ce92c191b6d952d9eb37e14885540ad5af99ed'
6666
'c975292adae1f2666f07f8ee9b7d50576da249d9151c6bd211602adc8d37b6ab'
6767
'53e630f581bee400100d074189754413afb6670ba1c09a5a3a09c5b575e41e60'
6868
'db754d6fe6722ad54d43df15ee93b1d9cead406158ed84dcbf35e5b4225469ed'
6969
'db754d6fe6722ad54d43df15ee93b1d9cead406158ed84dcbf35e5b4225469ed'
7070
'cbed8b133eb9eec9972f146be5c3ff49db29b2fff8ab9c87a6d0c646c08a5128'
7171
'027155aa6ca5f11ad7bcb89550a470935a9f22a9d5b3ab80a9eb209983258c1f'
72-
'386e965e184f657a5373b117c59e9e8711713e09177623a77718358cbc46296e'
72+
'b79173d806af70f211ce7b67684d8f82f5a2661e186eabf831935cf0f360c86d'
7373
'7413506c59d25621e475aa45447993748332c72cfbb4cf94cce6bee6f1218a09'
7474
'6d83e1cb1acdb6eb1f2d5cb9299298e57680f5ca43d43c3e67c9da17f21b9b01')
7575

mingw-w64-git/git-wrapper.c

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -114,48 +114,6 @@ static void my_path_append(LPWSTR list, LPCWSTR path, size_t alloc)
114114
}
115115
}
116116

117-
static int running_on_arm64 = -1;
118-
119-
static int is_running_on_arm64_hardware()
120-
{
121-
if (running_on_arm64 >= 0)
122-
return running_on_arm64;
123-
124-
USHORT process_machine = 0;
125-
USHORT native_machine = 0;
126-
127-
/* Note: IsWow64Process2 is only available in Windows 10 1511+ */
128-
BOOL (WINAPI* IsWow64Process2)(HANDLE, PUSHORT, PUSHORT) =
129-
(BOOL (WINAPI *)(HANDLE, PUSHORT, PUSHORT))
130-
GetProcAddress(GetModuleHandle(L"kernel32"), "IsWow64Process2");
131-
132-
running_on_arm64 = IsWow64Process2 &&
133-
IsWow64Process2(GetCurrentProcess(), &process_machine, &native_machine) &&
134-
native_machine == 0xaa64;
135-
136-
return running_on_arm64;
137-
}
138-
139-
static int is_running_on_arm64_msystem(LPWSTR top_level_path, LPWSTR msystem_bin)
140-
{
141-
int ret=0;
142-
size_t len = wcslen(top_level_path);
143-
144-
/* Does /clangarm64/bin exist? */
145-
my_path_append(top_level_path, L"clangarm64/bin", MAX_PATH);
146-
if (_waccess(top_level_path, 0) != -1) {
147-
wcscpy(msystem_bin, L"clangarm64/bin");
148-
ret=1;
149-
}
150-
top_level_path[len] = L'\0';
151-
return ret;
152-
}
153-
154-
static inline int is_running_on_arm64(LPWSTR top_level_path, LPWSTR msystem_bin)
155-
{
156-
return is_running_on_arm64_hardware() && is_running_on_arm64_msystem(top_level_path, msystem_bin);
157-
}
158-
159117
static int is_system32_path(LPWSTR path)
160118
{
161119
WCHAR system32[MAX_PATH];
@@ -165,20 +123,11 @@ static int is_system32_path(LPWSTR path)
165123

166124
static void setup_environment(LPWSTR top_level_path, int full_path)
167125
{
168-
WCHAR msystem[64];
169126
LPWSTR path2 = NULL;
170127
int len;
171128

172129
/* Set MSYSTEM */
173-
if (running_on_arm64 > 0) {
174-
swprintf(msystem, sizeof(msystem),
175-
L"CLANGARM64");
176-
} else {
177-
swprintf(msystem, sizeof(msystem),
178-
L"MINGW%d", (int)sizeof(void*) * 8);
179-
}
180-
181-
SetEnvironmentVariable(L"MSYSTEM", msystem);
130+
SetEnvironmentVariable(L"MSYSTEM", MSYSTEM);
182131

183132
/* if not set, set PLINK_PROTOCOL to ssh */
184133
if (!GetEnvironmentVariable(L"PLINK_PROTOCOL", NULL, 0))
@@ -633,8 +582,6 @@ static void initialize_top_level_path(LPWSTR top_level_path, LPWSTR exepath,
633582
while (strip_count) {
634583
if (strip_count < 0) {
635584
int len = wcslen(top_level_path);
636-
if (is_running_on_arm64(top_level_path, msystem_bin))
637-
return;
638585
my_path_append(top_level_path, msystem_bin, MAX_PATH);
639586
if (_waccess(top_level_path, 0) != -1) {
640587
/* We are in an MSys2-based setup */
@@ -665,8 +612,6 @@ static void initialize_top_level_path(LPWSTR top_level_path, LPWSTR exepath,
665612
if (strip_count > 0)
666613
--strip_count;
667614
}
668-
/* Only enable ARM64 support if <top-level>/arm64/bin/ exists */
669-
is_running_on_arm64(top_level_path, msystem_bin);
670615
}
671616

672617
static void maybe_read_config(LPWSTR top_level_path)
@@ -720,9 +665,10 @@ int main(void)
720665
LPWSTR working_directory = NULL;
721666
LPCWSTR prefix_args = NULL;
722667

723-
/* Determine MSys2-based Git path. */
724-
swprintf(msystem_bin, sizeof(msystem_bin),
725-
L"mingw%d\\bin", (int) sizeof(void *) * 8);
668+
/* Determine MSYS2-based `bin` path. */
669+
wcscpy(msystem_bin, MSYSTEM L"\\bin");
670+
for (wchar_t *p = msystem_bin; *p; p++)
671+
*p = towlower(*p);
726672
*top_level_path = L'\0';
727673

728674
/* get the installation location */

mingw-w64-git/mingw-w64-git.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ git-wrapper$(X): git-wrapper.o git.res
66

77
git-wrapper.o: %.o: ../%.c GIT-PREFIX
88
$(QUIET_CC)$(CC) $(ALL_CFLAGS) $(COMPAT_CFLAGS) \
9+
-DMSYSTEM=L"\"$(MSYSTEM)\"" \
910
-fno-stack-protector -o $*.o -c -Wall -Wwrite-strings $<
1011

1112
git-bash.res git-cmd.res git-wrapper.res gitk.res compat-bash.res tig.res: \

0 commit comments

Comments
 (0)