All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Schindelin <johannes.schindelin@gmx.de>
To: Dan Jacques <dnj@google.com>
Cc: git@vger.kernel.org, gitster@pobox.com
Subject: [PATCH 1/2] exec_cmd: provide a new-style RUNTIME_PREFIX helper for Windows
Date: Mon, 26 Mar 2018 23:31:38 +0200 (DST)	[thread overview]
Message-ID: <nycvar.QRO.7.76.6.1803262331370.77@ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz> (raw)
In-Reply-To: <20180325205120.17730-1-dnj@google.com>

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 f84e816..c944168 100644
--- a/Makefile
+++ b/Makefile
@@ -453,6 +453,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
@@ -1693,6 +1697,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 38d52d9..6e114f8 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.7.4


  parent reply	other threads:[~2018-03-26 21:31 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-25 20:51 [PATCH v7 0/3] RUNTIME_PREFIX relocatable Git Dan Jacques
2018-03-25 20:51 ` [PATCH v7 1/3] Makefile: generate Perl header from template file Dan Jacques
2018-03-25 20:51 ` [PATCH v7 2/3] Makefile: add Perl runtime prefix support Dan Jacques
2018-03-25 20:51 ` [PATCH v7 3/3] exec_cmd: RUNTIME_PREFIX on some POSIX systems Dan Jacques
2018-03-25 21:15 ` [PATCH v7 0/3] RUNTIME_PREFIX relocatable Git Ævar Arnfjörð Bjarmason
2018-03-26 13:03   ` Daniel Jacques
2018-03-26 14:08     ` Ævar Arnfjörð Bjarmason
2018-03-26 14:55       ` Daniel Jacques
2018-03-26  6:01 ` Junio C Hamano
2018-03-26 13:00   ` Daniel Jacques
2018-03-26 21:16     ` Johannes Schindelin
2018-03-26 21:31 ` [PATCH 0/2] Add Windows support to the new RUNTIME_PREFIX design Johannes Schindelin
2018-03-27 14:37   ` Daniel Jacques
2018-03-27 15:54     ` Johannes Schindelin
2018-03-27 16:05       ` Daniel Jacques
2018-03-27 16:28         ` Johannes Schindelin
2018-03-28 17:12         ` Junio C Hamano
2018-03-29 14:54           ` Johannes Schindelin
2018-03-26 21:31 ` Johannes Schindelin [this message]
2018-03-26 21:31 ` [PATCH 2/2] mingw/msvc: use the new-style RUNTIME_PREFIX helper Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=nycvar.QRO.7.76.6.1803262331370.77@ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz \
    --to=johannes.schindelin@gmx.de \
    --cc=dnj@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.