Skip to content

Commit aa56ade

Browse files
committed
Merge branch 'dj/runtime-prefix'
This topic branch first reverts a couple of conflicting patches and then cherry-picks Dan Jacques' patches to support RUNTIME_PREFIX also on other platforms than Windows. The original patches are already well under way into the next Git version, and we just take them early to give it a bit more testing. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 7e4058d + 016b860 commit aa56ade

File tree

14 files changed

+419
-65
lines changed

14 files changed

+419
-65
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/GIT-LDFLAGS
44
/GIT-PREFIX
55
/GIT-PERL-DEFINES
6+
/GIT-PERL-HEADER
67
/GIT-PYTHON-VARS
78
/GIT-SCRIPT-DEFINES
89
/GIT-USER-AGENT

Makefile

Lines changed: 114 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,29 @@ all::
434434
#
435435
# When cross-compiling, define HOST_CPU as the canonical name of the CPU on
436436
# which the built Git will run (for instance "x86_64").
437+
#
438+
# Define RUNTIME_PREFIX to configure Git to resolve its ancillary tooling and
439+
# support files relative to the location of the runtime binary, rather than
440+
# hard-coding them into the binary. Git installations built with RUNTIME_PREFIX
441+
# can be moved to arbitrary filesystem locations. RUNTIME_PREFIX also causes
442+
# Perl scripts to use a modified entry point header allowing them to resolve
443+
# support files at runtime.
444+
#
445+
# When using RUNTIME_PREFIX, define HAVE_BSD_KERN_PROC_SYSCTL if your platform
446+
# supports the KERN_PROC BSD sysctl function.
447+
#
448+
# When using RUNTIME_PREFIX, define PROCFS_EXECUTABLE_PATH if your platform
449+
# mounts a "procfs" filesystem capable of resolving the path of the current
450+
# executable. If defined, this must be the canonical path for the "procfs"
451+
# current executable path.
452+
#
453+
# When using RUNTIME_PREFIX, define HAVE_NS_GET_EXECUTABLE_PATH if your platform
454+
# supports calling _NSGetExecutablePath to retrieve the path of the running
455+
# executable.
456+
#
457+
# When using RUNTIME_PREFIX, define HAVE_WPGMPTR if your platform offers
458+
# the global variable _wpgmptr containing the absolute path of the current
459+
# executable (this is the case on Windows).
437460

438461
GIT-VERSION-FILE: FORCE
439462
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -471,6 +494,8 @@ ARFLAGS = rcs
471494
# mandir
472495
# infodir
473496
# htmldir
497+
# localedir
498+
# perllibdir
474499
# This can help installing the suite in a relocatable way.
475500

476501
prefix = $(HOME)
@@ -492,10 +517,12 @@ lib = lib
492517
# DESTDIR =
493518
pathsep = :
494519

495-
localedir_relative = $(patsubst $(prefix)/%,%,$(localedir))
496520
mandir_relative = $(patsubst $(prefix)/%,%,$(mandir))
497521
infodir_relative = $(patsubst $(prefix)/%,%,$(infodir))
522+
gitexecdir_relative = $(patsubst $(prefix)/%,%,$(gitexecdir))
523+
localedir_relative = $(patsubst $(prefix)/%,%,$(localedir))
498524
htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir))
525+
perllibdir_relative = $(patsubst $(prefix)/%,%,$(perllibdir))
499526

500527
export prefix bindir sharedir sysconfdir gitwebdir perllibdir localedir
501528

@@ -1654,10 +1681,27 @@ ifdef HAVE_BSD_SYSCTL
16541681
BASIC_CFLAGS += -DHAVE_BSD_SYSCTL
16551682
endif
16561683

1684+
ifdef HAVE_BSD_KERN_PROC_SYSCTL
1685+
BASIC_CFLAGS += -DHAVE_BSD_KERN_PROC_SYSCTL
1686+
endif
1687+
16571688
ifdef HAVE_GETDELIM
16581689
BASIC_CFLAGS += -DHAVE_GETDELIM
16591690
endif
16601691

