git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v8 4/5] exec_cmd: provide a new-style RUNTIME_PREFIX helper for Windows

From
Dan Jacques <dnj@google.com>
Date
Apr 10, 2018, 15:05 UTC
Message-ID
<20180410150546.38062-5-dnj@google.com>
In-Reply-To
<20180410150546.38062-1-dnj@google.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

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>
---
 Makefile   |  8 ++++++++
 exec_cmd.c | 22 ++++++++++++++++++++++
 2 files changed, 30 insertions(+)
diff --git a/Makefile b/Makefile
index 960541e77..8fc5559c7 100644
--- a/Makefile
+++ b/Makefile
@@ -460,6 +460,10 @@ all::
 # When using RUNTIME_PREFIX, define HAVE_NS_GET_EXECUTABLE_PATH if your platform
 # supports calling _NSGetExecutablePath to retrieve the path of the running
 # executable.
+#
+# When using RUNTIME_PREFIX, define HAVE_WPGMPTR if your platform offers
+# the global variable _wpgmptr containing the absolute path of the current
+# executable (this is the case on Windows).
 
 GIT-VERSION-FILE: FORCE
 	@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1700,6 +1704,10 @@ ifdef HAVE_NS_GET_EXECUTABLE_PATH
 	BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH
 endif
 
+ifdef HAVE_WPGMPTR
+	BASIC_CFLAGS += -DHAVE_WPGMPTR
+endif
+
 ifeq ($(TCLTK_PATH),)
 NO_TCLTK = NoThanks
 endif
diff --git a/exec_cmd.c b/exec_cmd.c
index 38d52d90a..6e114f8b3 100644
--- a/exec_cmd.c
+++ b/exec_cmd.c
@@ -144,6 +144,24 @@ static int git_get_exec_path_darwin(struct strbuf *buf)
 }
 #endif /* HAVE_NS_GET_EXECUTABLE_PATH */
 
+#ifdef HAVE_WPGMPTR
+/*
+ * Resolves the executable path by using the global variable _wpgmptr.
+ *
+ * Returns 0 on success, -1 on failure.
+ */
+static int git_get_exec_path_wpgmptr(struct strbuf *buf)
+{
+	int len = wcslen(_wpgmptr) * 3 + 1;
+	strbuf_grow(buf, len);
+	len = xwcstoutf(buf->buf, _wpgmptr, len);
+	if (len < 0)
+		return -1;
+	buf->len += len;
+	return 0;
+}
+#endif /* HAVE_WPGMPTR */
+
 /*
  * Resolves the absolute path of the current executable.
  *
@@ -178,6 +196,10 @@ static int git_get_exec_path(struct strbuf *buf, const char *argv0)
 		git_get_exec_path_procfs(buf) &&
 #endif /* PROCFS_EXECUTABLE_PATH */
 
+#ifdef HAVE_WPGMPTR
+		git_get_exec_path_wpgmptr(buf) &&
+#endif /* HAVE_WPGMPTR */
+
 		git_get_exec_path_from_argv0(buf, argv0)) {
 		return -1;
 	}
-- 
2.15.0.chromium12
Previous: Dan JacquesNext: Dan Jacques
Message 5 of 8 in “RUNTIME_PREFIX relocatable Git”
  1. 0/5 RUNTIME_PREFIX relocatable GitDan Jacques, Apr 10, 2018
  2. 1/5 Makefile: generate Perl header from template fileDan Jacques, Apr 10, 2018
  3. 2/5 Makefile: add Perl runtime prefix supportDan Jacques, Apr 10, 2018
  4. 3/5 exec_cmd: RUNTIME_PREFIX on some POSIX systemsDan Jacques, Apr 10, 2018
  5. 4/5 exec_cmd: provide a new-style RUNTIME_PREFIX helper for WindowsDan Jacques, Apr 10, 2018
  6. 5/5 mingw/msvc: use the new-style RUNTIME_PREFIX helperDan Jacques, Apr 10, 2018
  7. Junio C HamanoApr 11, 2018
  8. Ævar Arnfjörð BjarmasonApr 11, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.