exec_cmd: provide a new-style RUNTIME_PREFIX helper for Windows
The RUNTIME_PREFIX feature comes from Git for Windows, but it was enhanced to allow support for other platforms. While changing the original idea, the concept was also improved by not forcing argv[0] to be adjusted. Let's allow the same for Windows by implementing a helper just as for the other platforms. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Apr 10, 2018 at 11:05 UTC
c1be1cb7ea064bae5ee1cd226aa42b767f2b52c4
2 files changed
+30
Makefile
+8
@@ -460,6 +460,10 @@ all::
460
# When using RUNTIME_PREFIX, define HAVE_NS_GET_EXECUTABLE_PATH if your platform
461
# supports calling _NSGetExecutablePath to retrieve the path of the running
462
# executable.
463
+#
464
+# When using RUNTIME_PREFIX, define HAVE_WPGMPTR if your platform offers
465
+# the global variable _wpgmptr containing the absolute path of the current
466
+# executable (this is the case on Windows).
467
468
GIT-VERSION-FILE: FORCE
469
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1703,6 +1707,10 @@ ifdef HAVE_NS_GET_EXECUTABLE_PATH
1707
BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH
1708
endif
1709
1710
+ifdef HAVE_WPGMPTR
1711
+ BASIC_CFLAGS += -DHAVE_WPGMPTR
1712
+endif
1713
+
1714
ifeq ($(TCLTK_PATH),)
1715
NO_TCLTK = NoThanks
1716
endif
exec_cmd.c
+22
@@ -144,6 +144,24 @@ static int git_get_exec_path_darwin(struct strbuf *buf)
144
}
145
#endif /* HAVE_NS_GET_EXECUTABLE_PATH */
146
147
+#ifdef HAVE_WPGMPTR
148
+/*
149
+ * Resolves the executable path by using the global variable _wpgmptr.
150
+ *
151
+ * Returns 0 on success, -1 on failure.
152
+ */
153
+static int git_get_exec_path_wpgmptr(struct strbuf *buf)
154
+{
155
+ int len = wcslen(_wpgmptr) * 3 + 1;
156
+ strbuf_grow(buf, len);
157
+ len = xwcstoutf(buf->buf, _wpgmptr, len);
158
+ if (len < 0)
159
+ return -1;
160
+ buf->len += len;
161
+ return 0;
162
+}
163
+#endif /* HAVE_WPGMPTR */
164
+
165
/*
166
* Resolves the absolute path of the current executable.
167
*
@@ -178,6 +196,10 @@ static int git_get_exec_path(struct strbuf *buf, const char *argv0)
196
git_get_exec_path_procfs(buf) &&
197
#endif /* PROCFS_EXECUTABLE_PATH */
198
199
+#ifdef HAVE_WPGMPTR
200
+ git_get_exec_path_wpgmptr(buf) &&
201
+#endif /* HAVE_WPGMPTR */
202
+
203
git_get_exec_path_from_argv0(buf, argv0)) {
204
return -1;
205
}