1692+
ifneq ($(PROCFS_EXECUTABLE_PATH),)
1693+
procfs_executable_path_SQ = $(subst ','\'',$(PROCFS_EXECUTABLE_PATH))
1694+
BASIC_CFLAGS += '-DPROCFS_EXECUTABLE_PATH="$(procfs_executable_path_SQ)"'
1695+
endif
1696+
1697+
ifdef HAVE_NS_GET_EXECUTABLE_PATH
1698+
BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH
1699+
endif
1700+
1701+
ifdef HAVE_WPGMPTR
1702+
BASIC_CFLAGS += -DHAVE_WPGMPTR
1703+
endif
1704+
16611705
ifeq ($(TCLTK_PATH),)
16621706
NO_TCLTK = NoThanks
16631707
endif
@@ -1747,6 +1791,7 @@ gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
17471791
template_dir_SQ = $(subst ','\'',$(template_dir))
17481792
htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative))
17491793
prefix_SQ = $(subst ','\'',$(prefix))
1794+
perllibdir_relative_SQ = $(subst ','\'',$(perllibdir_relative))
17501795
gitwebdir_SQ = $(subst ','\'',$(gitwebdir))
17511796

17521797
SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
@@ -1757,6 +1802,31 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
17571802
DIFF_SQ = $(subst ','\'',$(DIFF))
17581803
PERLLIB_EXTRA_SQ = $(subst ','\'',$(PERLLIB_EXTRA))
17591804

1805+
# RUNTIME_PREFIX's resolution logic requires resource paths to be expressed
1806+
# relative to each other and share an installation path.
1807+
#
1808+
# This is a dependency in:
1809+
# - Git's binary RUNTIME_PREFIX logic in (see "exec_cmd.c").
1810+
# - The runtime prefix Perl header (see
1811+
# "perl/header_templates/runtime_prefix.template.pl").
1812+
ifdef RUNTIME_PREFIX
1813+
1814+
ifneq ($(filter /%,$(firstword $(gitexecdir_relative))),)
1815+
$(error RUNTIME_PREFIX requires a relative gitexecdir, not: $(gitexecdir))
1816+
endif
1817+
1818+
ifneq ($(filter /%,$(firstword $(localedir_relative))),)
1819+
$(error RUNTIME_PREFIX requires a relative localedir, not: $(localedir))
1820+
endif
1821+
1822+
ifndef NO_PERL
1823+
ifneq ($(filter /%,$(firstword $(perllibdir_relative))),)
1824+
$(error RUNTIME_PREFIX requires a relative perllibdir, not: $(perllibdir))
1825+
endif
1826+
endif
1827+
1828+
endif
1829+
17601830
# We must filter out any object files from $(GITLIBS),
17611831
# as it is typically used like:
17621832
#
@@ -1977,34 +2047,64 @@ git.res: git.rc GIT-VERSION-FILE GIT-PREFIX
19772047
# This makes sure we depend on the NO_PERL setting itself.
19782048
$(SCRIPT_PERL_GEN): GIT-BUILD-OPTIONS
19792049

1980-
ifndef NO_PERL
1981-
$(SCRIPT_PERL_GEN):
2050+
# Used for substitution in Perl modules. Disabled when using RUNTIME_PREFIX
2051+
# since the locale directory is injected.
2052+
perl_localedir_SQ = $(localedir_SQ)
19822053

2054+
ifndef NO_PERL
2055+
PERL_HEADER_TEMPLATE = perl/header_templates/fixed_prefix.template.pl
19832056
PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ):$(perllibdir_SQ)
1984-
$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-VERSION-FILE
2057+
2058+
PERL_DEFINES := $(PERL_PATH_SQ) $(PERLLIB_EXTRA_SQ) $(perllibdir_SQ)
2059+
PERL_DEFINES += $(RUNTIME_PREFIX)
2060+
2061+
# Support Perl runtime prefix. In this mode, a different header is installed
2062+
# into Perl scripts.
2063+
ifdef RUNTIME_PREFIX
2064+
2065+
PERL_HEADER_TEMPLATE = perl/header_templates/runtime_prefix.template.pl
2066+
2067+
# Don't export a fixed $(localedir) path; it will be resolved by the Perl header
2068+
# at runtime.
2069+
perl_localedir_SQ =
2070+
2071+
endif
2072+
2073+
PERL_DEFINES += $(gitexecdir) $(perllibdir) $(localedir)
2074+
2075+
$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE
19852076
$(QUIET_GEN)$(RM) $@ $@+ && \
1986-
INSTLIBDIR='$(perllibdir_SQ)' && \
1987-
INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \
1988-
INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \
19892077
sed -e '1{' \
19902078
-e ' s|#!.*perl|#!$(PERL_PATH_SQ)|' \
1991-
-e ' h' \
1992-
-e ' s=.*=use lib (split(/$(pathsep)/, $$ENV{GITPERLLIB} || "'"$$INSTLIBDIR"'"));=' \
1993-
-e ' H' \
1994-
-e ' x' \
2079+
-e ' rGIT-PERL-HEADER' \
2080+
-e ' G' \
19952081
-e '}' \
19962082
-e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
19972083
$< >$@+ && \
19982084
chmod +x $@+ && \
19992085
mv $@+ $@
20002086

2087+
PERL_DEFINES := $(subst $(space),:,$(PERL_DEFINES))
20012088
GIT-PERL-DEFINES: FORCE
20022089
@FLAGS='$(PERL_DEFINES)'; \
20032090
if test x"$$FLAGS" != x"`cat $@ 2>/dev/null`" ; then \
20042091
echo >&2 " * new perl-specific parameters"; \
20052092
echo "$$FLAGS" >$@; \
20062093
fi
20072094

2095+
GIT-PERL-HEADER: $(PERL_HEADER_TEMPLATE) GIT-PERL-DEFINES Makefile
2096+
$(QUIET_GEN)$(RM) $@ && \
2097+
INSTLIBDIR='$(perllibdir_SQ)' && \
2098+
INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \
2099+
INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \
2100+
sed -e 's=@@PATHSEP@@=$(pathsep)=g' \
2101+
-e 's=@@INSTLIBDIR@@='$$INSTLIBDIR'=g' \
2102+
-e 's=@@PERLLIBDIR@@='$(perllibdir_SQ)'=g' \
2103+
-e 's=@@PERLLIBDIR_REL@@=$(perllibdir_relative_SQ)=g' \
2104+
-e 's=@@GITEXECDIR_REL@@=$(gitexecdir_relative_SQ)=g' \
2105+
-e 's=@@LOCALEDIR_REL@@=$(localedir_relative_SQ)=g' \
2106+
$< >$@+ && \
2107+
mv $@+ $@
20082108

20092109
.PHONY: gitweb
20102110
gitweb:
@@ -2149,6 +2249,7 @@ endif
21492249
exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX
21502250
exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
21512251
'-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
2252+
'-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \
21522253
'-DBINDIR="$(bindir_relative_SQ)"' \
21532254
'-DFALLBACK_RUNTIME_PREFIX="$(prefix_SQ)"'
21542255

@@ -2326,7 +2427,7 @@ endif
23262427

23272428
perl/build/lib/%.pm: perl/%.pm
23282429
$(QUIET_GEN)mkdir -p $(dir $@) && \
2329-
sed -e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' \
2430+
sed -e 's|@@LOCALEDIR@@|$(perl_localedir_SQ)|g' \
23302431
-e 's|@@NO_PERL_CPAN_FALLBACKS@@|$(NO_PERL_CPAN_FALLBACKS_SQ)|g' \
23312432
< $< > $@
23322433

@@ -2801,7 +2902,7 @@ ifndef NO_TCLTK
28012902
endif
28022903
$(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS
28032904
$(RM) GIT-USER-AGENT GIT-PREFIX
2804-
$(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PYTHON-VARS
2905+
$(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS
28052906
ifdef MSVC
28062907
$(RM) $(patsubst %.o,%.o.pdb,$(OBJECTS))
28072908
$(RM) $(patsubst %.exe,%.pdb,$(OTHER_PROGRAMS))

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ static inline enum object_type object_type(unsigned int mode)
428428
#define GIT_ICASE_PATHSPECS_ENVIRONMENT "GIT_ICASE_PATHSPECS"
429429
#define GIT_QUARANTINE_ENVIRONMENT "GIT_QUARANTINE_PATH"
430430
#define GIT_OPTIONAL_LOCKS_ENVIRONMENT "GIT_OPTIONAL_LOCKS"
431+
#define GIT_TEXT_DOMAIN_DIR_ENVIRONMENT "GIT_TEXTDOMAINDIR"
431432

432433
/*
433434
* Environment variable used in handshaking the wire protocol.

common-main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int main(int argc, const char **argv)
3232
*/
3333
sanitize_stdfds();
3434

35-
git_extract_argv0_path(argv[0]);
35+
git_resolve_executable_dir(argv[0]);
3636

3737
git_setup_gettext();
3838

compat/mingw.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3454,7 +3454,7 @@ void mingw_startup(void)
34543454
die_startup();
34553455

34563456
/* determine size of argv and environ conversion buffer */
3457-
maxlen = wcslen(_wpgmptr);
3457+
maxlen = wcslen(wargv[0]);
34583458
for (i = 1; i < argc; i++)
34593459
maxlen = max(maxlen, wcslen(wargv[i]));
34603460
for (i = 0; wenv[i]; i++)
@@ -3474,8 +3474,7 @@ void mingw_startup(void)
34743474
buffer = malloc_startup(maxlen);
34753475

34763476
/* convert command line arguments and environment to UTF-8 */
3477-
__argv[0] = wcstoutfdup_startup(buffer, _wpgmptr, maxlen);
3478-
for (i = 1; i < argc; i++)
3477+
for (i = 0; i < argc; i++)
34793478
__argv[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
34803479
for (i = 0; wenv[i]; i++)
34813480
environ[i] = wcstoutfdup_startup(buffer, wenv[i], maxlen);

config.mak.uname

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ ifeq ($(uname_S),Linux)
5656
HAVE_GETDELIM = YesPlease
5757
SANE_TEXT_GREP=-a
5858
FREAD_READS_DIRECTORIES = UnfortunatelyYes
59+
PROCFS_EXECUTABLE_PATH = /proc/self/exe
5960
endif
6061
ifeq ($(uname_S),GNU/kFreeBSD)
6162
HAVE_ALLOCA_H = YesPlease
@@ -130,6 +131,7 @@ ifeq ($(uname_S),Darwin)
130131
BASIC_CFLAGS += -DPROTECT_HFS_DEFAULT=1
131132
HAVE_BSD_SYSCTL = YesPlease
132133
FREAD_READS_DIRECTORIES = UnfortunatelyYes
134+
HAVE_NS_GET_EXECUTABLE_PATH = YesPlease
133135
endif
134136
ifeq ($(uname_S),SunOS)
135137
NEEDS_SOCKET = YesPlease
@@ -224,6 +226,7 @@ ifeq ($(uname_S),FreeBSD)
224226
HAVE_PATHS_H = YesPlease
225227
GMTIME_UNRELIABLE_ERRORS = UnfortunatelyYes
226228
HAVE_BSD_SYSCTL = YesPlease
229+
HAVE_BSD_KERN_PROC_SYSCTL = YesPlease
227230
PAGER_ENV = LESS=FRX LV=-c MORE=FRX
228231
FREAD_READS_DIRECTORIES = UnfortunatelyYes
229232
endif
@@ -236,6 +239,8 @@ ifeq ($(uname_S),OpenBSD)
236239
BASIC_LDFLAGS += -L/usr/local/lib
237240
HAVE_PATHS_H = YesPlease
238241
HAVE_BSD_SYSCTL = YesPlease
242+
HAVE_BSD_KERN_PROC_SYSCTL = YesPlease
243+
PROCFS_EXECUTABLE_PATH = /proc/curproc/file
239244
endif
240245
ifeq ($(uname_S),MirBSD)
241246
NO_STRCASESTR = YesPlease
@@ -254,6 +259,8 @@ ifeq ($(uname_S),NetBSD)
254259
USE_ST_TIMESPEC = YesPlease
255260
HAVE_PATHS_H = YesPlease
256261
HAVE_BSD_SYSCTL = YesPlease
262+
HAVE_BSD_KERN_PROC_SYSCTL = YesPlease
263+
PROCFS_EXECUTABLE_PATH = /proc/curproc/exe
257264
endif
258265
ifeq ($(uname_S),AIX)
259266
DEFAULT_PAGER = more
@@ -388,6 +395,7 @@ ifeq ($(uname_S),Windows)
388395
# SNPRINTF_RETURNS_BOGUS = YesPlease
389396
NO_SVN_TESTS = YesPlease
390397
RUNTIME_PREFIX = YesPlease
398+
HAVE_WPGMPTR = YesWeDo
391399
NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
392400
USE_WIN32_MMAP = YesPlease
393401
MMAP_PREVENTS_DELETE = UnfortunatelyYes
@@ -556,6 +564,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
556564
NO_MKDTEMP = YesPlease
557565
NO_SVN_TESTS = YesPlease
558566
RUNTIME_PREFIX = YesPlease
567+
HAVE_WPGMPTR = YesWeDo
559568
NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
560569
USE_WIN32_MMAP = YesPlease
561570
MMAP_PREVENTS_DELETE = UnfortunatelyYes

0 commit comments

Comments
 (0)