[PATCH v8 5/5] mingw/msvc: use the new-style RUNTIME_PREFIX helper
From: Johannes SchindelinThis change also allows us to stop overriding argv[0] with the absolute path of the executable, allowing us to preserve e.g. the case of the executable's file name. This fixes https://github.com/git-for-windows/git/issues/1496 partially. Signed-off-by: Johannes Schindelin --- compat/mingw.c | 5 ++--- config.mak.uname | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index a67872bab..6ded1c859 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -2221,7 +2221,7 @@ void mingw_startup(void) die_startup(); /* determine size of argv and environ conversion buffer */ - maxlen = wcslen(_wpgmptr); + maxlen = wcslen(wargv[0]); for (i = 1; i < argc; i++) maxlen = max(maxlen, wcslen(wargv[i])); for (i = 0; wenv[i]; i++) @@ -2241,8 +2241,7 @@ void mingw_startup(void) buffer = malloc_startup(maxlen); /* convert command line arguments and environment to UTF-8 */ - __argv[0] = wcstoutfdup_startup(buffer, _wpgmptr, maxlen); - for (i = 1; i < argc; i++) + for (i = 0; i < argc; i++) __argv[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen); for (i = 0; wenv[i]; i++) environ[i] = wcstoutfdup_startup(buffer, wenv[i], maxlen); diff --git a/config.mak.uname b/config.mak.uname index e1cfe5e5e..a6e734c5d 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -357,6 +357,7 @@ ifeq ($(uname_S),Windows) SNPRINTF_RETURNS_BOGUS = YesPlease NO_SVN_TESTS = YesPlease RUNTIME_PREFIX = YesPlease + HAVE_WPGMPTR = YesWeDo NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease NO_NSEC = YesPlease USE_WIN32_MMAP = YesPlease @@ -506,6 +507,7 @@ ifneq (,$(findstring MINGW,$(uname_S))) NO_SVN_TESTS = YesPlease NO_PERL_MAKEMAKER = YesPlease RUNTIME_PREFIX = YesPlease + HAVE_WPGMPTR = YesWeDo NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease NO_NSEC = YesPlease USE_WIN32_MMAP = YesPlease -- 2.15.0.chromium12
[PATCH v8 1/5] Makefile: generate Perl header from template file
Currently, the generated Perl script headers are emitted by commands in the Makefile. This mechanism restricts options to introduce alternative header content, needed by Perl runtime prefix support, and obscures the origin of the Perl script header. Change the Makefile to generate a header by processing a template file and move the header content into the "perl/" subdirectory. The generated header content will now be stored in the "GIT-PERL-HEADER" file. This allows the content of the Perl header to be controlled by changing the path of the template in the Makefile. Signed-off-by: Dan Jacques <d...@google.com> Thanks-to: Ævar Arnfjörð Bjarmason <ava...@gmail.com> Thanks-to: Johannes Schindelin <johannes.schinde...@gmx.de> --- .gitignore | 1 + Makefile | 27 +++--- perl/header_templates/fixed_prefix.template.pl | 1 + 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 perl/header_templates/fixed_prefix.template.pl diff --git a/.gitignore b/.gitignore index 833ef3b0b..89bd7bd8a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /GIT-LDFLAGS /GIT-PREFIX /GIT-PERL-DEFINES +/GIT-PERL-HEADER /GIT-PYTHON-VARS /GIT-SCRIPT-DEFINES /GIT-USER-AGENT diff --git a/Makefile b/Makefile index 96f6138f6..ec7cf5a0f 100644 --- a/Makefile +++ b/Makefile @@ -1984,20 +1984,15 @@ git.res: git.rc GIT-VERSION-FILE $(SCRIPT_PERL_GEN): GIT-BUILD-OPTIONS ifndef NO_PERL -$(SCRIPT_PERL_GEN): - +PERL_HEADER_TEMPLATE = perl/header_templates/fixed_prefix.template.pl PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ):$(perllibdir_SQ) -$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-VERSION-FILE + +$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE $(QUIET_GEN)$(RM) $@ $@+ && \ - INSTLIBDIR='$(perllibdir_SQ)' && \ - INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \ - INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \ sed -e '1{' \ -e 's|#!.*perl|#!$(PERL_PATH_SQ)|' \ - -e 'h' \ - -e 's=.*=use lib (split(/$(pathsep)/, $$ENV{GITPERLLIB} || "'"$$INSTLIBDIR"'"));=' \ - -e 'H' \ - -e 'x' \ + -e 'rGIT-PERL-HEADER' \ + -e 'G' \ -e '}' \ -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \ $< >$@+ && \ @@ -2011,6 +2006,16 @@ GIT-PERL-DEFINES: FORCE echo "$$FLAGS" >$@; \ fi +GIT-PERL-HEADER: $(PERL_HEADER_TEMPLATE) GIT-PERL-DEFINES Makefile + $(QUIET_GEN)$(RM) $@ && \ + INSTLIBDIR='$(perllibdir_SQ)' && \ + INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \ + INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \ + sed -e 's=@@PATHSEP@@=$(pathsep)=g' \ + -e 's=@@INSTLIBDIR@@='$$INSTLIBDIR'=g' \ + -e 's=@@PERLLIBDIR@@='$(perllibdir_SQ)'=g' \ + $< >$@+ && \ + mv $@+ $@ .PHONY: gitweb gitweb: @@ -2788,7 +2793,7 @@ ifndef NO_TCLTK endif $(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS $(RM) GIT-USER-AGENT GIT-PREFIX - $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PYTHON-VARS + $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS .PHONY: all install profile-clean clean strip .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell diff --git a/perl/header_templates/fixed_prefix.template.pl b/perl/header_templates/fixed_prefix.template.pl new file mode 100644 index 0..857b4391a --- /dev/null +++ b/perl/header_templates/fixed_prefix.template.pl @@ -0,0 +1 @@ +use lib (split(/@@PATHSEP@@/, $ENV{GITPERLLIB} || '@@INSTLIBDIR@@')); -- 2.15.0.chromium12
[PATCH v8 3/5] exec_cmd: RUNTIME_PREFIX on some POSIX systems
Enable Git to resolve its own binary location using a variety of OS-specific and generic methods, including: - procfs via "/proc/self/exe" (Linux) - _NSGetExecutablePath (Darwin) - KERN_PROC_PATHNAME sysctl on BSDs. - argv0, if absolute (all, including Windows). This is used to enable RUNTIME_PREFIX support for non-Windows systems, notably Linux and Darwin. When configured with RUNTIME_PREFIX, Git will do a best-effort resolution of its executable path and automatically use this as its "exec_path" for relative helper and data lookups, unless explicitly overridden. Small incidental formatting cleanup of "exec_cmd.c". Signed-off-by: Dan Jacques <d...@google.com> Thanks-to: Robbie Iannucci <iannu...@google.com> Thanks-to: Junio C Hamano <gits...@pobox.com> --- Makefile | 28 +- cache.h| 1 + common-main.c | 4 +- config.mak.uname | 7 ++ exec_cmd.c | 236 +++-- exec_cmd.h | 4 +- gettext.c | 8 +- git.c | 2 +- t/t0061-run-command.sh | 2 +- 9 files changed, 253 insertions(+), 39 deletions(-) diff --git a/Makefile b/Makefile index 13fb0e19a..960541e77 100644 --- a/Makefile +++ b/Makefile @@ -448,6 +448,18 @@ all:: # can be moved to arbitrary filesystem locations. RUNTIME_PREFIX also causes # Perl scripts to use a modified entry point header allowing them to resolve # support files at runtime. +# +# When using RUNTIME_PREFIX, define HAVE_BSD_KERN_PROC_SYSCTL if your platform +# supports the KERN_PROC BSD sysctl function. +# +# When using RUNTIME_PREFIX, define PROCFS_EXECUTABLE_PATH if your platform +# mounts a "procfs" filesystem capable of resolving the path of the current +# executable. If defined, this must be the canonical path for the "procfs" +# current executable path. +# +# When using RUNTIME_PREFIX, define HAVE_NS_GET_EXECUTABLE_PATH if your platform +# supports calling _NSGetExecutablePath to retrieve the path of the running +# executable. GIT-VERSION-FILE: FORCE @$(SHELL_PATH) ./GIT-VERSION-GEN @@ -1671,10 +1683,23 @@ ifdef HAVE_BSD_SYSCTL BASIC_CFLAGS += -DHAVE_BSD_SYSCTL endif +ifdef HAVE_BSD_KERN_PROC_SYSCTL + BASIC_CFLAGS += -DHAVE_BSD_KERN_PROC_SYSCTL +endif + ifdef HAVE_GETDELIM BASIC_CFLAGS += -DHAVE_GETDELIM endif +ifneq ($(PROCFS_EXECUTABLE_PATH),) + procfs_executable_path_SQ = $(subst ','\'',$(PROCFS_EXECUTABLE_PATH)) + BASIC_CFLAGS += '-DPROCFS_EXECUTABLE_PATH="$(procfs_executable_path_SQ)"' +endif + +ifdef HAVE_NS_GET_EXECUTABLE_PATH + BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH +endif + ifeq ($(TCLTK_PATH),) NO_TCLTK = NoThanks endif @@ -2223,6 +2248,7 @@ endif exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \ '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \ + '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \ '-DBINDIR="$(bindir_relative_SQ)"' \ '-DPREFIX="$(prefix_SQ)"' @@ -2240,7 +2266,7 @@ attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \ gettext.sp gettext.s gettext.o: GIT-PREFIX gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \ - -DGIT_LOCALE_PATH='"$(localedir_SQ)"' + -DGIT_LOCALE_PATH='"$(localedir_relative_SQ)"' http-push.sp http.sp http-walker.sp remote-curl.sp imap-send.sp: SPARSE_FLAGS += \ -DCURL_DISABLE_TYPECHECK diff --git a/cache.h b/cache.h index 6e45c1b53..4f8754969 100644 --- a/cache.h +++ b/cache.h @@ -428,6 +428,7 @@ static inline enum object_type object_type(unsigned int mode) #define GIT_ICASE_PATHSPECS_ENVIRONMENT "GIT_ICASE_PATHSPECS" #define GIT_QUARANTINE_ENVIRONMENT "GIT_QUARANTINE_PATH" #define GIT_OPTIONAL_LOCKS_ENVIRONMENT "GIT_OPTIONAL_LOCKS" +#define GIT_TEXT_DOMAIN_DIR_ENVIRONMENT "GIT_TEXTDOMAINDIR" /* * Environment variable used in handshaking the wire protocol. diff --git a/common-main.c b/common-main.c index 7d716d5a5..b2e5a86df 100644 --- a/common-main.c +++ b/common-main.c @@ -32,14 +32,14 @@ int main(int argc, const char **argv) */ sanitize_stdfds(); + git_resolve_executable_dir(argv[0]); + git_setup_gettext(); initialize_the_repository(); attr_start(); - git_extract_argv0_path(argv[0]); - restore_sigpipe_to_default(); return cmd_main(argc, argv); diff --git a/config.mak.uname b/config.mak.uname index 6a1d0de0c..e1cfe5e5e 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -37,6 +37,7 @@ ifeq ($(uname_S),Linux) HAVE_GETDELIM = YesPlease SANE_TEXT_GREP=-a FREAD_READS_DIRECTORIES = UnfortunatelyYes + PROCFS_EXECUTABLE_PATH = /proc/self/exe endif ifeq ($(uname_S),GNU/kFreeBSD) HAVE_ALLOCA_H = YesPlease @
[PATCH v8 4/5] exec_cmd: provide a new-style RUNTIME_PREFIX helper for Windows
From: Johannes SchindelinThe 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 --- 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
[PATCH v8 2/5] Makefile: add Perl runtime prefix support
Broaden the RUNTIME_PREFIX flag to configure Git's Perl scripts to locate the Git installation's Perl support libraries by resolving against the script's path, rather than hard-coding that path at build-time. Hard-coding at build time worked on previous RUNTIME_PREFIX configurations (i.e., Windows) because the Perl scripts were run within a virtual filesystem whose paths were consistent regardless of the location of the actual installation. This will no longer be the case for non-Windows RUNTIME_PREFIX users. When enabled, RUNTIME_PREFIX now requires Perl's system paths to be expressed relative to a common installation directory in the Makefile, and uses that relationship to locate support files based on the known starting point of the script being executed, much like RUNTIME_PREFIX does for the Git binary. This change enables Git's Perl scripts to work when their Git installation is relocated or moved to another system, even when they are not in a virtual filesystem environment. Signed-off-by: Dan Jacques <d...@google.com> Thanks-to: Ævar Arnfjörð Bjarmason <ava...@gmail.com> Thanks-to: Johannes Schindelin <johannes.schinde...@gmx.de> --- Makefile | 65 +++- perl/Git/I18N.pm | 2 +- perl/header_templates/runtime_prefix.template.pl | 42 +++ 3 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 perl/header_templates/runtime_prefix.template.pl diff --git a/Makefile b/Makefile index ec7cf5a0f..13fb0e19a 100644 --- a/Makefile +++ b/Makefile @@ -441,6 +441,13 @@ all:: # # When cross-compiling, define HOST_CPU as the canonical name of the CPU on # which the built Git will run (for instance "x86_64"). +# +# Define RUNTIME_PREFIX to configure Git to resolve its ancillary tooling and +# support files relative to the location of the runtime binary, rather than +# hard-coding them into the binary. Git installations built with RUNTIME_PREFIX +# can be moved to arbitrary filesystem locations. RUNTIME_PREFIX also causes +# Perl scripts to use a modified entry point header allowing them to resolve +# support files at runtime. GIT-VERSION-FILE: FORCE @$(SHELL_PATH) ./GIT-VERSION-GEN @@ -478,6 +485,8 @@ ARFLAGS = rcs # mandir # infodir # htmldir +# localedir +# perllibdir # This can help installing the suite in a relocatable way. prefix = $(HOME) @@ -502,7 +511,9 @@ bindir_relative = $(patsubst $(prefix)/%,%,$(bindir)) mandir_relative = $(patsubst $(prefix)/%,%,$(mandir)) infodir_relative = $(patsubst $(prefix)/%,%,$(infodir)) gitexecdir_relative = $(patsubst $(prefix)/%,%,$(gitexecdir)) +localedir_relative = $(patsubst $(prefix)/%,%,$(localedir)) htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir)) +perllibdir_relative = $(patsubst $(prefix)/%,%,$(perllibdir)) export prefix bindir sharedir sysconfdir gitwebdir perllibdir localedir @@ -1748,11 +1759,13 @@ mandir_relative_SQ = $(subst ','\'',$(mandir_relative)) infodir_relative_SQ = $(subst ','\'',$(infodir_relative)) perllibdir_SQ = $(subst ','\'',$(perllibdir)) localedir_SQ = $(subst ','\'',$(localedir)) +localedir_relative_SQ = $(subst ','\'',$(localedir_relative)) gitexecdir_SQ = $(subst ','\'',$(gitexecdir)) gitexecdir_relative_SQ = $(subst ','\'',$(gitexecdir_relative)) template_dir_SQ = $(subst ','\'',$(template_dir)) htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative)) prefix_SQ = $(subst ','\'',$(prefix)) +perllibdir_relative_SQ = $(subst ','\'',$(perllibdir_relative)) gitwebdir_SQ = $(subst ','\'',$(gitwebdir)) SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) @@ -1763,6 +1776,31 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH)) DIFF_SQ = $(subst ','\'',$(DIFF)) PERLLIB_EXTRA_SQ = $(subst ','\'',$(PERLLIB_EXTRA)) +# RUNTIME_PREFIX's resolution logic requires resource paths to be expressed +# relative to each other and share an installation path. +# +# This is a dependency in: +# - Git's binary RUNTIME_PREFIX logic in (see "exec_cmd.c"). +# - The runtime prefix Perl header (see +# "perl/header_templates/runtime_prefix.template.pl"). +ifdef RUNTIME_PREFIX + +ifneq ($(filter /%,$(firstword $(gitexecdir_relative))),) +$(error RUNTIME_PREFIX requires a relative gitexecdir, not: $(gitexecdir)) +endif + +ifneq ($(filter /%,$(firstword $(localedir_relative))),) +$(error RUNTIME_PREFIX requires a relative localedir, not: $(localedir)) +endif + +ifndef NO_PERL +ifneq ($(filter /%,$(firstword $(perllibdir_relative))),) +$(error RUNTIME_PREFIX requires a relative perllibdir, not: $(perllibdir)) +endif +endif + +endif + # We must filter out any object files from $(GITLIBS), # as it is typically used like: # @@ -1983,10 +2021,31 @@ git.res: git.rc GIT-VERSION-FILE # This makes sure we depend on the NO_PERL setting itself. $(SCRIPT_PERL_GEN): GIT-BUILD-OPTIONS +# Used for substitution in Perl modules. Disabled when using RUNTIME_
[PATCH v8 0/5] RUNTIME_PREFIX relocatable Git
ted resolution strategy for "gettext()": use system_path() instead of special environment variable. - Added `sysctl` executable resolution support for BSDs that don't mount "procfs" by default (most of them). Dan Jacques (3): Makefile: generate Perl header from template file Makefile: add Perl runtime prefix support exec_cmd: RUNTIME_PREFIX on some POSIX systems Johannes Schindelin (2): exec_cmd: provide a new-style RUNTIME_PREFIX helper for Windows mingw/msvc: use the new-style RUNTIME_PREFIX helper .gitignore | 1 + Makefile | 128 +-- cache.h | 1 + common-main.c| 4 +- compat/mingw.c | 5 +- config.mak.uname | 9 + exec_cmd.c | 258 --- exec_cmd.h | 4 +- gettext.c| 8 +- git.c| 2 +- perl/Git/I18N.pm | 2 +- perl/header_templates/fixed_prefix.template.pl | 1 + perl/header_templates/runtime_prefix.template.pl | 42 t/t0061-run-command.sh | 2 +- 14 files changed, 412 insertions(+), 55 deletions(-) create mode 100644 perl/header_templates/fixed_prefix.template.pl create mode 100644 perl/header_templates/runtime_prefix.template.pl -- 2.15.0.chromium12
[PATCH v7 3/3] exec_cmd: RUNTIME_PREFIX on some POSIX systems
Enable Git to resolve its own binary location using a variety of OS-specific and generic methods, including: - procfs via "/proc/self/exe" (Linux) - _NSGetExecutablePath (Darwin) - KERN_PROC_PATHNAME sysctl on BSDs. - argv0, if absolute (all, including Windows). This is used to enable RUNTIME_PREFIX support for non-Windows systems, notably Linux and Darwin. When configured with RUNTIME_PREFIX, Git will do a best-effort resolution of its executable path and automatically use this as its "exec_path" for relative helper and data lookups, unless explicitly overridden. Small incidental formatting cleanup of "exec_cmd.c". Signed-off-by: Dan Jacques <d...@google.com> Thanks-to: Robbie Iannucci <iannu...@google.com> Thanks-to: Junio C Hamano <gits...@pobox.com> --- Makefile | 30 ++- cache.h| 1 + common-main.c | 4 +- config.mak.uname | 7 ++ exec_cmd.c | 236 +++-- exec_cmd.h | 4 +- gettext.c | 8 +- git.c | 2 +- t/t0061-run-command.sh | 2 +- 9 files changed, 254 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index 033a55505..f84e816cf 100644 --- a/Makefile +++ b/Makefile @@ -441,6 +441,18 @@ all:: # can be moved to arbitrary filesystem locations. RUNTIME_PREFIX also causes # Perl scripts to use a modified entry point header allowing them to resolve # support files at runtime. +# +# When using RUNTIME_PREFIX, define HAVE_BSD_KERN_PROC_SYSCTL if your platform +# supports the KERN_PROC BSD sysctl function. +# +# When using RUNTIME_PREFIX, define PROCFS_EXECUTABLE_PATH if your platform +# mounts a "procfs" filesystem capable of resolving the path of the current +# executable. If defined, this must be the canonical path for the "procfs" +# current executable path. +# +# When using RUNTIME_PREFIX, define HAVE_NS_GET_EXECUTABLE_PATH if your platform +# supports calling _NSGetExecutablePath to retrieve the path of the running +# executable. GIT-VERSION-FILE: FORCE @$(SHELL_PATH) ./GIT-VERSION-GEN @@ -1664,10 +1676,23 @@ ifdef HAVE_BSD_SYSCTL BASIC_CFLAGS += -DHAVE_BSD_SYSCTL endif +ifdef HAVE_BSD_KERN_PROC_SYSCTL + BASIC_CFLAGS += -DHAVE_BSD_KERN_PROC_SYSCTL +endif + ifdef HAVE_GETDELIM BASIC_CFLAGS += -DHAVE_GETDELIM endif +ifneq ($(PROCFS_EXECUTABLE_PATH),) + procfs_executable_path_SQ = $(subst ','\'',$(PROCFS_EXECUTABLE_PATH)) + BASIC_CFLAGS += '-DPROCFS_EXECUTABLE_PATH="$(procfs_executable_path_SQ)"' +endif + +ifdef HAVE_NS_GET_EXECUTABLE_PATH + BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH +endif + ifeq ($(TCLTK_PATH),) NO_TCLTK = NoThanks endif @@ -1772,7 +1797,7 @@ PERLLIB_EXTRA_SQ = $(subst ','\'',$(PERLLIB_EXTRA)) # RUNTIME_PREFIX's resolution logic requires resource paths to be expressed # relative to each other and share an installation path. # -# This is a dependnecy in: +# This is a dependency in: # - Git's binary RUNTIME_PREFIX logic in (see "exec_cmd.c"). # - The runtime prefix Perl header (see # "perl/header_templates/runtime_prefix.template.pl"). @@ -2216,6 +2241,7 @@ endif exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \ '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \ + '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \ '-DBINDIR="$(bindir_relative_SQ)"' \ '-DPREFIX="$(prefix_SQ)"' @@ -2233,7 +2259,7 @@ attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \ gettext.sp gettext.s gettext.o: GIT-PREFIX gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \ - -DGIT_LOCALE_PATH='"$(localedir_SQ)"' + -DGIT_LOCALE_PATH='"$(localedir_relative_SQ)"' http-push.sp http.sp http-walker.sp remote-curl.sp imap-send.sp: SPARSE_FLAGS += \ -DCURL_DISABLE_TYPECHECK diff --git a/cache.h b/cache.h index a61b2d3f0..d8c55d72b 100644 --- a/cache.h +++ b/cache.h @@ -428,6 +428,7 @@ static inline enum object_type object_type(unsigned int mode) #define GIT_ICASE_PATHSPECS_ENVIRONMENT "GIT_ICASE_PATHSPECS" #define GIT_QUARANTINE_ENVIRONMENT "GIT_QUARANTINE_PATH" #define GIT_OPTIONAL_LOCKS_ENVIRONMENT "GIT_OPTIONAL_LOCKS" +#define GIT_TEXT_DOMAIN_DIR_ENVIRONMENT "GIT_TEXTDOMAINDIR" /* * Environment variable used in handshaking the wire protocol. diff --git a/common-main.c b/common-main.c index 6a689007e..6516a1f89 100644 --- a/common-main.c +++ b/common-main.c @@ -32,12 +32,12 @@ int main(int argc, const char **argv) */ sanitize_stdfds(); + git_resolve_executable_dir(argv[0]); + git_setup_gettext(); attr_start(); - git_extract_argv0_path(argv[0]); - restore_sigpipe_to_default(); return cmd_main(argc, argv); diff -
[PATCH v7 1/3] Makefile: generate Perl header from template file
Currently, the generated Perl script headers are emitted by commands in the Makefile. This mechanism restricts options to introduce alternative header content, needed by Perl runtime prefix support, and obscures the origin of the Perl script header. Change the Makefile to generate a header by processing a template file and move the header content into the "perl/" subdirectory. The generated header content will now be stored in the "GIT-PERL-HEADER" file. This allows the content of the Perl header to be controlled by changing the path of the template in the Makefile. Signed-off-by: Dan Jacques <d...@google.com> Thanks-to: Ævar Arnfjörð Bjarmason <ava...@gmail.com> Thanks-to: Johannes Schindelin <johannes.schinde...@gmx.de> --- .gitignore | 1 + Makefile | 27 +++--- perl/header_templates/fixed_prefix.template.pl | 1 + 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 perl/header_templates/fixed_prefix.template.pl diff --git a/.gitignore b/.gitignore index 833ef3b0b..89bd7bd8a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /GIT-LDFLAGS /GIT-PREFIX /GIT-PERL-DEFINES +/GIT-PERL-HEADER /GIT-PYTHON-VARS /GIT-SCRIPT-DEFINES /GIT-USER-AGENT diff --git a/Makefile b/Makefile index a1d8775ad..e479822ce 100644 --- a/Makefile +++ b/Makefile @@ -1975,20 +1975,15 @@ git.res: git.rc GIT-VERSION-FILE $(SCRIPT_PERL_GEN): GIT-BUILD-OPTIONS ifndef NO_PERL -$(SCRIPT_PERL_GEN): - +PERL_HEADER_TEMPLATE = perl/header_templates/fixed_prefix.template.pl PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ):$(perllibdir_SQ) -$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-VERSION-FILE + +$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE $(QUIET_GEN)$(RM) $@ $@+ && \ - INSTLIBDIR='$(perllibdir_SQ)' && \ - INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \ - INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \ sed -e '1{' \ -e 's|#!.*perl|#!$(PERL_PATH_SQ)|' \ - -e 'h' \ - -e 's=.*=use lib (split(/$(pathsep)/, $$ENV{GITPERLLIB} || "'"$$INSTLIBDIR"'"));=' \ - -e 'H' \ - -e 'x' \ + -e 'rGIT-PERL-HEADER' \ + -e 'G' \ -e '}' \ -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \ $< >$@+ && \ @@ -2002,6 +1997,16 @@ GIT-PERL-DEFINES: FORCE echo "$$FLAGS" >$@; \ fi +GIT-PERL-HEADER: $(PERL_HEADER_TEMPLATE) GIT-PERL-DEFINES Makefile + $(QUIET_GEN)$(RM) $@ && \ + INSTLIBDIR='$(perllibdir_SQ)' && \ + INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \ + INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \ + sed -e 's=@@PATHSEP@@=$(pathsep)=g' \ + -e 's=@@INSTLIBDIR@@='$$INSTLIBDIR'=g' \ + -e 's=@@PERLLIBDIR@@='$(perllibdir_SQ)'=g' \ + $< >$@+ && \ + mv $@+ $@ .PHONY: gitweb gitweb: @@ -2770,7 +2775,7 @@ ifndef NO_TCLTK endif $(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS $(RM) GIT-USER-AGENT GIT-PREFIX - $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PYTHON-VARS + $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS .PHONY: all install profile-clean clean strip .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell diff --git a/perl/header_templates/fixed_prefix.template.pl b/perl/header_templates/fixed_prefix.template.pl new file mode 100644 index 0..857b4391a --- /dev/null +++ b/perl/header_templates/fixed_prefix.template.pl @@ -0,0 +1 @@ +use lib (split(/@@PATHSEP@@/, $ENV{GITPERLLIB} || '@@INSTLIBDIR@@')); -- 2.15.0.chromium12
[PATCH v7 2/3] Makefile: add Perl runtime prefix support
Broaden the RUNTIME_PREFIX flag to configure Git's Perl scripts to locate the Git installation's Perl support libraries by resolving against the script's path, rather than hard-coding that path at build-time. Hard-coding at build time worked on previous RUNTIME_PREFIX configurations (i.e., Windows) because the Perl scripts were run within a virtual filesystem whose paths were consistent regardless of the location of the actual installation. This will no longer be the case for non-Windows RUNTIME_PREFIX users. When enabled, RUNTIME_PREFIX now requires Perl's system paths to be expressed relative to a common installation directory in the Makefile, and uses that relationship to locate support files based on the known starting point of the script being executed, much like RUNTIME_PREFIX does for the Git binary. This change enables Git's Perl scripts to work when their Git installation is relocated or moved to another system, even when they are not in a virtual filesystem environment. Signed-off-by: Dan Jacques <d...@google.com> Thanks-to: Ævar Arnfjörð Bjarmason <ava...@gmail.com> Thanks-to: Johannes Schindelin <johannes.schinde...@gmx.de> --- Makefile | 67 +++- perl/Git/I18N.pm | 2 +- perl/header_templates/runtime_prefix.template.pl | 42 +++ 3 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 perl/header_templates/runtime_prefix.template.pl diff --git a/Makefile b/Makefile index e479822ce..033a55505 100644 --- a/Makefile +++ b/Makefile @@ -434,6 +434,13 @@ all:: # # When cross-compiling, define HOST_CPU as the canonical name of the CPU on # which the built Git will run (for instance "x86_64"). +# +# Define RUNTIME_PREFIX to configure Git to resolve its ancillary tooling and +# support files relative to the location of the runtime binary, rather than +# hard-coding them into the binary. Git installations built with RUNTIME_PREFIX +# can be moved to arbitrary filesystem locations. RUNTIME_PREFIX also causes +# Perl scripts to use a modified entry point header allowing them to resolve +# support files at runtime. GIT-VERSION-FILE: FORCE @$(SHELL_PATH) ./GIT-VERSION-GEN @@ -471,6 +478,8 @@ ARFLAGS = rcs # mandir # infodir # htmldir +# localedir +# perllibdir # This can help installing the suite in a relocatable way. prefix = $(HOME) @@ -494,7 +503,10 @@ pathsep = : mandir_relative = $(patsubst $(prefix)/%,%,$(mandir)) infodir_relative = $(patsubst $(prefix)/%,%,$(infodir)) +gitexecdir_relative = $(patsubst $(prefix)/%,%,$(gitexecdir)) +localedir_relative = $(patsubst $(prefix)/%,%,$(localedir)) htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir)) +perllibdir_relative = $(patsubst $(prefix)/%,%,$(perllibdir)) export prefix bindir sharedir sysconfdir gitwebdir perllibdir localedir @@ -1740,10 +1752,13 @@ mandir_relative_SQ = $(subst ','\'',$(mandir_relative)) infodir_relative_SQ = $(subst ','\'',$(infodir_relative)) perllibdir_SQ = $(subst ','\'',$(perllibdir)) localedir_SQ = $(subst ','\'',$(localedir)) +localedir_relative_SQ = $(subst ','\'',$(localedir_relative)) gitexecdir_SQ = $(subst ','\'',$(gitexecdir)) +gitexecdir_relative_SQ = $(subst ','\'',$(gitexecdir_relative)) template_dir_SQ = $(subst ','\'',$(template_dir)) htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative)) prefix_SQ = $(subst ','\'',$(prefix)) +perllibdir_relative_SQ = $(subst ','\'',$(perllibdir_relative)) gitwebdir_SQ = $(subst ','\'',$(gitwebdir)) SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) @@ -1754,6 +1769,31 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH)) DIFF_SQ = $(subst ','\'',$(DIFF)) PERLLIB_EXTRA_SQ = $(subst ','\'',$(PERLLIB_EXTRA)) +# RUNTIME_PREFIX's resolution logic requires resource paths to be expressed +# relative to each other and share an installation path. +# +# This is a dependnecy in: +# - Git's binary RUNTIME_PREFIX logic in (see "exec_cmd.c"). +# - The runtime prefix Perl header (see +# "perl/header_templates/runtime_prefix.template.pl"). +ifdef RUNTIME_PREFIX + +ifneq ($(filter /%,$(firstword $(gitexecdir_relative))),) +$(error RUNTIME_PREFIX requires a relative gitexecdir, not: $(gitexecdir)) +endif + +ifneq ($(filter /%,$(firstword $(localedir_relative))),) +$(error RUNTIME_PREFIX requires a relative localedir, not: $(localedir)) +endif + +ifndef NO_PERL +ifneq ($(filter /%,$(firstword $(perllibdir_relative))),) +$(error RUNTIME_PREFIX requires a relative perllibdir, not: $(perllibdir)) +endif +endif + +endif + # We must filter out any object files from $(GITLIBS), # as it is typically used like: # @@ -1974,10 +2014,31 @@ git.res: git.rc GIT-VERSION-FILE # This makes sure we depend on the NO_PERL setting itself. $(SCRIPT_PERL_GEN): GIT-BUILD-OPTIONS +# Used for substitution in Perl modules. Disabled when using RUNTIME_PREFIX +# since the locale directory is injected
[PATCH v7 0/3] RUNTIME_PREFIX relocatable Git
This patch set expands support for the RUNTIME_PREFIX configuration flag, currently only used on Windows builds, to include Linux, Darwin, and FreeBSD. When Git is built with RUNTIME_PREFIX enabled, it resolves its ancillary paths relative to the runtime location of its executable rather than hard-coding them at compile-time, allowing a Git installation to be deployed to a path other than the one in which it was built/installed. Note that RUNTIME_PREFIX is not currently used outside of Windows. This patch set should not have an impact on default Git builds. This is a minor update based on comments from the v6 series. If all's well, I'm hoping this set is good to go. Previous threads: v1: https://public-inbox.org/git/20171116170523.28696-1-...@google.com/ v2: https://public-inbox.org/git/20171119173141.4896-1-...@google.com/ v3: https://public-inbox.org/git/20171127164055.93283-1-...@google.com/ v4: https://public-inbox.org/git/20171129223807.91343-1-...@google.com/ v5: https://public-inbox.org/git/20180108030239.92036-1-...@google.com/ v5: https://public-inbox.org/git/20180108030239.92036-1-...@google.com/ v6: https://public-inbox.org/git/20180319025046.58052-1-...@google.com/ Changes in v7 from v6: - Change Perl header based on avarab@'s suggestion. - Rearranged Makefile lines to align with avarab@'s patch in next. - Fix typos in commit messages and comments. === Testing === The latest patch set is available for testing on my GitHub fork, including "travis.ci" testing. The "runtime-prefix" branch includes a "config.mak" commit that enables runtime prefix for the Travis build; the "runtime-prefix-no-config" omits this file, testing this patch without runtime prefix enabled: - https://github.com/danjacques/git/tree/runtime-prefix - https://github.com/danjacques/git/tree/runtime-prefix-no-config - https://travis-ci.org/danjacques/git/branches Built/tested locally using this "config.mak" w/ autoconf: === Example config.mak === ## (BEGIN config.mak) RUNTIME_PREFIX = YesPlease RUNTIME_PREFIX_PERL = YesPlease gitexecdir = libexec/git-core template_dir = share/git-core/templates sysconfdir = etc ## (END config.mak) === Revision History === Changes in v6 from v5: - Rebased on top of "master". - Updated commit messages. - Updated runtime prefix Perl header comment and code to clarify when and why FindBin is used. - With Johannes' blessing on Git-for-Windows, folded "RUNTIME_PREFIX_PERL" functionality into "RUNTIME_PREFIX". - Updated "run-command" test to accommodate RUNTIME_PREFIX trace messages. Changes in v5 from v4: - Rebase on top of "next", notably incorporating the "ab/simplify-perl-makefile" branch. - Cleaner Makefile relative path enforcement. - Update Perl header template path now that the "perl/" directory has fewer build-related files in it. - Update Perl runtime prefix header to use a general system path resolution function. - Implemented the injection of the locale directory into Perl's "Git/I18N.pm" module from the runtime prefix Perl script header. - Updated Perl's "Git/I18N.pm" module to accept injected locale directory. - Added more content to some comments. Changes in v4 from v3: - Incorporated some quoting and Makefile dependency fixes, courtesy of <johannes.schinde...@gmx.de>. Changes in v3 from v2: - Broken into multiple patches now that Perl is isolated in its own RUNTIME_PREFIX_PERL flag. - Working with avarab@, several changes to Perl script runtime prefix support: - Moved Perl header body content from Makefile into external template file(s). - Added generic "perllibdir" variable to override Perl installation path. - RUNTIME_PREFIX_PERL generated script header is more descriptive and consistent with how the C version operates. - Fixed Generated Perl header Makefile dependency, should rebuild when dependent files and flags change. - Changed some of the new RUNTIME_PREFIX trace strings to use consistent formatting and terminology. Changes in v2 from v1: - Added comments and formatting to improve readability of platform-sepecific executable path resolution sleds in `git_get_exec_path`. - Consolidated "cached_exec_path" and "argv_exec_path" globals into "exec_path_value". - Use `strbuf_realpath` instead of `realpath` for procfs resolution. - Removed new environment variable exports. Git with RUNTIME_PREFIX no longer exports or consumes any additional environment information. - Updated Perl script resolution strategy: rather than having Git export the relative executable path to the Perl scripts, they now resolve it independently when RUNTIME_PREFIX_PERL is enabled. - Updated resolution strategy for "gettext()": use system_path() instead of special environment variable. - Added `sysctl` executable resolution
[PATCH v6 2/3] Makefile: add Perl runtime prefix support
Add a new Makefile flag, RUNTIME_PREFIX_PERL, which, when enabled, configures Perl scripts to locate the Git installation's Perl support libraries by resolving against the script's path, rather than hard-coding that path at build-time. RUNTIME_PREFIX_PERL requires that system paths are expressed relative to a common installation directory, and uses that relationship to locate support files based on the known starting point of the script being executed, much like RUNTIME_PREFIX does for the Git binary. This change enables Git's Perl scripts to work when their Git installation is relocated or moved to another system. Signed-off-by: Dan Jacques <d...@google.com> Thanks-to: Ævar Arnfjörð Bjarmason <ava...@gmail.com> Thanks-to: Johannes Schindelin <johannes.schinde...@gmx.de> --- Makefile | 67 +++- perl/Git/I18N.pm | 2 +- perl/header_templates/runtime_prefix.template.pl | 40 ++ 3 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 perl/header_templates/runtime_prefix.template.pl diff --git a/Makefile b/Makefile index e479822ce..101a98a78 100644 --- a/Makefile +++ b/Makefile @@ -434,6 +434,13 @@ all:: # # When cross-compiling, define HOST_CPU as the canonical name of the CPU on # which the built Git will run (for instance "x86_64"). +# +# Define RUNTIME_PREFIX to configure Git to resolve its ancillary tooling and +# support files relative to the location of the runtime binary, rather than +# hard-coding them into the binary. Git installations built with RUNTIME_PREFIX +# can be moved to arbitrary filesystem locations. RUNTIME_PREFIX also causes +# Perl scripts to use a modified entry point header allowing them to resolve +# support files at runtime. GIT-VERSION-FILE: FORCE @$(SHELL_PATH) ./GIT-VERSION-GEN @@ -471,6 +478,8 @@ ARFLAGS = rcs # mandir # infodir # htmldir +# localedir +# perllibdir # This can help installing the suite in a relocatable way. prefix = $(HOME) @@ -492,9 +501,12 @@ lib = lib # DESTDIR = pathsep = : +gitexecdir_relative = $(patsubst $(prefix)/%,%,$(gitexecdir)) mandir_relative = $(patsubst $(prefix)/%,%,$(mandir)) infodir_relative = $(patsubst $(prefix)/%,%,$(infodir)) +localedir_relative = $(patsubst $(prefix)/%,%,$(localedir)) htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir)) +perllibdir_relative = $(patsubst $(prefix)/%,%,$(perllibdir)) export prefix bindir sharedir sysconfdir gitwebdir perllibdir localedir @@ -1740,10 +1752,13 @@ mandir_relative_SQ = $(subst ','\'',$(mandir_relative)) infodir_relative_SQ = $(subst ','\'',$(infodir_relative)) perllibdir_SQ = $(subst ','\'',$(perllibdir)) localedir_SQ = $(subst ','\'',$(localedir)) +localedir_relative_SQ = $(subst ','\'',$(localedir_relative)) gitexecdir_SQ = $(subst ','\'',$(gitexecdir)) +gitexecdir_relative_SQ = $(subst ','\'',$(gitexecdir_relative)) template_dir_SQ = $(subst ','\'',$(template_dir)) htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative)) prefix_SQ = $(subst ','\'',$(prefix)) +perllibdir_relative_SQ = $(subst ','\'',$(perllibdir_relative)) gitwebdir_SQ = $(subst ','\'',$(gitwebdir)) SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) @@ -1754,6 +1769,31 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH)) DIFF_SQ = $(subst ','\'',$(DIFF)) PERLLIB_EXTRA_SQ = $(subst ','\'',$(PERLLIB_EXTRA)) +# RUNTIME_PREFIX's resolution logic requires resource paths to be expressed +# relative to each other and share an installation path. +# +# This is a dependnecy in: +# - Git's binary RUNTIME_PREFIX logic in (see "exec_cmd.c"). +# - The runtime prefix Perl header (see +# "perl/header_templates/runtime_prefix.template.pl"). +ifdef RUNTIME_PREFIX + +ifneq ($(filter /%,$(firstword $(gitexecdir_relative))),) +$(error RUNTIME_PREFIX requires a relative gitexecdir, not: $(gitexecdir)) +endif + +ifneq ($(filter /%,$(firstword $(localedir_relative))),) +$(error RUNTIME_PREFIX requires a relative localedir, not: $(localedir)) +endif + +ifndef NO_PERL +ifneq ($(filter /%,$(firstword $(perllibdir_relative))),) +$(error RUNTIME_PREFIX requires a relative perllibdir, not: $(perllibdir)) +endif +endif + +endif + # We must filter out any object files from $(GITLIBS), # as it is typically used like: # @@ -1974,10 +2014,31 @@ git.res: git.rc GIT-VERSION-FILE # This makes sure we depend on the NO_PERL setting itself. $(SCRIPT_PERL_GEN): GIT-BUILD-OPTIONS +# Used for substitution in Perl modules. Disabled when using RUNTIME_PREFIX +# since the locale directory is injected. +perl_localedir_SQ = $(localedir_SQ) + ifndef NO_PERL PERL_HEADER_TEMPLATE = perl/header_templates/fixed_prefix.template.pl PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ):$(perllibdir_SQ) +PERL_DEFINES := $(PERL_PATH_SQ) $(PERLLIB_EXTRA_SQ) $(perllibdir_SQ) +PERL_DEFINES += $(RUNTIME_PREFIX) + +# Support Perl runtime prefix. In this mo
[PATCH v6 1/3] Makefile: generate Perl header from template file
Currently, the generated Perl script headers are emitted by commands in the Makefile. This mechanism restricts options to introduce alternative header content, needed by Perl runtime prefix support, and obscures the origin of the Perl script header. Change the Makefile to generate a header by processing a template file and move the header content into the "perl/" subdirectory. The processed generated will now be stored in the "GIT-PERL-HEADER" file. This allows the content of the Perl header to be controlled by changing the path of the template in the Makefile. Signed-off-by: Dan Jacques <d...@google.com> Thanks-to: Ævar Arnfjörð Bjarmason <ava...@gmail.com> Thanks-to: Johannes Schindelin <johannes.schinde...@gmx.de> --- .gitignore | 1 + Makefile | 27 +++--- perl/header_templates/fixed_prefix.template.pl | 1 + 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 perl/header_templates/fixed_prefix.template.pl diff --git a/.gitignore b/.gitignore index 833ef3b0b..89bd7bd8a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /GIT-LDFLAGS /GIT-PREFIX /GIT-PERL-DEFINES +/GIT-PERL-HEADER /GIT-PYTHON-VARS /GIT-SCRIPT-DEFINES /GIT-USER-AGENT diff --git a/Makefile b/Makefile index a1d8775ad..e479822ce 100644 --- a/Makefile +++ b/Makefile @@ -1975,20 +1975,15 @@ git.res: git.rc GIT-VERSION-FILE $(SCRIPT_PERL_GEN): GIT-BUILD-OPTIONS ifndef NO_PERL -$(SCRIPT_PERL_GEN): - +PERL_HEADER_TEMPLATE = perl/header_templates/fixed_prefix.template.pl PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ):$(perllibdir_SQ) -$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-VERSION-FILE + +$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE $(QUIET_GEN)$(RM) $@ $@+ && \ - INSTLIBDIR='$(perllibdir_SQ)' && \ - INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \ - INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \ sed -e '1{' \ -e 's|#!.*perl|#!$(PERL_PATH_SQ)|' \ - -e 'h' \ - -e 's=.*=use lib (split(/$(pathsep)/, $$ENV{GITPERLLIB} || "'"$$INSTLIBDIR"'"));=' \ - -e 'H' \ - -e 'x' \ + -e 'rGIT-PERL-HEADER' \ + -e 'G' \ -e '}' \ -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \ $< >$@+ && \ @@ -2002,6 +1997,16 @@ GIT-PERL-DEFINES: FORCE echo "$$FLAGS" >$@; \ fi +GIT-PERL-HEADER: $(PERL_HEADER_TEMPLATE) GIT-PERL-DEFINES Makefile + $(QUIET_GEN)$(RM) $@ && \ + INSTLIBDIR='$(perllibdir_SQ)' && \ + INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \ + INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \ + sed -e 's=@@PATHSEP@@=$(pathsep)=g' \ + -e 's=@@INSTLIBDIR@@='$$INSTLIBDIR'=g' \ + -e 's=@@PERLLIBDIR@@='$(perllibdir_SQ)'=g' \ + $< >$@+ && \ + mv $@+ $@ .PHONY: gitweb gitweb: @@ -2770,7 +2775,7 @@ ifndef NO_TCLTK endif $(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS $(RM) GIT-USER-AGENT GIT-PREFIX - $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PYTHON-VARS + $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS .PHONY: all install profile-clean clean strip .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell diff --git a/perl/header_templates/fixed_prefix.template.pl b/perl/header_templates/fixed_prefix.template.pl new file mode 100644 index 0..857b4391a --- /dev/null +++ b/perl/header_templates/fixed_prefix.template.pl @@ -0,0 +1 @@ +use lib (split(/@@PATHSEP@@/, $ENV{GITPERLLIB} || '@@INSTLIBDIR@@')); -- 2.15.0.chromium12
[PATCH v6 3/3] exec_cmd: RUNTIME_PREFIX on some POSIX systems
Enable Git to resolve its own binary location using a variety of OS-specific and generic methods, including: - procfs via "/proc/self/exe" (Linux) - _NSGetExecutablePath (Darwin) - KERN_PROC_PATHNAME sysctl on BSDs. - argv0, if absolute (all, including Windows). This is used to enable RUNTIME_PREFIX support for non-Windows systems, notably Linux and Darwin. When configured with RUNTIME_PREFIX, Git will do a best-effort resolution of its executable path and automatically use this as its "exec_path" for relative helper and data lookups, unless explicitly overridden. Small incidental formatting cleanup of "exec_cmd.c". Signed-off-by: Dan Jacques <d...@google.com> Thanks-to: Robbie Iannucci <iannu...@google.com> Thanks-to: Junio C Hamano <gits...@pobox.com> --- Makefile | 26 +- cache.h| 1 + common-main.c | 4 +- config.mak.uname | 7 ++ exec_cmd.c | 241 ++--- exec_cmd.h | 4 +- gettext.c | 8 +- git.c | 2 +- t/t0061-run-command.sh | 2 +- 9 files changed, 254 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index 101a98a78..df17a62a4 100644 --- a/Makefile +++ b/Makefile @@ -418,6 +418,16 @@ all:: # # Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function. # +# Define HAVE_BSD_KERN_PROC_SYSCTL if your platform supports the KERN_PROC BSD +# sysctl function. +# +# Define PROCFS_EXECUTABLE_PATH if your platform mounts a "procfs" filesystem +# capable of resolving the path of the current executable. If defined, this +# must be the canonical path for the "procfs" current executable path. +# +# Define HAVE_NS_GET_EXECUTABLE_PATH if your platform supports calling +# _NSGetExecutablePath to retrieve the path of the running executable. +# # Define HAVE_GETDELIM if your system has the getdelim() function. # # Define PAGER_ENV to a SP separated VAR=VAL pairs to define @@ -1664,10 +1674,23 @@ ifdef HAVE_BSD_SYSCTL BASIC_CFLAGS += -DHAVE_BSD_SYSCTL endif +ifdef HAVE_BSD_KERN_PROC_SYSCTL + BASIC_CFLAGS += -DHAVE_BSD_KERN_PROC_SYSCTL +endif + ifdef HAVE_GETDELIM BASIC_CFLAGS += -DHAVE_GETDELIM endif +ifneq ($(PROCFS_EXECUTABLE_PATH),) + procfs_executable_path_SQ = $(subst ','\'',$(PROCFS_EXECUTABLE_PATH)) + BASIC_CFLAGS += '-DPROCFS_EXECUTABLE_PATH="$(procfs_executable_path_SQ)"' +endif + +ifdef HAVE_NS_GET_EXECUTABLE_PATH + BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH +endif + ifeq ($(TCLTK_PATH),) NO_TCLTK = NoThanks endif @@ -2216,6 +2239,7 @@ endif exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \ '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \ + '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \ '-DBINDIR="$(bindir_relative_SQ)"' \ '-DPREFIX="$(prefix_SQ)"' @@ -2233,7 +2257,7 @@ attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \ gettext.sp gettext.s gettext.o: GIT-PREFIX gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \ - -DGIT_LOCALE_PATH='"$(localedir_SQ)"' + -DGIT_LOCALE_PATH='"$(localedir_relative_SQ)"' http-push.sp http.sp http-walker.sp remote-curl.sp imap-send.sp: SPARSE_FLAGS += \ -DCURL_DISABLE_TYPECHECK diff --git a/cache.h b/cache.h index d06932ed0..2d1999a5f 100644 --- a/cache.h +++ b/cache.h @@ -428,6 +428,7 @@ static inline enum object_type object_type(unsigned int mode) #define GIT_ICASE_PATHSPECS_ENVIRONMENT "GIT_ICASE_PATHSPECS" #define GIT_QUARANTINE_ENVIRONMENT "GIT_QUARANTINE_PATH" #define GIT_OPTIONAL_LOCKS_ENVIRONMENT "GIT_OPTIONAL_LOCKS" +#define GIT_TEXT_DOMAIN_DIR_ENVIRONMENT "GIT_TEXTDOMAINDIR" /* * Environment variable used in handshaking the wire protocol. diff --git a/common-main.c b/common-main.c index 6a689007e..6516a1f89 100644 --- a/common-main.c +++ b/common-main.c @@ -32,12 +32,12 @@ int main(int argc, const char **argv) */ sanitize_stdfds(); + git_resolve_executable_dir(argv[0]); + git_setup_gettext(); attr_start(); - git_extract_argv0_path(argv[0]); - restore_sigpipe_to_default(); return cmd_main(argc, argv); diff --git a/config.mak.uname b/config.mak.uname index 6a1d0de0c..e1cfe5e5e 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -37,6 +37,7 @@ ifeq ($(uname_S),Linux) HAVE_GETDELIM = YesPlease SANE_TEXT_GREP=-a FREAD_READS_DIRECTORIES = UnfortunatelyYes + PROCFS_EXECUTABLE_PATH = /proc/self/exe endif ifeq ($(uname_S),GNU/kFreeBSD) HAVE_ALLOCA_H = YesPlease @@ -111,6 +112,7 @@ ifeq ($(uname_S),Darwin) BASIC_CFLAGS += -DPROTECT_HFS_DEFAULT=1 HAVE_BSD_SYSCTL = YesPlease FREAD_READS_DIRECTORIE
[PATCH v6 0/3] RUNTIME_PREFIX relocatable Git
This patch set expands support for the RUNTIME_PREFIX configuration flag, currently only used on Windows builds, to include Linux, Darwin, and FreeBSD. When Git is built with RUNTIME_PREFIX enabled, it resolves its ancillary paths relative to the runtime location of its executable rather than hard-coding them at compile-time, allowing a Git installation to be deployed to a path other than the one in which it was built/installed. Note that RUNTIME_PREFIX is not currently used outside of Windows. This patch set should not have an impact on default Git builds. I'm dusting this back off now that avarab@'s Perl Makefile simplification patch set has landed. It's been a few months, so I'm a bit rusty, but I think that I've incorporated all of the feedback. Please take a look and let me know what you think! Previous threads: v1: https://public-inbox.org/git/20171116170523.28696-1-...@google.com/ v2: https://public-inbox.org/git/20171119173141.4896-1-...@google.com/ v3: https://public-inbox.org/git/20171127164055.93283-1-...@google.com/ v4: https://public-inbox.org/git/20171129223807.91343-1-...@google.com/ v5: https://public-inbox.org/git/20180108030239.92036-1-...@google.com/ Changes in v6 from v5: - Rebased on top of "master". - Updated commit messages. - Updated runtime prefix Perl header comment and code to clarify when and why FindBin is used. - With Johannes' blessing on Git-for-Windows, folded "RUNTIME_PREFIX_PERL" functionality into "RUNTIME_PREFIX". - Updated "run-command" test to accommodate RUNTIME_PREFIX trace messages. === Testing === The latest patch set is available for testing on my GitHub fork, including "travis.ci" testing. The "runtime-prefix" branch includes a "config.mak" commit that enables runtime prefix for the Travis build; the "runtime-prefix-no-config" omits this file, testing this patch without runtime prefix enabled: - https://github.com/danjacques/git/tree/runtime-prefix - https://github.com/danjacques/git/tree/runtime-prefix-no-config - https://travis-ci.org/danjacques/git/branches Built/tested locally using this "config.mak" w/ autoconf: === Example config.mak === ## (BEGIN config.mak) RUNTIME_PREFIX = YesPlease RUNTIME_PREFIX_PERL = YesPlease gitexecdir = libexec/git-core template_dir = share/git-core/templates sysconfdir = etc ## (END config.mak) === Revision History === Changes in v5 from v4: - Rebase on top of "next", notably incorporating the "ab/simplify-perl-makefile" branch. - Cleaner Makefile relative path enforcement. - Update Perl header template path now that the "perl/" directory has fewer build-related files in it. - Update Perl runtime prefix header to use a general system path resolution function. - Implemented the injection of the locale directory into Perl's "Git/I18N.pm" module from the runtime prefix Perl script header. - Updated Perl's "Git/I18N.pm" module to accept injected locale directory. - Added more content to some comments. Changes in v4 from v3: - Incorporated some quoting and Makefile dependency fixes, courtesy of <johannes.schinde...@gmx.de>. Changes in v3 from v2: - Broken into multiple patches now that Perl is isolated in its own RUNTIME_PREFIX_PERL flag. - Working with avarab@, several changes to Perl script runtime prefix support: - Moved Perl header body content from Makefile into external template file(s). - Added generic "perllibdir" variable to override Perl installation path. - RUNTIME_PREFIX_PERL generated script header is more descriptive and consistent with how the C version operates. - Fixed Generated Perl header Makefile dependency, should rebuild when dependent files and flags change. - Changed some of the new RUNTIME_PREFIX trace strings to use consistent formatting and terminology. Changes in v2 from v1: - Added comments and formatting to improve readability of platform-sepecific executable path resolution sleds in `git_get_exec_path`. - Consolidated "cached_exec_path" and "argv_exec_path" globals into "exec_path_value". - Use `strbuf_realpath` instead of `realpath` for procfs resolution. - Removed new environment variable exports. Git with RUNTIME_PREFIX no longer exports or consumes any additional environment information. - Updated Perl script resolution strategy: rather than having Git export the relative executable path to the Perl scripts, they now resolve it independently when RUNTIME_PREFIX_PERL is enabled. - Updated resolution strategy for "gettext()": use system_path() instead of special environment variable. - Added `sysctl` executable resolution support for BSDs that don't mount "procfs" by default (most of them). Dan Jacques (3): Makefile: generate Perl header from template file Makefile: add Perl r
Re: [PATCH v5 2/3] Makefile: add Perl runtime prefix support
On Mon, 08 Jan 2018, Ævar Arnfjörð Bjarmason wrote: > > I'll add a "NO_RUNTIME_PREFIX_PERL" flag as per avarab@'s suggestion as a > > potential mitigation if a problem does end up arising in Windows builds, > > with a note that NO_RUNTIME_PREFIX_PERL can be deleted if everything seems > > to be working. What do you think? > > To be clear, I meant that if it's determined by you/others that an > opt-out on Windows is needed I think it makes sense to make it a NO_* > flag, but if there's a solution where we can just turn it on for > everything then ideally we'd just have RUNTIME_PREFIX=YesPlease. Oh that's fair. Okay, we'll go all in and just have RUNTIME_PREFIX.
Re: [PATCH v5 2/3] Makefile: add Perl runtime prefix support
On 2018-01-08 20:27, Johannes Schindelin wrote: > > Maybe we covered this in previous submissions, but refresh my memory, > > why is the *_PERL define still needed? Reading this explanation doesn't > > make sense to me, but I'm probably missing something. > > If the reason is to accommodate Windows, I think it'd make more sense to > change the way Git for Windows handles this, and use the same relative > paths (if possible, that is, see the GITPERLLIB problems I mentioned > elsewhere and which necessitated > https://github.com/git-for-windows/git/commit/3b2f716bd8). > (...) > What do you think? Should we just fold the RUNTIME_PREFIX_PERL handling > into RUNTIME_PREFIX and be done with that part? > (...) > As I mentioned in the mail I just finished and sent (I started it hours > ago, but then got busy with other things while the builds were running): I > am totally cool with changing this on Windows, too. Should simplify > things, right? No objections here. I see it as adding slightly more risk to this patch's potential impact on Windows builds, but if Git-for-Windows is okay with that, I'll go ahead and fold RUNTIME_PREFIX_PERL into RUNTIME_PREFIX for simplicity's sake. I'll add a "NO_RUNTIME_PREFIX_PERL" flag as per avarab@'s suggestion as a potential mitigation if a problem does end up arising in Windows builds, with a note that NO_RUNTIME_PREFIX_PERL can be deleted if everything seems to be working. What do you think? > BTW I managed to run your `runtime-prefix` branch through VSTS builds on > Windows, macOS and Linux and they all pass the test suite. (Including the > RUNTIME_PREFIX_PERL=YesPlease setting you added for Travis CI testing.) Great news, thanks for doing this!
Re: [PATCH v5 2/3] Makefile: add Perl runtime prefix support
On Mon, 08 Jan 2018, Ævar Arnfjörð Bjarmason replied: > Thanks, applied this on top of next and it works for me, i.e. install to > /tmp/git and move to /tmp/git2 = works for me. Comments below. Good to hear! I've run this through a few machines at my disposal, but the more hands on the better. >> Enabling RUNTIME_PREFIX_PERL overrides the system-specific Perl script >> installation path generated by MakeMaker to force installation into a >> platform-neutral location, "/share/perl5". > > Not generated by MakeMaker anymore :) Hah good catch! I'll update the commit message. >>+# it. This is intentionally separate from RUNTIME_PREFIX so that notably >>Windows >>+# can hard-code Perl library paths while still enabling RUNTIME_PREFIX >>+# resolution. > > Maybe we covered this in previous submissions, but refresh my memory, > why is the *_PERL define still needed? Reading this explanation doesn't > make sense to me, but I'm probably missing something. > > If we have a system where we have some perl library paths on the system > we want to use, then they'll still be in @INC after our 'use lib'-ing, > so we'll find libraries there. > > The only reason I can think of for doing this for C and not for Perl > would be if you for some reason want to have a git in /tmp/git but then > use a different version of the Git.pm from some system install, but I > can't imagine why. The reason is entirely due to the way Git-for-Windows is structured. In Git-for-Windows, Git binaries are run directly from Windows, meaning that they require RUNTIME_PREFIX resolution. However, Perl scripts are run from a MinGW universe, within which filesystem paths are fixed. Therefore, Windows Perl scripts don't require a runtime prefix resolution. This makes sense because they are clearly functional right now without this patch enabled :) However, we don't have the luxury of running Perl in a separate universe on other OSes, so this patch is necessary for them. I created a separate option because I wanted to ensure that I don't change anything fundamental in Windows, which currently relies on runtime prefix resoultion. On all other operating systems, Perl and binary runtime prefix resolution is disabled by default, so if this patch set does end up having bugs or edge cases in the Perl runtime prefix code, it won't inpact anybody's current builds. I can foresee a future where Windows maintainers decide that PERL_RUNTIME_PREFIX is fine for Windows and merge the two options; however, I didn't want to force that decision in the initial implementation. > > + # GIT_EXEC_PATH is supplied by `git` or the test suite. Otherwise, > > resolve > > + # against the runtime path of this script. > > + require FindBin; > > + require File::Spec; > > + (my $prefix = $ENV{GIT_EXEC_PATH} || $FindBin::Bin) =~ > > s=${gitexecdir_relative}$==; > > So why are we falling back on $FindBin::Bin? Just so you can do > e.g. /tmp/git2/libexec/git-core/git-svn like you can do > /tmp/git2/libexec/git-core/git-status, i.e. will this never be false if > invoked via "git"? > > I don't mind it, just wondering if I'm missing something and we need to > use the fallback path in some "normal" codepath. Yep, exactly. The ability to directly invoke Perl scripts is currently functional in non-runtime-prefix builds, so enabling it in runtime-prefix builds seemed appropriate. I have found this useful for testing. However, since GIT_EXEC_PATH is probably going to be the common path, I'll scoop the FindBin code (including the "require" statement) into a conditional in v6 and use it only when GIT_EXEC_PATH is empty. > > + return File::Spec->catdir($prefix, $relpath); > > I think you initially got some version of this from me (or not), so this > is probably my fault, but reading this again I think this would be > better as just: > > return $prefix . '@@PATHSEP@@' . $relpath; > > I.e. right after this we split on @@PATHSEP@@, and that clearly works > (as opposed to using File::Spec->splitpath) since we've used it > forever. > > Better just to use the same idiom on both ends to not leave the reader > wondering why we can split paths one way, but need to join them another > way. PATHSEP is the path separator (":"), as opposed to the filesystem separator ("/"). We split on PATHSEP below b/c we need to "use lib" as an array, but it may be a ":"-delimited string.
[PATCH v5 3/3] exec_cmd: RUNTIME_PREFIX on some POSIX systems
Enable Git to resolve its own binary location using a variety of OS-specific and generic methods, including: - procfs via "/proc/self/exe" (Linux) - _NSGetExecutablePath (Darwin) - KERN_PROC_PATHNAME sysctl on BSDs. - argv0, if absolute (all, including Windows). This is used to enable RUNTIME_PREFIX support for non-Windows systems, notably Linux and Darwin. When configured with RUNTIME_PREFIX, Git will do a best-effort resolution of its executable path and automatically use this as its "exec_path" for relative helper and data lookups, unless explicitly overridden. Small incidental formatting cleanup of "exec_cmd.c". Signed-off-by: Dan Jacques <d...@google.com> Thanks-to: Robbie Iannucci <iannu...@google.com> Thanks-to: Junio C Hamano <gits...@pobox.com> --- Makefile | 36 - cache.h | 1 + common-main.c| 4 +- config.mak.uname | 7 ++ exec_cmd.c | 241 --- exec_cmd.h | 4 +- gettext.c| 8 +- git.c| 2 +- 8 files changed, 262 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index 060b47879..587ff18e9 100644 --- a/Makefile +++ b/Makefile @@ -412,6 +412,16 @@ all:: # # Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function. # +# Define HAVE_BSD_KERN_PROC_SYSCTL if your platform supports the KERN_PROC BSD +# sysctl function. +# +# Define PROCFS_EXECUTABLE_PATH if your platform mounts a "procfs" filesystem +# capable of resolving the path of the current executable. If defined, this +# must be the canonical path for the "procfs" current executable path. +# +# Define HAVE_NS_GET_EXECUTABLE_PATH if your platform supports calling +# _NSGetExecutablePath to retrieve the path of the running executable. +# # Define HAVE_GETDELIM if your system has the getdelim() function. # # Define PAGER_ENV to a SP separated VAR=VAL pairs to define @@ -429,9 +439,17 @@ all:: # When cross-compiling, define HOST_CPU as the canonical name of the CPU on # which the built Git will run (for instance "x86_64"). # +# Define RUNTIME_PREFIX to configure Git to resolve its ancillary tooling and +# support files relative to the location of the runtime binary, rather than +# hard-coding them into the binary. Git installations built with RUNTIME_PREFIX +# can be moved to arbitrary filesystem locations. Users may want to enable +# RUNTIME_PREFIX_PERL as well (see below). +# # Define RUNTIME_PREFIX_PERL to configure Git's PERL commands to locate Git # support libraries relative to their filesystem path instead of hard-coding -# it. +# it. This is intentionally separate from RUNTIME_PREFIX so that notably Windows +# can hard-code Perl library paths while still enabling RUNTIME_PREFIX +# resolution. GIT-VERSION-FILE: FORCE @$(SHELL_PATH) ./GIT-VERSION-GEN @@ -1653,10 +1671,23 @@ ifdef HAVE_BSD_SYSCTL BASIC_CFLAGS += -DHAVE_BSD_SYSCTL endif +ifdef HAVE_BSD_KERN_PROC_SYSCTL + BASIC_CFLAGS += -DHAVE_BSD_KERN_PROC_SYSCTL +endif + ifdef HAVE_GETDELIM BASIC_CFLAGS += -DHAVE_GETDELIM endif +ifneq ($(PROCFS_EXECUTABLE_PATH),) + procfs_executable_path_SQ = $(subst ','\'',$(PROCFS_EXECUTABLE_PATH)) + BASIC_CFLAGS += '-DPROCFS_EXECUTABLE_PATH="$(procfs_executable_path_SQ)"' +endif + +ifdef HAVE_NS_GET_EXECUTABLE_PATH + BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH +endif + ifeq ($(TCLTK_PATH),) NO_TCLTK = NoThanks endif @@ -2194,6 +2225,7 @@ endif exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \ '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \ + '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \ '-DBINDIR="$(bindir_relative_SQ)"' \ '-DPREFIX="$(prefix_SQ)"' @@ -2211,7 +2243,7 @@ attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \ gettext.sp gettext.s gettext.o: GIT-PREFIX gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \ - -DGIT_LOCALE_PATH='"$(localedir_SQ)"' + -DGIT_LOCALE_PATH='"$(localedir_relative_SQ)"' http-push.sp http.sp http-walker.sp remote-curl.sp imap-send.sp: SPARSE_FLAGS += \ -DCURL_DISABLE_TYPECHECK diff --git a/cache.h b/cache.h index d8b975a57..212c1a631 100644 --- a/cache.h +++ b/cache.h @@ -452,6 +452,7 @@ static inline enum object_type object_type(unsigned int mode) #define GIT_ICASE_PATHSPECS_ENVIRONMENT "GIT_ICASE_PATHSPECS" #define GIT_QUARANTINE_ENVIRONMENT "GIT_QUARANTINE_PATH" #define GIT_OPTIONAL_LOCKS_ENVIRONMENT "GIT_OPTIONAL_LOCKS" +#define GIT_TEXT_DOMAIN_DIR_ENVIRONMENT "GIT_TEXTDOMAINDIR" /* * Environment variable used in handshaking the wire protocol. diff --git a/common-main.c b/common-main.c index 6a689007e..6516a1f89 100644 --- a/common-main.c +++ b/common-main.c @@ -32,
[PATCH v5 0/3] RUNTIME_PREFIX relocatable Git
(Send #2, since I failed to CC everyone in the first posting). This patch set expands support for the RUNTIME_PREFIX configuration flag, currently only used on Windows builds, to include Linux, Darwin, and FreeBSD. When Git is built with RUNTIME_PREFIX enabled, it resolves its ancillary paths relative to the runtime location of its executable rather than hard-coding them at compile-time, allowing a Git installation to be deployed to a path other than the one in which it was built/installed. Note that RUNTIME_PREFIX is not currently used outside of Windows. This patch set should not have an impact on default Git builds. I'm uploading an updated patch set now that avarab@'s Perl Makefile simplification patch set has advanced and seems to be stable. Please take a look and let me know what you think! Previous threads: v1: https://public-inbox.org/git/20171116170523.28696-1-...@google.com/ v2: https://public-inbox.org/git/20171119173141.4896-1-...@google.com/ v3: https://public-inbox.org/git/20171127164055.93283-1-...@google.com/ v4: https://public-inbox.org/git/20171129223807.91343-1-...@google.com/ Changes in v5 from v4: - Rebase on top of "next", notably incorporating the "ab/simplify-perl-makefile" branch. - Cleaner Makefile relative path enforcement. - Update Perl header template path now that the "perl/" directory has fewer build-related files in it. - Update Perl runtime prefix header to use a general system path resolution function. - Implemented the injection of the locale directory into Perl's "Git/I18N.pm" module from the runtime prefix Perl script header. - Updated Perl's "Git/I18N.pm" module to accept injected locale directory. - Added more content to some comments. === Testing === The latest patch set is available for testing on my GitHub fork, including "travis.ci" testing. The "runtime-prefix" branch includes a "config.mak" commit that enables runtime prefix for the Travis build; the "runtime-prefix-no-config" omits this file, testing this patch without runtime prefix enabled: - https://github.com/danjacques/git/tree/runtime-prefix - https://travis-ci.org/danjacques/git/branches Built/tested locally using this "config.mak" w/ autoconf: === Example config.mak === ## (BEGIN config.mak) RUNTIME_PREFIX = YesPlease RUNTIME_PREFIX_PERL = YesPlease gitexecdir = libexec/git-core template_dir = share/git-core/templates sysconfdir = etc ## (END config.mak) === Revision History === Changes in v4 from v3: - Incorporated some quoting and Makefile dependency fixes, courtesy of <johannes.schinde...@gmx.de>. Changes in v3 from v2: - Broken into multiple patches now that Perl is isolated in its own RUNTIME_PREFIX_PERL flag. - Working with avarab@, several changes to Perl script runtime prefix support: - Moved Perl header body content from Makefile into external template file(s). - Added generic "perllibdir" variable to override Perl installation path. - RUNTIME_PREFIX_PERL generated script header is more descriptive and consistent with how the C version operates. - Fixed Generated Perl header Makefile dependency, should rebuild when dependent files and flags change. - Changed some of the new RUNTIME_PREFIX trace strings to use consistent formatting and terminology. Changes in v2 from v1: - Added comments and formatting to improve readability of platform-sepecific executable path resolution sleds in `git_get_exec_path`. - Consolidated "cached_exec_path" and "argv_exec_path" globals into "exec_path_value". - Use `strbuf_realpath` instead of `realpath` for procfs resolution. - Removed new environment variable exports. Git with RUNTIME_PREFIX no longer exports or consumes any additional environment information. - Updated Perl script resolution strategy: rather than having Git export the relative executable path to the Perl scripts, they now resolve it independently when RUNTIME_PREFIX_PERL is enabled. - Updated resolution strategy for "gettext()": use system_path() instead of special environment variable. - Added `sysctl` executable resolution support for BSDs that don't mount "procfs" by default (most of them). Dan Jacques (3): Makefile: generate Perl header from template file Makefile: add Perl runtime prefix support exec_cmd: RUNTIME_PREFIX on some POSIX systems .gitignore | 1 + Makefile | 114 +-- cache.h | 1 + common-main.c| 4 +- config.mak.uname | 7 + exec_cmd.c | 241 --- exec_cmd.h | 4 +- gettext.c| 8 +- git.c
[PATCH v5 1/3] Makefile: generate Perl header from template file
Currently, the generated Perl script headers are emitted by commands in the Makefile. This mechanism restricts options to introduce alternative header content, needed by Perl runtime prefix support, and obscures the origin of the Perl script header. Change the Makefile to generate a header by processing a template file and move the header content into the "perl/" subdirectory. The processed generated will now be stored in the "GIT-PERL-HEADER" file. This allows the content of the Perl header to be controlled by changing the path of the template in the Makefile. Signed-off-by: Dan Jacques <d...@google.com> Thanks-to: Ævar Arnfjörð Bjarmason <ava...@gmail.com> Thanks-to: Johannes Schindelin <johannes.schinde...@gmx.de> --- .gitignore | 1 + Makefile | 27 +++--- perl/header_templates/fixed_prefix.template.pl | 1 + 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 perl/header_templates/fixed_prefix.template.pl diff --git a/.gitignore b/.gitignore index 833ef3b0b..89bd7bd8a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /GIT-LDFLAGS /GIT-PREFIX /GIT-PERL-DEFINES +/GIT-PERL-HEADER /GIT-PYTHON-VARS /GIT-SCRIPT-DEFINES /GIT-USER-AGENT diff --git a/Makefile b/Makefile index 37e02cec1..e5e81ca1b 100644 --- a/Makefile +++ b/Makefile @@ -1967,20 +1967,15 @@ git.res: git.rc GIT-VERSION-FILE $(SCRIPT_PERL_GEN): GIT-BUILD-OPTIONS ifndef NO_PERL -$(SCRIPT_PERL_GEN): - +PERL_HEADER_TEMPLATE = perl/header_templates/fixed_prefix.template.pl PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ):$(perllibdir_SQ) -$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-VERSION-FILE + +$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE $(QUIET_GEN)$(RM) $@ $@+ && \ - INSTLIBDIR='$(perllibdir_SQ)' && \ - INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \ - INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \ sed -e '1{' \ -e 's|#!.*perl|#!$(PERL_PATH_SQ)|' \ - -e 'h' \ - -e 's=.*=use lib (split(/$(pathsep)/, $$ENV{GITPERLLIB} || "'"$$INSTLIBDIR"'"));=' \ - -e 'H' \ - -e 'x' \ + -e 'rGIT-PERL-HEADER' \ + -e 'G' \ -e '}' \ -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \ $< >$@+ && \ @@ -1994,6 +1989,16 @@ GIT-PERL-DEFINES: FORCE echo "$$FLAGS" >$@; \ fi +GIT-PERL-HEADER: $(PERL_HEADER_TEMPLATE) GIT-PERL-DEFINES Makefile + $(QUIET_GEN)$(RM) $@ && \ + INSTLIBDIR='$(perllibdir_SQ)' && \ + INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \ + INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \ + sed -e 's=@@PATHSEP@@=$(pathsep)=g' \ + -e 's=@@INSTLIBDIR@@='$$INSTLIBDIR'=g' \ + -e 's=@@PERLLIBDIR@@='$(perllibdir_SQ)'=g' \ + $< >$@+ && \ + mv $@+ $@ .PHONY: gitweb gitweb: @@ -2735,7 +2740,7 @@ ifndef NO_TCLTK endif $(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS $(RM) GIT-USER-AGENT GIT-PREFIX - $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PYTHON-VARS + $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS .PHONY: all install profile-clean clean strip .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell diff --git a/perl/header_templates/fixed_prefix.template.pl b/perl/header_templates/fixed_prefix.template.pl new file mode 100644 index 0..857b4391a --- /dev/null +++ b/perl/header_templates/fixed_prefix.template.pl @@ -0,0 +1 @@ +use lib (split(/@@PATHSEP@@/, $ENV{GITPERLLIB} || '@@INSTLIBDIR@@')); -- 2.15.0.chromium12
[PATCH v5 2/3] Makefile: add Perl runtime prefix support
Add a new Makefile flag, RUNTIME_PREFIX_PERL, which, when enabled, configures Perl scripts to locate the Git installation's Perl support libraries by resolving against the script's path, rather than hard-coding that path at build-time. Enabling RUNTIME_PREFIX_PERL overrides the system-specific Perl script installation path generated by MakeMaker to force installation into a platform-neutral location, "/share/perl5". This change enables Git's Perl scripts to work when their Git installation is relocated or moved to another system. Signed-off-by: Dan Jacques <d...@google.com> Thanks-to: Ævar Arnfjörð Bjarmason <ava...@gmail.com> Thanks-to: Johannes Schindelin <johannes.schinde...@gmx.de> --- Makefile | 53 +++- perl/Git/I18N.pm | 2 +- perl/header_templates/runtime_prefix.template.pl | 32 ++ 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 perl/header_templates/runtime_prefix.template.pl diff --git a/Makefile b/Makefile index e5e81ca1b..060b47879 100644 --- a/Makefile +++ b/Makefile @@ -428,6 +428,10 @@ all:: # # When cross-compiling, define HOST_CPU as the canonical name of the CPU on # which the built Git will run (for instance "x86_64"). +# +# Define RUNTIME_PREFIX_PERL to configure Git's PERL commands to locate Git +# support libraries relative to their filesystem path instead of hard-coding +# it. GIT-VERSION-FILE: FORCE @$(SHELL_PATH) ./GIT-VERSION-GEN @@ -465,6 +469,8 @@ ARFLAGS = rcs # mandir # infodir # htmldir +# localedir +# perllibdir # This can help installing the suite in a relocatable way. prefix = $(HOME) @@ -486,9 +492,12 @@ lib = lib # DESTDIR = pathsep = : +gitexecdir_relative = $(patsubst $(prefix)/%,%,$(gitexecdir)) mandir_relative = $(patsubst $(prefix)/%,%,$(mandir)) infodir_relative = $(patsubst $(prefix)/%,%,$(infodir)) +localedir_relative = $(patsubst $(prefix)/%,%,$(localedir)) htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir)) +perllibdir_relative = $(patsubst $(prefix)/%,%,$(perllibdir)) export prefix bindir sharedir sysconfdir gitwebdir perllibdir localedir @@ -1732,10 +1741,13 @@ mandir_relative_SQ = $(subst ','\'',$(mandir_relative)) infodir_relative_SQ = $(subst ','\'',$(infodir_relative)) perllibdir_SQ = $(subst ','\'',$(perllibdir)) localedir_SQ = $(subst ','\'',$(localedir)) +localedir_relative_SQ = $(subst ','\'',$(localedir_relative)) gitexecdir_SQ = $(subst ','\'',$(gitexecdir)) +gitexecdir_relative_SQ = $(subst ','\'',$(gitexecdir_relative)) template_dir_SQ = $(subst ','\'',$(template_dir)) htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative)) prefix_SQ = $(subst ','\'',$(prefix)) +perllibdir_relative_SQ = $(subst ','\'',$(perllibdir_relative)) gitwebdir_SQ = $(subst ','\'',$(gitwebdir)) SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) @@ -1966,10 +1978,45 @@ git.res: git.rc GIT-VERSION-FILE # This makes sure we depend on the NO_PERL setting itself. $(SCRIPT_PERL_GEN): GIT-BUILD-OPTIONS +# Used for substitution in Perl modules. Disabled when using RUNTIME_PREFIX_PERL +# since the locale directory is injected. +perl_localedir_SQ = $(localedir_SQ) + ifndef NO_PERL PERL_HEADER_TEMPLATE = perl/header_templates/fixed_prefix.template.pl PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ):$(perllibdir_SQ) +PERL_DEFINES := $(PERL_PATH_SQ) $(PERLLIB_EXTRA_SQ) $(perllibdir_SQ) +PERL_DEFINES += $(RUNTIME_PREFIX_PERL) + +# Support Perl runtime prefix. In this mode, a different header is installed +# into Perl scripts. This header requires Perl resource directories to be +# relative to the executable installation path, $(gitexecdir), and uses this +# property to resolve $(perllibdir) and $(localedir). +ifdef RUNTIME_PREFIX_PERL + +PERL_HEADER_TEMPLATE = perl/header_templates/runtime_prefix.template.pl + +# Don't export a fixed $(localedir) path; it will be resolved by the Perl header +# at runtime. +perl_localedir_SQ = + +ifneq ($(filter /%,$(firstword $(perllibdir_relative))),) +$(error RUNTIME_PREFIX_PERL requires a relative perllibdir, not: $(perllibdir)) +endif + +ifneq ($(filter /%,$(firstword $(gitexecdir_relative))),) +$(error RUNTIME_PREFIX_PERL requires a relative gitexecdir, not: $(gitexecdir)) +endif + +ifneq ($(filter /%,$(firstword $(localedir_relative))),) +$(error RUNTIME_PREFIX_PERL requires a relative localedir, not: $(localedir)) +endif + +endif + +PERL_DEFINES += $(gitexecdir) $(perllibdir) $(localedir) + $(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE $(QUIET_GEN)$(RM) $@ $@+ && \ sed -e '1{' \ @@ -1982,6 +2029,7 @@ $(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE chmod +x $@+ && \ mv $@+ $@ +PERL_DEFINES := $(subst $(space),:,$(PERL_DEFINES)) GIT-PERL-DEFINES: FORCE @FLAGS='$(PERL_DEFINES)'; \
[PATCH v5 0/3] RUNTIME_PREFIX relocatable Git
This patch set expands support for the RUNTIME_PREFIX configuration flag, currently only used on Windows builds, to include Linux, Darwin, and FreeBSD. When Git is built with RUNTIME_PREFIX enabled, it resolves its ancillary paths relative to the runtime location of its executable rather than hard-coding them at compile-time, allowing a Git installation to be deployed to a path other than the one in which it was built/installed. Note that RUNTIME_PREFIX is not currently used outside of Windows. This patch set should not have an impact on default Git builds. I'm uploading an updated patch set now that avarab@'s Perl Makefile simplification patch set has advanced and seems to be stable. Please take a look and let me know what you think! Previous threads: v1: https://public-inbox.org/git/20171116170523.28696-1-...@google.com/ v2: https://public-inbox.org/git/20171119173141.4896-1-...@google.com/ v3: https://public-inbox.org/git/20171127164055.93283-1-...@google.com/ v4: https://public-inbox.org/git/20171129223807.91343-1-...@google.com/ Changes in v5 from v4: - Rebase on top of "next", notably incorporating the "ab/simplify-perl-makefile" branch. - Cleaner Makefile relative path enforcement. - Update Perl header template path now that the "perl/" directory has fewer build-related files in it. - Update Perl runtime prefix header to use a general system path resolution function. - Implemented the injection of the locale directory into Perl's "Git/I18N.pm" module from the runtime prefix Perl script header. - Updated Perl's "Git/I18N.pm" module to accept injected locale directory. - Added more content to some comments. === Testing === The latest patch set is available for testing on my GitHub fork, including "travis.ci" testing. The "runtime-prefix" branch includes a "config.mak" commit that enables runtime prefix for the Travis build; the "runtime-prefix-no-config" omits this file, testing this patch without runtime prefix enabled: - https://github.com/danjacques/git/tree/runtime-prefix - https://travis-ci.org/danjacques/git/branches Built/tested locally using this "config.mak" w/ autoconf: === Example config.mak === ## (BEGIN config.mak) RUNTIME_PREFIX = YesPlease RUNTIME_PREFIX_PERL = YesPlease gitexecdir = libexec/git-core template_dir = share/git-core/templates sysconfdir = etc ## (END config.mak) === Revision History === Changes in v4 from v3: - Incorporated some quoting and Makefile dependency fixes, courtesy of <johannes.schinde...@gmx.de>. Changes in v3 from v2: - Broken into multiple patches now that Perl is isolated in its own RUNTIME_PREFIX_PERL flag. - Working with avarab@, several changes to Perl script runtime prefix support: - Moved Perl header body content from Makefile into external template file(s). - Added generic "perllibdir" variable to override Perl installation path. - RUNTIME_PREFIX_PERL generated script header is more descriptive and consistent with how the C version operates. - Fixed Generated Perl header Makefile dependency, should rebuild when dependent files and flags change. - Changed some of the new RUNTIME_PREFIX trace strings to use consistent formatting and terminology. Changes in v2 from v1: - Added comments and formatting to improve readability of platform-sepecific executable path resolution sleds in `git_get_exec_path`. - Consolidated "cached_exec_path" and "argv_exec_path" globals into "exec_path_value". - Use `strbuf_realpath` instead of `realpath` for procfs resolution. - Removed new environment variable exports. Git with RUNTIME_PREFIX no longer exports or consumes any additional environment information. - Updated Perl script resolution strategy: rather than having Git export the relative executable path to the Perl scripts, they now resolve it independently when RUNTIME_PREFIX_PERL is enabled. - Updated resolution strategy for "gettext()": use system_path() instead of special environment variable. - Added `sysctl` executable resolution support for BSDs that don't mount "procfs" by default (most of them). Dan Jacques (3): Makefile: generate Perl header from template file Makefile: add Perl runtime prefix support exec_cmd: RUNTIME_PREFIX on some POSIX systems .gitignore | 1 + Makefile | 114 +-- cache.h | 1 + common-main.c| 4 +- config.mak.uname | 7 + exec_cmd.c | 241 --- exec_cmd.h | 4 +- gettext.c| 8 +- git.c| 2 +- perl/Git/I18N.pm
Need to add test artifacts to .gitignore
FYI, I've noticed when building from "pu" that neither the "t/helper/test-print-values" or "t/helper/test-print-larger-than-ssize" testing artifacts added to Makefile in this patch series are not added to "t/helper/.gitignore" like other helpers, resulting in the testing artifact being recognized as an untracked file.
Re: [PATCH v4 1/4] Makefile: generate Perl header from template file
Johannes Sixt wrote: > I don't know what I tested last week; most likely not the version of the > patch I quoted above. > > Today's version, with the tip at 5d7f59c391ce, is definitely bogus > with its quoting. It needs the patch below, otherwise an unquoted > semicolon may be expanded from $(pathsep). This would terminate the sed > command, of course. Thanks for checking! The patch that you quoted above looks like it's from this "v4" thread; however, the patch that you are diffing against in your latest reply seems like it is from an earlier version. I believe that the $(pathsep) changes in your proposed patch are already present in v4, having been caught by Johannes, so perhaps you were using an older version of the patch as the diffbase? That change only appeared in v4, so any older version would have had the previous incorrect quoting. I think the reason that is necessary to remove the single quotes is not because the ";" is terminating the `sed` expression, but because it's terminating the entire shell stanza, causing the shell to execute two commands: 1) {"sed" "-e" "s=@@PATHSEP@@="} 2) {"=g" "-e" "s=@@INSTLIBDIR@@=..." ...} By including the ";" within the single-tick-protected `sed` argument, the shell receives the entire block, "s=@@PATHSEP@@=;=", as a single string. Also see Johannes' explanation here: https://github.com/danjacques/git/pull/1/commits/57dc265478692ea2a395fc61fa122cb73ce58dc3 Could you apply this v4 patch series and confirm that it is working for you? Or, if I am mistaken and your patch is correctly against this "v4" patch series, let me know and I'll try and figure out what I'm missing. Thanks again! -Dan
Re: [PATCH v2] Makefile: replace perl/Makefile.PL with simple make rules
Junio C Hamano writes: > Well the thing is that I cannot queue this and Dan's at the same > time, while both of these topics are expected to be in flux. For > today's pushout, I tentatively kicked out Dan's relative path series > and queued this one to see how well it works with the rest of the > system, after giving this patch another round of reading. > > It seemed that Dan was happy with (an earlier draft of?) this > build procedure simplification patch, so hopefully we can solidify > this one reasonably quickly and ask the relative path series to be > rebuilt on top of it? Sounds good to me! I'm in no rush, and if this is moving forward I'm more than happy to wait for it to land and rebase on top. I didn't want to weigh in too heavily on the actual details of this patch since I think the majority stakeholders are the folks who maintain the Perl subsystem and those who build distribution packages. My work on Perl only touches installation as a means to an end, and avarab@'s work does simplify this for me. Cheers, and thanks! -Dan
Re: [PATCH v4 3/4] RUNTIME_PREFIX relocatable Git
My initial set of replies are inline here: https://public-inbox.org/git/20171129223807.91343-1-...@google.com/T/#m1ff5cda787eaea4a4015a8f00a8be5966122c73a I put together this solution for the I18N module. It exports "localedir" to the Perl header and injects the correct value into Git::I18N. It also suppresses the emission of the full ++LOCALEDIR++ when in runtime prefix mode. One downside of this approach is that, since the point of resolution happens at the beginning of the script execution, external users of the runtime prefix Git::I18N module will not be able to resolve the locale directory. I think this is okay, though, since RUNTIME_PREFIX_PERL is decidedly *not* intended for system installation and is not trying to offer system module import portability. After looking a bit at your $ENV{GIT_EXEC_PATH} optimization suggestion, I ended up favoring the current usage of FindBin::Bin for a few reasons: - Encoding the relative GITEXECDIR into the script is more consistent with how "exec_cmd.c" does its own self-resolution. - The resolution code is a bit more readable, both in terms of what it's doing and where it starts from. - It makes the scripts individually executable, rather than having to go through the Git wrapper. This is, minimally, useful for testing. I admittedly don't know much about FindBin, so if it has a downside that could outweigh this I'm more than happy to reevaluate. With respect to testing, I did find "GIT_TEST_INSTALLED". Unfortunately, it doesn't seem to work against the full test suite even on master, and individual tests, especially Perl and locale, set their own path expectations. I think including installation-relative testing here would take a fair amount of work. Note that this is a replacement for [PATCH v4 3/4], so if you're trying to apply it, you will need to build it on top of the preceding patches. Many thanks, -Dan --- Makefile | 59 +++--- perl/Git/I18N.pm | 2 +- perl/Makefile | 17 ++ perl/header_runtime_prefix.pl.template | 31 ++ t/test-lib.sh | 13 +--- 5 files changed, 107 insertions(+), 15 deletions(-) create mode 100644 perl/header_runtime_prefix.pl.template diff --git a/Makefile b/Makefile index 80904f8b0..558bd3ebb 100644 --- a/Makefile +++ b/Makefile @@ -425,6 +425,10 @@ all:: # # to say "export LESS=FRX (and LV=-c) if the environment variable # LESS (and LV) is not set, respectively". +# +# Define RUNTIME_PREFIX_PERL to configure Git's PERL commands to locate Git +# support libraries relative to their filesystem path instead of hard-coding +# it. GIT-VERSION-FILE: FORCE @$(SHELL_PATH) ./GIT-VERSION-GEN @@ -462,6 +466,7 @@ ARFLAGS = rcs # mandir # infodir # htmldir +# localedir # perllibdir # This can help installing the suite in a relocatable way. @@ -483,9 +488,12 @@ lib = lib # DESTDIR = pathsep = : +gitexecdir_relative = $(patsubst $(prefix)/%,%,$(gitexecdir)) mandir_relative = $(patsubst $(prefix)/%,%,$(mandir)) infodir_relative = $(patsubst $(prefix)/%,%,$(infodir)) +localedir_relative = $(patsubst $(prefix)/%,%,$(localedir)) htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir)) +perllibdir_relative = $(patsubst $(prefix)/%,%,$(perllibdir)) export prefix bindir sharedir sysconfdir gitwebdir localedir @@ -1718,11 +1726,13 @@ bindir_relative_SQ = $(subst ','\'',$(bindir_relative)) mandir_relative_SQ = $(subst ','\'',$(mandir_relative)) infodir_relative_SQ = $(subst ','\'',$(infodir_relative)) localedir_SQ = $(subst ','\'',$(localedir)) +localedir_relative_SQ = $(subst ','\'',$(localedir_relative)) gitexecdir_SQ = $(subst ','\'',$(gitexecdir)) +gitexecdir_relative_SQ = $(subst ','\'',$(gitexecdir_relative)) template_dir_SQ = $(subst ','\'',$(template_dir)) htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative)) prefix_SQ = $(subst ','\'',$(prefix)) -perllibdir_SQ = $(subst ','\'',$(perllibdir)) +perllibdir_relative_SQ = $(subst ','\'',$(perllibdir_relative)) gitwebdir_SQ = $(subst ','\'',$(gitwebdir)) SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) @@ -1965,14 +1975,52 @@ perl/PM.stamp: GIT-PERL-DEFINES FORCE $(RM) $@+ PERL_HEADER_TEMPLATE = perl/header_fixed_prefix.pl.template +perl_localedir = $(localedir) PERL_DEFINES := $(PERL_PATH_SQ) $(PERLLIB_EXTRA_SQ) -PERL_DEFINES += $(NO_PERL_MAKEMAKER) -PERL_DEFINES += $(perllibdir) +PERL_DEFINES += $(NO_PERL_MAKEMAKER) $(RUNTIME_PREFIX_PERL) + +# Support Perl runtime prefix. In this mode, a different header is installed +# into Perl scripts. This header expects both the scripts and their support +# library to be installed relative to $(prefix), and resolves the path to +# the Perl libraries (perllibdir) from the executable's current path +# (gitexecdir). +# +# This configuration requires both $(perllibdir) and $(gitexecdir) to be +# relative paths, and will error if
Re: [PATCH v4 1/4] Makefile: generate Perl header from template file
On Fri, 1 Dec 2017, Johannes Sixt wrote: >>> This doesn't work, unfortunately. When $(pathsep) is ';', we get an >>> incomplete sed expression because ';' is also a command separator in the >>> sed language. >> >> Funny, I tried this also with ';' as pathsep, and it worked in the Git for >> Windows SDK... > > My ancient sed vs. your modern sed, perhaps? I can check this on Monday. If you wouldn't mind, that would be much appreciated. Did you actually observe this issue, or is it just coming up in review? I am not a `sed` wizard, but perhaps the tool is ignoring the semicolon because it's in the middle of the "s" expression? The shell may similarly be ignoring it because it's nested in between single-quotes? -Dan
Re: [PATCH v4 0/4] RUNTIME_PREFIX relocatable Git
> In general this whole thing structurally looks good to me with the > caveats noted in other review E-Mails. > > I haven't done anything but skim the details of the "where's my > executable" C code though, just looked at what it's doing structurally. > > I think it makes sense for this to land first ahead of my patch. This is > an actual feature you need, whereas I just hate our use of MakeMaker, > but that can wait, unless you're keen to rebase this on my patch. Would > probably make your whole diff a bit shorter. I'm not strictly pressed for time here, so we can put this off if that's strategically appropriate. Chromiuum, right now, just manually patches upstream Git with a similar patch set, so it's working and function. This is just an effort to upstream those changes for everyone else to enjoy! I think that landing in either order is probably okay, so if your RFC goes through pretty quickly I don't mind rebasing, but if this is otherwise good to go in v5, I wouldn't mind landing it and then removing the obsoleted parts during the Makefile update. > The whole converting our absolute to relative paths in the make code is > unavoidably ugly, but after having an initial knee-jerk reaction to it I > don't see how it can be avoided. I was hoping most of these paths > could/would just be a fixed path away from our libexec path, but alas > due to having had these configurable all along that simplicity seems out > of reach. Yeah I spent no small amount of time massaging that code hoping some better formulation would shake out, and this is what I ended up with. UNTIME_PREFIX_PERL is a specialty build with a stronger set of assumptions than the standard installation (RE prefix-relative paths). > Maybe I asked this before, but I don't see any obvious reason for why > RUNTIME_PREFIX_PERL is a different thing than RUNTIME_PREFIX as opposed > to us just doing the right thing for the perl scripts. I did this to isolate Windows builds from the Perl script changes. Git-for- Windows uses (invented) RUNTIME_PREFIX, but runs its Perl scripts in a MinGW sub-environment which, internally, has the Perl libraries installed at a fixed path, so it doesn't need any special resolution logic. I support that if Git-for-Windows wants to, a trivial future patch can merge the two, so I opted to play it safe and keep these changes isolated. === > We could use $ENV{GIT_EXEC_PATH} instead of FindBin here though, I > missed that the first time. But that's just a nano-optimization. I just > wondered whether git wasn't already passing us this info. Oh good idea - I'll go ahead and do this. > There is one remaining bug here. Git::I18N isn't doing the right thing, > I installed in /tmp/git and moved to /tmp/git2, and it has: > > our $TEXTDOMAINDIR = $ENV{GIT_TEXTDOMAINDIR} || '/tmp/git/share/locale'; > > And GIT_TEXTDOMAINDIR is not passed by git (it's only used for the tests > IIRC). Would need a similar treatment as this. Easiest to just set the > path we find here in $Git::Whatever and pick it up in $Git::I18N later, > it's not like anyone uses it outside of git.git. Good catch! I'm going to see what I can do here. > But that does raise a more general concern for me. Isn't there some way > we can run the test suite against an installed git (don't remember), > then build, install, move the dir, and run the tests from the moved dir. > > That would have caught this bug, and anything else that may be lurking > still. I am not aware of such an option, but I'll take a look again. This sort of thing might just require a reformulation of the test suite in general to make it run against a Git installation instead of the intermediate artifacts. A positive outcome would be the ability to remove the Perl path environment variable hacks ($ENV{...} || ...) and just use production resolution logic, increasing the test surface! But I think that's a bit more work than I have time for at the moment. === > Noticed after I sent the last E-Mail, this is missing @@INSTLIBDIR@@ > which per my reading of it being initially introduced should be here in > addition to this relative path. > > My reading of the intial patch that added it, as indicated in my patch, > is that it's the dir we're going to be installing our libs to, so I > didn't fiddle with it, but I think with your patches we need that dir > *and* or own $perllibdir. INSTLIBDIR is used for the standard fixed-prefix header, but not in this one. This one uses a combination of GITEXECDIR and PERLLIBDIR. PERLLIBDIR is effectively the prefix-relative part of INSTLIBDIR, so it's here in spirit! Thanks for taking the time to review! I'll go ahead and see what I can do RE your comments. Cheers, -Dan
[PATCH v4 2/4] Makefile: add support for "perllibdir"
Add the "perllibdir" Makefile variable, which allows the customization of the Perl library installation path. The Perl library installation path is currently left entirely to the Perl Makefile implementation, either MakeMaker (default) or a fixed path when NO_PERL_MAKEMAKER is enabled. This patch introduces "perllibdir", a Makefile variable that can override that Perl module installation path. As with some other Makefile variables, "perllibdir" may be either absolute or relative. In the latter case, it is treated as relative to "$(prefix)". Add some incidental documentation to perl/Makefile. Explicitly specifying an installation path is necessary for Perl runtime prefix support, as runtime prefix resolution code must know in advance where the Perl support modules are installed. Signed-off-by: Dan Jacques <d...@google.com> --- Makefile | 18 +- perl/Makefile | 52 ++-- 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index f7c4ac207..80904f8b0 100644 --- a/Makefile +++ b/Makefile @@ -462,6 +462,7 @@ ARFLAGS = rcs # mandir # infodir # htmldir +# perllibdir # This can help installing the suite in a relocatable way. prefix = $(HOME) @@ -1721,6 +1722,7 @@ gitexecdir_SQ = $(subst ','\'',$(gitexecdir)) template_dir_SQ = $(subst ','\'',$(template_dir)) htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative)) prefix_SQ = $(subst ','\'',$(prefix)) +perllibdir_SQ = $(subst ','\'',$(perllibdir)) gitwebdir_SQ = $(subst ','\'',$(gitwebdir)) SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) @@ -1955,17 +1957,22 @@ $(SCRIPT_PERL_GEN): perl/perl.mak perl/perl.mak: perl/PM.stamp -perl/PM.stamp: FORCE +perl/PM.stamp: GIT-PERL-DEFINES FORCE @$(FIND) perl -type f -name '*.pm' | sort >$@+ && \ + cat GIT-PERL-DEFINES >>$@+ && \ $(PERL_PATH) -V >>$@+ && \ { cmp $@+ $@ >/dev/null 2>/dev/null || mv $@+ $@; } && \ $(RM) $@+ -perl/perl.mak: GIT-CFLAGS GIT-PREFIX perl/Makefile perl/Makefile.PL - $(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' $(@F) - PERL_HEADER_TEMPLATE = perl/header_fixed_prefix.pl.template -PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ) + +PERL_DEFINES := $(PERL_PATH_SQ) $(PERLLIB_EXTRA_SQ) +PERL_DEFINES += $(NO_PERL_MAKEMAKER) +PERL_DEFINES += $(perllibdir) + +perl/perl.mak: GIT-CFLAGS GIT-PREFIX perl/Makefile perl/Makefile.PL + $(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' \ + prefix='$(prefix_SQ)' perllibdir='$(perllibdir_SQ)' $(@F) $(SCRIPT_PERL_GEN): % : %.perl perl/perl.mak GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE $(QUIET_GEN)$(RM) $@ $@+ && \ @@ -1979,6 +1986,7 @@ $(SCRIPT_PERL_GEN): % : %.perl perl/perl.mak GIT-PERL-DEFINES GIT-PERL-HEADER GI chmod +x $@+ && \ mv $@+ $@ +PERL_DEFINES := $(subst $(space),:,$(PERL_DEFINES)) GIT-PERL-DEFINES: FORCE @FLAGS='$(PERL_DEFINES)'; \ if test x"$$FLAGS" != x"`cat $@ 2>/dev/null`" ; then \ diff --git a/perl/Makefile b/perl/Makefile index f657de20e..b2aeeb0d8 100644 --- a/perl/Makefile +++ b/perl/Makefile @@ -1,6 +1,22 @@ # # Makefile for perl support modules and routine # +# This Makefile generates "perl.mak", which contains the actual build and +# installation directions. +# +# PERL_PATH must be defined to be the path of the Perl interpreter to use. +# +# prefix must be defined as the Git installation prefix. +# +# localedir must be defined as the path to the locale data. +# +# perllibdir may be optionally defined to override the default Perl module +# installation directory, which is relative to prefix. If perllibdir is not +# absolute, it will be treated as relative to prefix. +# +# NO_PERL_MAKEMAKER may be defined to use a built-in Makefile generation method +# instead of Perl MakeMaker. + makfile:=perl.mak modules = @@ -12,6 +28,16 @@ ifndef V QUIET = @ endif +# If a library directory is provided, and it is not an absolute path, resolve +# it relative to prefix. +ifneq ($(perllibdir),) +ifneq ($(filter /%,$(firstword $(perllibdir))),) +perllib_instdir = $(perllibdir) +else +perllib_instdir = $(prefix)/$(perllibdir) +endif +endif + all install instlibdir: $(makfile) $(QUIET)$(MAKE) -f $(makfile) $@ @@ -25,7 +51,12 @@ clean: $(makfile): PM.stamp ifdef NO_PERL_MAKEMAKER -instdir_SQ = $(subst ','\'',$(prefix)/lib) + +ifeq ($(perllib_instdir),) +perllib_instdir = $(prefix)/lib +endif + +instdir_SQ = $(subst ','\'',$(perllib_instdir)) modules += Git modules += Git/I18N @@ -42,7 +73,7 @@ modules += Git/SVN/Prompt modules += Git/SVN/Ra modules += Git/SVN/Utils -$(makfile): ../GIT-CFLAGS Makefile +$(makfile): ../GIT-CFLAGS ../GIT-PERL-DEFINES Makefile echo al
[PATCH v4 0/4] RUNTIME_PREFIX relocatable Git
Previous threads: v1: https://public-inbox.org/git/20171116170523.28696-1-...@google.com/ v2: https://public-inbox.org/git/20171119173141.4896-1-...@google.com/ v3: https://public-inbox.org/git/20171127164055.93283-1-...@google.com/ This is a small update to incorporate some Windows fixes from Johannes. At this point, it passes the full test suite on Linux, Mac, and FreeBSD, as well as the Travis.ci test suites, with and without RUNTIME_PREFIX/RUNTIME_PREFIX_PERL flags. I'm happy with the patch set, and feel that it is ready to move forward. However, while it's been looked at by several people, and I have incorporated reviewer feedback, the patch set hasn't received any formal LGTM-style responses yet. I'm not sure what standard of review is required to move forward with a patch on this project, so maybe this is totally fine, but I wanted to make sure to point this out. I also want to note Ævar Arnfjörð Bjarmason's RFC: https://public-inbox.org/git/20171129153436.24471-1-ava...@gmail.com/T/ The proposed patch set conflicts with the Perl installation directory changes in this patch set, as avarab@ notes. The proposed Perl installation process would simplify patch 0002 in this patch set. I don't think the landing order is terribly impactful - if this lands first, the patch in the RFC would delete a few more lines, and if this lands later, patch 0002 would largely not be necessary. Cheers, -Dan Built using this "config.mak" w/ autoconf: === BEGIN config.mak === RUNTIME_PREFIX = YesPlease RUNTIME_PREFIX_PERL = YesPlease gitexecdir = libexec/git-core template_dir = share/git-core/templates sysconfdir = etc === END config.mak === Changes in v4 from v3: - Incorporated some quoting and Makefile dependency fixes, courtesy of <johannes.schinde...@gmx.de>. Changes in v3 from v2: - Broken into multiple patches now that Perl is isolated in its own RUNTIME_PREFIX_PERL flag. - Working with avarab@, several changes to Perl script runtime prefix support: - Moved Perl header body content from Makefile into external template file(s). - Added generic "perllibdir" variable to override Perl installation path. - RUNTIME_PREFIX_PERL generated script header is more descriptive and consistent with how the C version operates. - Fixed Generated Perl header Makefile dependency, should rebuild when dependent files and flags change. - Changed some of the new RUNTIME_PREFIX trace strings to use consistent formatting and terminology. Changes in v2 from v1: - Added comments and formatting to improve readability of platform-sepecific executable path resolution sleds in `git_get_exec_path`. - Consolidated "cached_exec_path" and "argv_exec_path" globals into "exec_path_value". - Use `strbuf_realpath` instead of `realpath` for procfs resolution. - Removed new environment variable exports. Git with RUNTIME_PREFIX no longer exports or consumes any additional environment information. - Updated Perl script resolution strategy: rather than having Git export the relative executable path to the Perl scripts, they now resolve it independently when RUNTIME_PREFIX_PERL is enabled. - Updated resolution strategy for "gettext()": use system_path() instead of special environment variable. - Added `sysctl` executable resolution support for BSDs that don't mount "procfs" by default (most of them). Dan Jacques (4): Makefile: generate Perl header from template file Makefile: add support for "perllibdir" Makefile: add Perl runtime prefix support exec_cmd: RUNTIME_PREFIX on some POSIX systems .gitignore | 1 + Makefile | 111 +-- cache.h| 1 + common-main.c | 4 +- config.mak.uname | 7 + exec_cmd.c | 239 - exec_cmd.h | 4 +- gettext.c | 8 +- git.c | 2 +- perl/Makefile | 52 ++- perl/header_fixed_prefix.pl.template | 1 + perl/header_runtime_prefix.pl.template | 24 12 files changed, 396 insertions(+), 58 deletions(-) create mode 100644 perl/header_fixed_prefix.pl.template create mode 100644 perl/header_runtime_prefix.pl.template -- 2.15.0.chromium12
[PATCH v4 1/4] Makefile: generate Perl header from template file
Currently, the generated Perl script headers are emitted by commands in the Makefile. This mechanism restricts options to introduce alternative header content, needed by Perl runtime prefix support, and obscures the origin of the Perl script header. Change the Makefile to generate a header by processing a template file and move the header content into the "perl/" subdirectory. The processed generated will now be stored in the "GIT-PERL-HEADER" file. This allows the content of the Perl header to be controlled by changing the path of the template in the Makefile. Signed-off-by: Dan Jacques <d...@google.com> Thanks-to: Ævar Arnfjörð Bjarmason <ava...@gmail.com> Thanks-to: Johannes Schindelin <johannes.schinde...@gmx.de> --- .gitignore | 1 + Makefile | 24 +++- perl/header_fixed_prefix.pl.template | 1 + 3 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 perl/header_fixed_prefix.pl.template diff --git a/.gitignore b/.gitignore index 833ef3b0b..89bd7bd8a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /GIT-LDFLAGS /GIT-PREFIX /GIT-PERL-DEFINES +/GIT-PERL-HEADER /GIT-PYTHON-VARS /GIT-SCRIPT-DEFINES /GIT-USER-AGENT diff --git a/Makefile b/Makefile index e53750ca0..f7c4ac207 100644 --- a/Makefile +++ b/Makefile @@ -1964,18 +1964,15 @@ perl/PM.stamp: FORCE perl/perl.mak: GIT-CFLAGS GIT-PREFIX perl/Makefile perl/Makefile.PL $(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' $(@F) +PERL_HEADER_TEMPLATE = perl/header_fixed_prefix.pl.template PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ) -$(SCRIPT_PERL_GEN): % : %.perl perl/perl.mak GIT-PERL-DEFINES GIT-VERSION-FILE + +$(SCRIPT_PERL_GEN): % : %.perl perl/perl.mak GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE $(QUIET_GEN)$(RM) $@ $@+ && \ - INSTLIBDIR=`MAKEFLAGS= $(MAKE) -C perl -s --no-print-directory instlibdir` && \ - INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \ - INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \ sed -e '1{' \ -e 's|#!.*perl|#!$(PERL_PATH_SQ)|' \ - -e 'h' \ - -e 's=.*=use lib (split(/$(pathsep)/, $$ENV{GITPERLLIB} || "'"$$INSTLIBDIR"'"));=' \ - -e 'H' \ - -e 'x' \ + -e 'rGIT-PERL-HEADER' \ + -e 'G' \ -e '}' \ -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \ $< >$@+ && \ @@ -1989,6 +1986,15 @@ GIT-PERL-DEFINES: FORCE echo "$$FLAGS" >$@; \ fi +GIT-PERL-HEADER: $(PERL_HEADER_TEMPLATE) GIT-PERL-DEFINES perl/perl.mak Makefile + $(QUIET_GEN)$(RM) $@ && \ + INSTLIBDIR=`MAKEFLAGS= $(MAKE) -C perl -s --no-print-directory instlibdir` && \ + INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \ + INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \ + sed -e 's=@@PATHSEP@@=$(pathsep)=g' \ + -e 's=@@INSTLIBDIR@@='$$INSTLIBDIR'=g' \ + $< >$@+ && \ + mv $@+ $@ .PHONY: gitweb gitweb: @@ -2707,7 +2713,7 @@ ifndef NO_TCLTK endif $(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS $(RM) GIT-USER-AGENT GIT-PREFIX - $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PYTHON-VARS + $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS .PHONY: all install profile-clean clean strip .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell diff --git a/perl/header_fixed_prefix.pl.template b/perl/header_fixed_prefix.pl.template new file mode 100644 index 0..9a4bc4d30 --- /dev/null +++ b/perl/header_fixed_prefix.pl.template @@ -0,0 +1 @@ +use lib (split(/@@PATHSEP@@/, $ENV{GITPERLLIB} || "@@INSTLIBDIR@@")); -- 2.15.0.chromium12
[PATCH v4 4/4] exec_cmd: RUNTIME_PREFIX on some POSIX systems
Enable Git to resolve its own binary location using a variety of OS-specific and generic methods, including: - procfs via "/proc/self/exe" (Linux) - _NSGetExecutablePath (Darwin) - KERN_PROC_PATHNAME sysctl on BSDs. - argv0, if absolute (all, including Windows). This is used to enable RUNTIME_PREFIX support for non-Windows systems, notably Linux and Darwin. When configured with RUNTIME_PREFIX, Git will do a best-effort resolution of its executable path and automatically use this as its "exec_path" for relative helper and data lookups, unless explicitly overridden. Small incidental formatting cleanup of "exec_cmd.c". Signed-off-by: Dan Jacques <d...@google.com> Thanks-to: Robbie Iannucci <iannu...@google.com> Thanks-to: Junio C Hamano <gits...@pobox.com> --- Makefile | 35 +++- cache.h | 1 + common-main.c| 4 +- config.mak.uname | 7 ++ exec_cmd.c | 239 +++ exec_cmd.h | 4 +- gettext.c| 8 +- git.c| 2 +- 8 files changed, 260 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index 741d1583f..e663fda1f 100644 --- a/Makefile +++ b/Makefile @@ -416,6 +416,16 @@ all:: # # Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function. # +# Define HAVE_BSD_KERN_PROC_SYSCTL if your platform supports the KERN_PROC BSD +# sysctl function. +# +# Define PROCFS_EXECUTABLE_PATH if your platform mounts a "procfs" filesystem +# capable of resolving the path of the current executable. If defined, this +# must be the canonical path for the "procfs" current executable path. +# +# Define HAVE_NS_GET_EXECUTABLE_PATH if your platform supports calling +# _NSGetExecutablePath to retrieve the path of the running executable. +# # Define HAVE_GETDELIM if your system has the getdelim() function. # # Define PAGER_ENV to a SP separated VAR=VAL pairs to define @@ -426,6 +436,12 @@ all:: # to say "export LESS=FRX (and LV=-c) if the environment variable # LESS (and LV) is not set, respectively". # +# Define RUNTIME_PREFIX to configure Git to resolve its ancillary tooling and +# support files relative to the location of the runtime binary, rather than +# hard-coding them into the binary. Git installations built with RUNTIME_PREFIX +# can be moved to arbitrary filesystem locations. Users may want to enable +# RUNTIME_PREFIX_PERL as well (see below). +# # Define RUNTIME_PREFIX_PERL to configure Git's PERL commands to locate Git # support libraries relative to their filesystem path instead of hard-coding # it. @@ -466,6 +482,7 @@ ARFLAGS = rcs # mandir # infodir # htmldir +# localedir # perllibdir # This can help installing the suite in a relocatable way. @@ -491,6 +508,7 @@ mandir_relative = $(patsubst $(prefix)/%,%,$(mandir)) infodir_relative = $(patsubst $(prefix)/%,%,$(infodir)) sharedir_relative = $(patsubst $(prefix)/%,%,$(sharedir)) htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir)) +localedir_relative = $(patsubst $(prefix)/%,%,$(localedir)) export prefix bindir sharedir sysconfdir gitwebdir localedir @@ -1637,10 +1655,23 @@ ifdef HAVE_BSD_SYSCTL BASIC_CFLAGS += -DHAVE_BSD_SYSCTL endif +ifdef HAVE_BSD_KERN_PROC_SYSCTL + BASIC_CFLAGS += -DHAVE_BSD_KERN_PROC_SYSCTL +endif + ifdef HAVE_GETDELIM BASIC_CFLAGS += -DHAVE_GETDELIM endif +ifneq ($(PROCFS_EXECUTABLE_PATH),) + procfs_executable_path_SQ = $(subst ','\'',$(PROCFS_EXECUTABLE_PATH)) + BASIC_CFLAGS += '-DPROCFS_EXECUTABLE_PATH="$(procfs_executable_path_SQ)"' +endif + +ifdef HAVE_NS_GET_EXECUTABLE_PATH + BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH +endif + ifeq ($(TCLTK_PATH),) NO_TCLTK = NoThanks endif @@ -1723,6 +1754,7 @@ bindir_relative_SQ = $(subst ','\'',$(bindir_relative)) mandir_relative_SQ = $(subst ','\'',$(mandir_relative)) infodir_relative_SQ = $(subst ','\'',$(infodir_relative)) localedir_SQ = $(subst ','\'',$(localedir)) +localedir_relative_SQ = $(subst ','\'',$(localedir_relative)) gitexecdir_SQ = $(subst ','\'',$(gitexecdir)) template_dir_SQ = $(subst ','\'',$(template_dir)) htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative)) @@ -2185,6 +2217,7 @@ endif exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \ '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \ + '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \ '-DBINDIR="$(bindir_relative_SQ)"' \ '-DPREFIX="$(prefix_SQ)"' @@ -2202,7 +2235,7 @@ attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \ gettext.sp gettext.s gettext.o: GIT-PREFIX gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \ - -DGIT_LOCALE_PATH='"$(localedir_SQ)"' + -DGIT_LOCALE_PATH='"$(localedir_relative_SQ)"' http-push.sp http.sp http-walker.sp remote-curl.sp imap-send.
[PATCH v4 3/4] Makefile: add Perl runtime prefix support
Add a new Makefile flag, RUNTIME_PREFIX_PERL, which, when enabled, configures Perl scripts to locate the Git installation's Perl support libraries by resolving against the script's path, rather than hard-coding that path at build-time. Enabling RUNTIME_PREFIX_PERL overrides the system-specific Perl script installation path generated by MakeMaker to force installation into a platform-neutral location, "/share/perl5". This change enables Git's Perl scripts to work when their Git installation is relocated or moved to another system. Signed-off-by: Dan Jacques <d...@google.com> Thanks-to: Ævar Arnfjörð Bjarmason <ava...@gmail.com> Thanks-to: Johannes Schindelin <johannes.schinde...@gmx.de> --- Makefile | 40 +- perl/header_runtime_prefix.pl.template | 24 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 perl/header_runtime_prefix.pl.template diff --git a/Makefile b/Makefile index 80904f8b0..741d1583f 100644 --- a/Makefile +++ b/Makefile @@ -425,6 +425,10 @@ all:: # # to say "export LESS=FRX (and LV=-c) if the environment variable # LESS (and LV) is not set, respectively". +# +# Define RUNTIME_PREFIX_PERL to configure Git's PERL commands to locate Git +# support libraries relative to their filesystem path instead of hard-coding +# it. GIT-VERSION-FILE: FORCE @$(SHELL_PATH) ./GIT-VERSION-GEN @@ -485,6 +489,7 @@ pathsep = : mandir_relative = $(patsubst $(prefix)/%,%,$(mandir)) infodir_relative = $(patsubst $(prefix)/%,%,$(infodir)) +sharedir_relative = $(patsubst $(prefix)/%,%,$(sharedir)) htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir)) export prefix bindir sharedir sysconfdir gitwebdir localedir @@ -1967,7 +1972,38 @@ perl/PM.stamp: GIT-PERL-DEFINES FORCE PERL_HEADER_TEMPLATE = perl/header_fixed_prefix.pl.template PERL_DEFINES := $(PERL_PATH_SQ) $(PERLLIB_EXTRA_SQ) -PERL_DEFINES += $(NO_PERL_MAKEMAKER) +PERL_DEFINES += $(NO_PERL_MAKEMAKER) $(RUNTIME_PREFIX_PERL) + +# Support Perl runtime prefix. In this mode, a different header is installed +# into Perl scripts. This header expects both the scripts and their support +# library to be installed relative to $(prefix), and resolves the path to +# the Perl libraries (perllibdir) from the executable's current path +# (gitexecdir). +# +# This configuration requires both $(perllibdir) and $(gitexecdir) to be +# relative paths, and will error if this is not the case. +ifdef RUNTIME_PREFIX_PERL + +PERL_HEADER_TEMPLATE = perl/header_runtime_prefix.pl.template +PERL_DEFINES += $(gitexecdir) + +# RUNTIME_PREFIX_PERL requires a $(perllibdir) value. +ifeq ($(perllibdir),) +perllibdir = $(sharedir_relative)/perl5 +endif + +ifneq ($(filter /%,$(firstword $(gitexecdir))),) +$(error RUNTIME_PREFIX_PERL requires a relative gitexecdir, not: $(gitexecdir)) +endif +gitexecdir_relative_SQ = $(gitexecdir_SQ) + +ifneq ($(filter /%,$(firstword $(perllibdir))),) +$(error RUNTIME_PREFIX_PERL requires a relative perllibdir, not: $(perllibdir)) +endif +perllibdir_relative_SQ = $(perllibdir_SQ) + +endif + PERL_DEFINES += $(perllibdir) perl/perl.mak: GIT-CFLAGS GIT-PREFIX perl/Makefile perl/Makefile.PL @@ -2001,6 +2037,8 @@ GIT-PERL-HEADER: $(PERL_HEADER_TEMPLATE) GIT-PERL-DEFINES perl/perl.mak Makefile INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \ sed -e 's=@@PATHSEP@@=$(pathsep)=g' \ -e 's=@@INSTLIBDIR@@='$$INSTLIBDIR'=g' \ + -e 's=@@GITEXECDIR@@=$(gitexecdir_relative_SQ)=g' \ + -e 's=@@PERLLIBDIR@@=$(perllibdir_relative_SQ)=g' \ $< >$@+ && \ mv $@+ $@ diff --git a/perl/header_runtime_prefix.pl.template b/perl/header_runtime_prefix.pl.template new file mode 100644 index 0..fb9a9924d --- /dev/null +++ b/perl/header_runtime_prefix.pl.template @@ -0,0 +1,24 @@ +# BEGIN RUNTIME_PREFIX_PERL generated code. +# +# This finds our Git::* libraries relative to the script's runtime path. +BEGIN { + use lib split /@@PATHSEP@@/, + ( + $ENV{GITPERLLIB} + || + do { + require FindBin; + require File::Spec; + my $gitexecdir_relative = '@@GITEXECDIR@@'; + my $perllibdir_relative = '@@PERLLIBDIR@@'; + + ($FindBin::Bin =~ m=${gitexecdir_relative}$=) || + die('Unrecognized runtime path.'); + my $prefix = substr($FindBin::Bin, 0, -length($gitexecdir_relative)); + my $perllibdir = File::Spec->catdir($prefix, $perllibdir_relative); + (-e $perllibdir) || die("Invalid library path: $perllibdir"); + $perllibdir; + } + ); +} +# END RUNTIME_PREFIX_PERL generated code. -- 2.15.0.chromium12
Question regarding "next" merge
Junio, I read the "what's cooking in Git" notes and saw that you were intending to introduce this patch set into "next". Johannes pointed out some quoting errors that break Windows builds, and I have incorporated fixes in my working copy. I was going to hold off on publishing v4 in case some of the other reviewers had additional comments, but if you would prefer, I can publish them now before you merge, so "next" doesn't break on Windows. Please advise! Thanks, -Dan
Re: [PATCH v3 4/4] exec_cmd: RUNTIME_PREFIX on some POSIX systems
> In Git for Windows, we have an almost identical patch: > > https://github.com/git-for-windows/git/commit/bdd739bb2b0b > > We just guard the call to system_path() behind a test whether podir is > already absolute, but these days, system_path() does that itself. > > I am too little of a Perl expert to be helpful with the other patches, but > I would gladly runa build & test on Windows if you direct me to an > easily-pullable branch. Oh interesting - I've only peripherally looked at Git-for-Windows code, since Chromium uses its packages verbatim (thanks, BTW!). I think you're correct though - this patch set seems to be doing the same thing. I've been force-pushing my changes to the "runtime-prefix" branch of my Git fork for travis.ci testing. The latest commit on that branch adds a "config.mak" for testing, so one commit from the branch head will contain the sum set of this patch series applied at (or near) Git's master branch: https://github.com/danjacques/git/tree/runtime-prefix~1 Let me know if this is what you are looking for, and if I can offer any help with Windows testing. Thanks!
[PATCH v3 1/4] Makefile: generate Perl header from template file
Currently, the generated Perl script headers are emitted by commands in the Makefile. This mechanism restricts options to introduce alternative header content, needed by Perl runtime prefix support, and obscures the origin of the Perl script header. Change the Makefile to generate a header by processing a template file and move the header content into the "perl/" subdirectory. The processed generated will now be stored in the "GIT-PERL-HEADER" file. This allows the content of the Perl header to be controlled by changing the path of the template in the Makefile. Signed-off-by: Dan Jacques <d...@google.com> --- .gitignore | 1 + Makefile | 23 ++- perl/header_fixed_prefix.pl.template | 1 + 3 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 perl/header_fixed_prefix.pl.template diff --git a/.gitignore b/.gitignore index 833ef3b0b..89bd7bd8a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /GIT-LDFLAGS /GIT-PREFIX /GIT-PERL-DEFINES +/GIT-PERL-HEADER /GIT-PYTHON-VARS /GIT-SCRIPT-DEFINES /GIT-USER-AGENT diff --git a/Makefile b/Makefile index e53750ca0..5ad60a54c 100644 --- a/Makefile +++ b/Makefile @@ -1964,18 +1964,15 @@ perl/PM.stamp: FORCE perl/perl.mak: GIT-CFLAGS GIT-PREFIX perl/Makefile perl/Makefile.PL $(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' $(@F) +PERL_HEADER_TEMPLATE = perl/header_fixed_prefix.pl.template PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ) -$(SCRIPT_PERL_GEN): % : %.perl perl/perl.mak GIT-PERL-DEFINES GIT-VERSION-FILE + +$(SCRIPT_PERL_GEN): % : %.perl perl/perl.mak GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE $(QUIET_GEN)$(RM) $@ $@+ && \ - INSTLIBDIR=`MAKEFLAGS= $(MAKE) -C perl -s --no-print-directory instlibdir` && \ - INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \ - INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \ sed -e '1{' \ -e 's|#!.*perl|#!$(PERL_PATH_SQ)|' \ - -e 'h' \ - -e 's=.*=use lib (split(/$(pathsep)/, $$ENV{GITPERLLIB} || "'"$$INSTLIBDIR"'"));=' \ - -e 'H' \ - -e 'x' \ + -e 'rGIT-PERL-HEADER' \ + -e 'G' \ -e '}' \ -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \ $< >$@+ && \ @@ -1989,6 +1986,14 @@ GIT-PERL-DEFINES: FORCE echo "$$FLAGS" >$@; \ fi +GIT-PERL-HEADER: $(PERL_HEADER_TEMPLATE) GIT-PERL-DEFINES perl/perl.mak + $(QUIET_GEN)$(RM) $@ && \ + INSTLIBDIR=`MAKEFLAGS= $(MAKE) -C perl -s --no-print-directory instlibdir` && \ + INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \ + INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \ + sed -e 's=@@PATHSEP@@='$(pathsep)'=g' \ + -e 's=@@INSTLIBDIR@@='$$INSTLIBDIR'=g' \ + $< >$@ .PHONY: gitweb gitweb: @@ -2707,7 +2712,7 @@ ifndef NO_TCLTK endif $(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS $(RM) GIT-USER-AGENT GIT-PREFIX - $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PYTHON-VARS + $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS .PHONY: all install profile-clean clean strip .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell diff --git a/perl/header_fixed_prefix.pl.template b/perl/header_fixed_prefix.pl.template new file mode 100644 index 0..9a4bc4d30 --- /dev/null +++ b/perl/header_fixed_prefix.pl.template @@ -0,0 +1 @@ +use lib (split(/@@PATHSEP@@/, $ENV{GITPERLLIB} || "@@INSTLIBDIR@@")); -- 2.15.0.chromium12
[PATCH v3 4/4] exec_cmd: RUNTIME_PREFIX on some POSIX systems
Enable Git to resolve its own binary location using a variety of OS-specific and generic methods, including: - procfs via "/proc/self/exe" (Linux) - _NSGetExecutablePath (Darwin) - KERN_PROC_PATHNAME sysctl on BSDs. - argv0, if absolute (all, including Windows). This is used to enable RUNTIME_PREFIX support for non-Windows systems, notably Linux and Darwin. When configured with RUNTIME_PREFIX, Git will do a best-effort resolution of its executable path and automatically use this as its "exec_path" for relative helper and data lookups, unless explicitly overridden. Small incidental formatting cleanup of "exec_cmd.c". Signed-off-by: Dan Jacques <d...@google.com> --- Makefile | 35 +++- cache.h | 1 + common-main.c| 4 +- config.mak.uname | 7 ++ exec_cmd.c | 239 +++ exec_cmd.h | 4 +- gettext.c| 8 +- git.c| 2 +- 8 files changed, 260 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index a36815b49..014988318 100644 --- a/Makefile +++ b/Makefile @@ -416,6 +416,16 @@ all:: # # Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function. # +# Define HAVE_BSD_KERN_PROC_SYSCTL if your platform supports the KERN_PROC BSD +# sysctl function. +# +# Define PROCFS_EXECUTABLE_PATH if your platform mounts a "procfs" filesystem +# capable of resolving the path of the current executable. If defined, this +# must be the canonical path for the "procfs" current executable path. +# +# Define HAVE_NS_GET_EXECUTABLE_PATH if your platform supports calling +# _NSGetExecutablePath to retrieve the path of the running executable. +# # Define HAVE_GETDELIM if your system has the getdelim() function. # # Define PAGER_ENV to a SP separated VAR=VAL pairs to define @@ -426,6 +436,12 @@ all:: # to say "export LESS=FRX (and LV=-c) if the environment variable # LESS (and LV) is not set, respectively". # +# Define RUNTIME_PREFIX to configure Git to resolve its ancillary tooling and +# support files relative to the location of the runtime binary, rather than +# hard-coding them into the binary. Git installations built with RUNTIME_PREFIX +# can be moved to arbitrary filesystem locations. Users may want to enable +# RUNTIME_PREFIX_PERL as well (see below). +# # Define RUNTIME_PREFIX_PERL to configure Git's PERL commands to locate Git # support libraries relative to their filesystem path instead of hard-coding # it. @@ -466,6 +482,7 @@ ARFLAGS = rcs # mandir # infodir # htmldir +# localedir # perllibdir # This can help installing the suite in a relocatable way. @@ -491,6 +508,7 @@ mandir_relative = $(patsubst $(prefix)/%,%,$(mandir)) infodir_relative = $(patsubst $(prefix)/%,%,$(infodir)) sharedir_relative = $(patsubst $(prefix)/%,%,$(sharedir)) htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir)) +localedir_relative = $(patsubst $(prefix)/%,%,$(localedir)) export prefix bindir sharedir sysconfdir gitwebdir localedir @@ -1637,10 +1655,23 @@ ifdef HAVE_BSD_SYSCTL BASIC_CFLAGS += -DHAVE_BSD_SYSCTL endif +ifdef HAVE_BSD_KERN_PROC_SYSCTL + BASIC_CFLAGS += -DHAVE_BSD_KERN_PROC_SYSCTL +endif + ifdef HAVE_GETDELIM BASIC_CFLAGS += -DHAVE_GETDELIM endif +ifneq ($(PROCFS_EXECUTABLE_PATH),) + procfs_executable_path_SQ = $(subst ','\'',$(PROCFS_EXECUTABLE_PATH)) + BASIC_CFLAGS += '-DPROCFS_EXECUTABLE_PATH="$(procfs_executable_path_SQ)"' +endif + +ifdef HAVE_NS_GET_EXECUTABLE_PATH + BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH +endif + ifeq ($(TCLTK_PATH),) NO_TCLTK = NoThanks endif @@ -1723,6 +1754,7 @@ bindir_relative_SQ = $(subst ','\'',$(bindir_relative)) mandir_relative_SQ = $(subst ','\'',$(mandir_relative)) infodir_relative_SQ = $(subst ','\'',$(infodir_relative)) localedir_SQ = $(subst ','\'',$(localedir)) +localedir_relative_SQ = $(subst ','\'',$(localedir_relative)) gitexecdir_SQ = $(subst ','\'',$(gitexecdir)) template_dir_SQ = $(subst ','\'',$(template_dir)) htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative)) @@ -2184,6 +2216,7 @@ endif exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \ '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \ + '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \ '-DBINDIR="$(bindir_relative_SQ)"' \ '-DPREFIX="$(prefix_SQ)"' @@ -2201,7 +2234,7 @@ attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \ gettext.sp gettext.s gettext.o: GIT-PREFIX gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \ - -DGIT_LOCALE_PATH='"$(localedir_SQ)"' + -DGIT_LOCALE_PATH='"$(localedir_relative_SQ)"' http-push.sp http.sp http-walker.sp remote-curl.sp imap-send.sp: SPARSE_FLAGS += \ -DCURL_DISABLE_TYPECHECK diff --git a/cache.h b/cache.h index 2e1434505..
[PATCH v3 2/4] Makefile: add support for "perllibdir"
Add the "perllibdir" Makefile variable, which allows the customization of the Perl library installation path. The Perl library installation path is currently left entirely to the Perl Makefile implementation, either MakeMaker (default) or a fixed path when NO_PERL_MAKEMAKER is enabled. This patch introduces "perllibdir", a Makefile variable that can override that Perl module installation path. As with some other Makefile variables, "perllibdir" may be either absolute or relative. In the latter case, it is treated as relative to "$(prefix)". Add some incidental documentation to perl/Makefile. Explicitly specifying an installation path is necessary for Perl runtime prefix support, as runtime prefix resolution code must know in advance where the Perl support modules are installed. Signed-off-by: Dan Jacques <d...@google.com> --- Makefile | 18 +- perl/Makefile | 52 ++-- 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 5ad60a54c..7a2ed8857 100644 --- a/Makefile +++ b/Makefile @@ -462,6 +462,7 @@ ARFLAGS = rcs # mandir # infodir # htmldir +# perllibdir # This can help installing the suite in a relocatable way. prefix = $(HOME) @@ -1721,6 +1722,7 @@ gitexecdir_SQ = $(subst ','\'',$(gitexecdir)) template_dir_SQ = $(subst ','\'',$(template_dir)) htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative)) prefix_SQ = $(subst ','\'',$(prefix)) +perllibdir_SQ = $(subst ','\'',$(perllibdir)) gitwebdir_SQ = $(subst ','\'',$(gitwebdir)) SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) @@ -1955,17 +1957,22 @@ $(SCRIPT_PERL_GEN): perl/perl.mak perl/perl.mak: perl/PM.stamp -perl/PM.stamp: FORCE +perl/PM.stamp: GIT-PERL-DEFINES FORCE @$(FIND) perl -type f -name '*.pm' | sort >$@+ && \ + cat GIT-PERL-DEFINES >>$@+ && \ $(PERL_PATH) -V >>$@+ && \ { cmp $@+ $@ >/dev/null 2>/dev/null || mv $@+ $@; } && \ $(RM) $@+ -perl/perl.mak: GIT-CFLAGS GIT-PREFIX perl/Makefile perl/Makefile.PL - $(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' $(@F) - PERL_HEADER_TEMPLATE = perl/header_fixed_prefix.pl.template -PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ) + +PERL_DEFINES := $(PERL_PATH_SQ) $(PERLLIB_EXTRA_SQ) +PERL_DEFINES += $(NO_PERL_MAKEMAKER) +PERL_DEFINES += $(perllibdir) + +perl/perl.mak: GIT-CFLAGS GIT-PREFIX perl/Makefile perl/Makefile.PL + $(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' \ + prefix='$(prefix_SQ)' perllibdir='$(perllibdir_SQ)' $(@F) $(SCRIPT_PERL_GEN): % : %.perl perl/perl.mak GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE $(QUIET_GEN)$(RM) $@ $@+ && \ @@ -1979,6 +1986,7 @@ $(SCRIPT_PERL_GEN): % : %.perl perl/perl.mak GIT-PERL-DEFINES GIT-PERL-HEADER GI chmod +x $@+ && \ mv $@+ $@ +PERL_DEFINES := $(subst $(space),:,$(PERL_DEFINES)) GIT-PERL-DEFINES: FORCE @FLAGS='$(PERL_DEFINES)'; \ if test x"$$FLAGS" != x"`cat $@ 2>/dev/null`" ; then \ diff --git a/perl/Makefile b/perl/Makefile index f657de20e..b2aeeb0d8 100644 --- a/perl/Makefile +++ b/perl/Makefile @@ -1,6 +1,22 @@ # # Makefile for perl support modules and routine # +# This Makefile generates "perl.mak", which contains the actual build and +# installation directions. +# +# PERL_PATH must be defined to be the path of the Perl interpreter to use. +# +# prefix must be defined as the Git installation prefix. +# +# localedir must be defined as the path to the locale data. +# +# perllibdir may be optionally defined to override the default Perl module +# installation directory, which is relative to prefix. If perllibdir is not +# absolute, it will be treated as relative to prefix. +# +# NO_PERL_MAKEMAKER may be defined to use a built-in Makefile generation method +# instead of Perl MakeMaker. + makfile:=perl.mak modules = @@ -12,6 +28,16 @@ ifndef V QUIET = @ endif +# If a library directory is provided, and it is not an absolute path, resolve +# it relative to prefix. +ifneq ($(perllibdir),) +ifneq ($(filter /%,$(firstword $(perllibdir))),) +perllib_instdir = $(perllibdir) +else +perllib_instdir = $(prefix)/$(perllibdir) +endif +endif + all install instlibdir: $(makfile) $(QUIET)$(MAKE) -f $(makfile) $@ @@ -25,7 +51,12 @@ clean: $(makfile): PM.stamp ifdef NO_PERL_MAKEMAKER -instdir_SQ = $(subst ','\'',$(prefix)/lib) + +ifeq ($(perllib_instdir),) +perllib_instdir = $(prefix)/lib +endif + +instdir_SQ = $(subst ','\'',$(perllib_instdir)) modules += Git modules += Git/I18N @@ -42,7 +73,7 @@ modules += Git/SVN/Prompt modules += Git/SVN/Ra modules += Git/SVN/Utils -$(makfile): ../GIT-CFLAGS Makefile +$(makfile): ../GIT-CFLAGS ../GIT-PERL-DEFINES Makefile echo al
[PATCH v3 3/4] Makefile: add Perl runtime prefix support
Add a new Makefile flag, RUNTIME_PREFIX_PERL, which, when enabled, configures Perl scripts to locate the Git installation's Perl support libraries by resolving against the script's path, rather than hard-coding that path at build-time. Enabling RUNTIME_PREFIX_PERL overrides the system-specific Perl script installation path generated by MakeMaker to force installation into a platform-neutral location, "/share/perl5". This change enables Git's Perl scripts to work when their Git installation is relocated or moved to another system. Signed-off-by: Dan Jacques <d...@google.com> --- Makefile | 40 +- perl/header_runtime_prefix.pl.template | 24 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 perl/header_runtime_prefix.pl.template diff --git a/Makefile b/Makefile index 7a2ed8857..a36815b49 100644 --- a/Makefile +++ b/Makefile @@ -425,6 +425,10 @@ all:: # # to say "export LESS=FRX (and LV=-c) if the environment variable # LESS (and LV) is not set, respectively". +# +# Define RUNTIME_PREFIX_PERL to configure Git's PERL commands to locate Git +# support libraries relative to their filesystem path instead of hard-coding +# it. GIT-VERSION-FILE: FORCE @$(SHELL_PATH) ./GIT-VERSION-GEN @@ -485,6 +489,7 @@ pathsep = : mandir_relative = $(patsubst $(prefix)/%,%,$(mandir)) infodir_relative = $(patsubst $(prefix)/%,%,$(infodir)) +sharedir_relative = $(patsubst $(prefix)/%,%,$(sharedir)) htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir)) export prefix bindir sharedir sysconfdir gitwebdir localedir @@ -1967,7 +1972,38 @@ perl/PM.stamp: GIT-PERL-DEFINES FORCE PERL_HEADER_TEMPLATE = perl/header_fixed_prefix.pl.template PERL_DEFINES := $(PERL_PATH_SQ) $(PERLLIB_EXTRA_SQ) -PERL_DEFINES += $(NO_PERL_MAKEMAKER) +PERL_DEFINES += $(NO_PERL_MAKEMAKER) $(RUNTIME_PREFIX_PERL) + +# Support Perl runtime prefix. In this mode, a different header is installed +# into Perl scripts. This header expects both the scripts and their support +# library to be installed relative to $(prefix), and resolves the path to +# the Perl libraries (perllibdir) from the executable's current path +# (gitexecdir). +# +# This configuration requires both $(perllibdir) and $(gitexecdir) to be +# relative paths, and will error if this is not the case. +ifdef RUNTIME_PREFIX_PERL + +PERL_HEADER_TEMPLATE = perl/header_runtime_prefix.pl.template +PERL_DEFINES += $(gitexecdir) + +# RUNTIME_PREFIX_PERL requires a $(perllibdir) value. +ifeq ($(perllibdir),) +perllibdir = $(sharedir_relative)/perl5 +endif + +ifneq ($(filter /%,$(firstword $(gitexecdir))),) +$(error RUNTIME_PREFIX_PERL requires a relative $(gitexecdir)) +endif +gitexecdir_relative_SQ = $(gitexecdir_SQ) + +ifneq ($(filter /%,$(firstword $(perllibdir))),) +$(error RUNTIME_PREFIX_PERL requires a relative perllibdir) +endif +perllibdir_relative_SQ = $(perllibdir_SQ) + +endif + PERL_DEFINES += $(perllibdir) perl/perl.mak: GIT-CFLAGS GIT-PREFIX perl/Makefile perl/Makefile.PL @@ -2001,6 +2037,8 @@ GIT-PERL-HEADER: $(PERL_HEADER_TEMPLATE) GIT-PERL-DEFINES perl/perl.mak INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \ sed -e 's=@@PATHSEP@@='$(pathsep)'=g' \ -e 's=@@INSTLIBDIR@@='$$INSTLIBDIR'=g' \ + -e 's=@@GITEXECDIR@@='$(gitexecdir_relative_SQ)'=g' \ + -e 's=@@PERLLIBDIR@@='$(perllibdir_relative_SQ)'=g' \ $< >$@ .PHONY: gitweb diff --git a/perl/header_runtime_prefix.pl.template b/perl/header_runtime_prefix.pl.template new file mode 100644 index 0..fb9a9924d --- /dev/null +++ b/perl/header_runtime_prefix.pl.template @@ -0,0 +1,24 @@ +# BEGIN RUNTIME_PREFIX_PERL generated code. +# +# This finds our Git::* libraries relative to the script's runtime path. +BEGIN { + use lib split /@@PATHSEP@@/, + ( + $ENV{GITPERLLIB} + || + do { + require FindBin; + require File::Spec; + my $gitexecdir_relative = '@@GITEXECDIR@@'; + my $perllibdir_relative = '@@PERLLIBDIR@@'; + + ($FindBin::Bin =~ m=${gitexecdir_relative}$=) || + die('Unrecognized runtime path.'); + my $prefix = substr($FindBin::Bin, 0, -length($gitexecdir_relative)); + my $perllibdir = File::Spec->catdir($prefix, $perllibdir_relative); + (-e $perllibdir) || die("Invalid library path: $perllibdir"); + $perllibdir; + } + ); +} +# END RUNTIME_PREFIX_PERL generated code. -- 2.15.0.chromium12
[PATCH v3 0/4] RUNTIME_PREFIX relocatable Git
Previous threads: v1: https://public-inbox.org/git/20171116170523.28696-1-...@google.com/ v2: https://public-inbox.org/git/20171119173141.4896-1-...@google.com/ After working with avarab@, I isolated the Perl changes into a separate set of patches and adapted the code to be more correct and readable. I opted to prescribe a relative Perl library path instead of letting MakeMaker or the Config module choose one, since the latter both incorporate build system parameters and a major purpose of this is to be portable between ABI-compatible systems. I've tested this via Travis and run full test suite with and without RUNTIME_PREFIX/RUNTIME_PREFIX_PERL, and tested locally on Mac, Linux, and FreeBSD systems. Please take a look! Built using this "config.mak": === BEGIN config.mak === RUNTIME_PREFIX = YesPlease RUNTIME_PREFIX_PERL = YesPlease gitexecdir = libexec/git-core template_dir = share/git-core/templates sysconfdir = etc === END config.mak === Changes in v3 from v2: - Broken into multiple patches now that Perl is isolated in its own RUNTIME_PREFIX_PERL flag. - Working with avarab@, several changes to Perl script runtime prefix support: - Moved Perl header body content from Makefile into external template file(s). - Added generic "perllibdir" variable to override Perl installation path. - RUNTIME_PREFIX_PERL generated script header is more descriptive and consistent with how the C version operates. - Fixed Generated Perl header Makefile dependency, should rebuild when dependent files and flags change. - Changed some of the new RUNTIME_PREFIX trace strings to use consistent formatting and terminology. Changes in v2 from v1: - Added comments and formatting to improve readability of platform-sepecific executable path resolution sleds in `git_get_exec_path`. - Consolidated "cached_exec_path" and "argv_exec_path" globals into "exec_path_value". - Use `strbuf_realpath` instead of `realpath` for procfs resolution. - Removed new environment variable exports. Git with RUNTIME_PREFIX no longer exports or consumes any additional environment information. - Updated Perl script resolution strategy: rather than having Git export the relative executable path to the Perl scripts, they now resolve it independently when RUNTIME_PREFIX_PERL is enabled. - Updated resolution strategy for "gettext()": use system_path() instead of special environment variable. - Added `sysctl` executable resolution support for BSDs that don't mount "procfs" by default (most of them). Dan Jacques (4): Makefile: generate Perl header from template file Makefile: add support for "perllibdir" Makefile: add Perl runtime prefix support exec_cmd: RUNTIME_PREFIX on some POSIX systems .gitignore | 1 + Makefile | 110 +-- cache.h| 1 + common-main.c | 4 +- config.mak.uname | 7 + exec_cmd.c | 239 - exec_cmd.h | 4 +- gettext.c | 8 +- git.c | 2 +- perl/Makefile | 52 ++- perl/header_fixed_prefix.pl.template | 1 + perl/header_runtime_prefix.pl.template | 24 12 files changed, 395 insertions(+), 58 deletions(-) create mode 100644 perl/header_fixed_prefix.pl.template create mode 100644 perl/header_runtime_prefix.pl.template -- 2.15.0.chromium12
Re [PATCH 1/1] exec_cmd: RUNTIME_PREFIX on some POSIX systems
On Wed, 22 Nov 2017, Ævar Arnfjörð Bjarmason wrote: > > The latter case concerns me here. If the "Config" module is loading local > > system paths, then the relative pathing between "$Config{installsitelib}" > > and "$Config{siteprefixexp}" may not be consistent between systems, so an > > archive built from one system may not have a compatible relative > > directory structure when resolved with the Config module on another > > system. > > I don't see how this is different from any other option we build git > with. When we dynamically link to e.g. PCRE under RUNTIME_PREFIX*=Yes > you can move the installed git from /tmp/git to /tmp/git2, but it'll > still expect the specific version of the *.so libraries to be in > /usr/lib or whatever. PCRE brings up a good point. When I build Git for Chromium, I am actually statically linking in PCRE and most other runtime dependencies, so this is the sort of portability that I am targetting. The set of configuration options for full static linking, however, are too use-case-specific to build into Git, so this patch set merely seeks to fundamentally enable relocatability as an option for users to customize as they need. > Similarly we under the default MakeMaker path add the perl version to > the directories we have, you can move git from /tmp/git to /tmp/git2 no > problem, since that won't change the perl version, but if you upgrade > the global perl itself from 5.20 to 5.24 you'll need to re-build. As you note below, the Git PERL code below, doesn't include any compiled binary files. As far as I can tell, it's highly portable, with no real dependencies outside of PERL 5. To that end, I very much do want to transplant a Git distribution built on Machine-A w/ PERL 5.20 and dump it onto Machine-B w/ PERL 5.24 and have things work. My inclination is to follow your previous advice and export an installation path to MakeMaker. I found that "INSTALLSITELIB" did what I wanted. My working version exports a version-neutral installation path, "$(prefix)/share/perl5", to MakeMaker. I can then hard-code that relative path into the PERL header and use it for resolution, similar to what my previous patch is doing. NO_PERL_MAKEMAKER emitted a neutral library path, "$(prefix)/lib", and that was one of the things that made it an appealing option in my previous patch, but prescribing the path also works fine. At the end of the day, we're hard-coding "instlibdir" into the generated header, so it doesn't *really* matter if we use "$(prefix)/share/perl5/5.2.4" or "$(prefix)/share/perl5"; however, as a matter of preference, I would like to avoid naming the build system's PERL version into the deployable bundle when RUNTIME_PREFIX_PERL is set, so I'd opt for the latter. > [...] > If it's not neede dwe can just do "$p/lib". ATM my working code does (pseudocode and filling in values): 1) $gitexecpath = "libexec/git-core"; 2) $perllibpath = "share/perl5" 3) Assert that $FindBin::Bin ends with $gitexecpath (or die). 4) Strip $gitexecpath, result stored as $prefix. 5) Use File->concat($prefix, $perllibpath); This behaves similarly to how the C code resolves things, and seems adequate for this purpose. > Having said the above, I don't understand why we're using MakeMaker at > all and I think we should just get rid of it. > > I think the best way to proceed is probalby to just start getting rid of > the perl/* make stuff as discussed above. > > Is that something you're interested in / have time for, otherwise I > could see if I could find some time, but I don't have a lot these days. Once thought on why MakeMaker may have value is that third-party PERL tooling may want to import Git's PERL libraries. If this is something Git supports, we probably need something like MakeMaker to know where the system PERL library installation path is so it can put the Git library in the right place in standard (non-RUNTIME_PREFIX_PERL) installations. I agree that it shouldn't block this effort. My general judgement tends to be that that a patch set should not sway far from a single purpose, else it becomes hard to review and/or revert if it is problematic. Removing MakeMaker seems like an independent cleanup task, so I'd inclined to do that work in a separate patch set. Having dived this deeply into things, I wouldn't mind working on this if a block of time presents itself. Is there an issue tracker that the Git project uses where I could add this as a backburner/cleanup task, so it's not forgotten? Would it be appropriate to add a "TODO" comment in "perl/Makefile"? > [...] I could see if I could find some time, but I don't have a lot these > days. Thanks again for taking the time to work this out with me. -Dan
Re [PATCH 1/1] exec_cmd: RUNTIME_PREFIX on some POSIX systems
Ævar Arnfjörð Bjarmason @ 2017-11-20 21:50 UTC suggested: > So LeonT over at #p5p helped me with this. He believes this'll work > (unless MakeMaker INSTALL_BASE is set, but that should break the Git > install anyway): I think that the problem with this approach is that it uses the local "Config" module. The primary purpose of RUNTIME_PREFIX(_PERL) is that one can build/install Git into a directory, then either move that directory somewhere else or archive it and put it on a different (binary-compatible) system altogether. The latter case concerns me here. If the "Config" module is loading local system paths, then the relative pathing between "$Config{installsitelib}" and "$Config{siteprefixexp}" may not be consistent between systems, so an archive built from one system may not have a compatible relative directory structure when resolved with the Config module on another system. Since we control the installation process and paths, we know that the directory structure looks someting like: .../prefix/$GITEXECDIR/git-perl-script .../prefix/$RELPERLPATH/Git.pm Our goal is to, given the directory that "git-perl-script" belongs to, first identify the path for ".../prefix" and then append "$RELPERLPATH" to it to generate the full library path. The most straightforward way to do this, to me, is to: 1) Have the Makefile hard-code "$RELPERLPATH" and "$GITEXECDIR" (relative paths) into the header code. 2) Assert that "$FindBin::Bin" (the directory containing the script) ends with "$GITEXECDIR". 3) Remove "$GITEXECDIR" from the end of "$FindBin::Bin" to obtain ".../prefix" ($prefix). Simple string truncation is probably fine for this. 4) Add "File::Spec->catdir($prefix, $RELPERLPATH)" to "lib". I don't think path separators are a problem, since the Makefile uses "/" indiscriminately. Even Git-for-Windows seems to run its PERL scripts in a POSIX environment (mingw). Does this sound like a reasonable way to proceed?
Re(2): [PATCH 1/1] exec_cmd: RUNTIME_PREFIX on some POSIX systems
On Mon, 20 Nov 2017 22:00:10, Ævar Arnfjörð Bjarmason replied: > [...] Thanks for responding. I'll readily confess that PERL and the PERL ecosystem are not areas I'm very familiar with, so I'm really grateful for your feedback here. > You need to bust the perl/PM.stamp cache as a function of your > RUNTIME_PREFIX_PERL variable (or NO_PERL_MAKEMAKER). Good catch, I'll add that to the next version of the patch. > Other than that, is this whole NO_PERL_MAKEMAKER workaround just because > you couldn't figure out what the target RELPERLPATH is in > $prefix/$RELPERLPATH, which in this case is share/perl/5.26.1 ? Sort of. I actually had a version set hacked MakeMaker's $INSTALLSITELIB (same general result) and it worked. The executable path resolution logic that I built make assumptions about the layout of the installation, and I ended up favoring NO_PERL_MAKEMAKER because I could rely on its explicit and straightforward installation logic. I am not sure that MakeMaker adds value in a RUNTIME_PREFIX installation, since RUNTIME_PREFIX's motivation is fundamentally portable and my impression of MakeMaker is that much of the value that it adds is handling system-specific PERL installation details. Given that NO_PERL_MAKEMAKER is supported as a Git installation option, I opted to take advantage of the explicit installation rather than rely on MakeMaker as an intermediary. My other motivation is that if I integrate $RELPERLPATH into the MakeMaker installation, I'd still have to implement that behavior when NO_PERL_MAKEMAMER is enabled so that it is compatible with RUNTIME_PREFIX_PERL. I'd welcome any insight on whether this is the correct way to proceed. If we decode to go forward with NO_PERL_MAKEMAKER, I'm happy to add some better documentation in the Makefile to detail the rationale for forcefully enabling it. > 1. The regex match you're doing to munge the dir could be done as a >catdir($orig, '..', '..', 'lib'), that doesn't work as discussed >above, but *might* be more portable. I say might because I don't know >if the path string is always normalized to be unix-like, but if not >this won't work e.g on Windows where it'll have \ not /. The regex-based approach was motivated by a perceived value to conciseness. Since a larger header code block seems to be acceptable, I could emit "$(gitexecdir)" as a constant in the header and operate on it at runtime. This would avoid having to calculate the correct sequence of "../" to walk up from "$(gitexecdir)" directly in the Makefile. > 2. You are 'use'-ing FindBin there unconditionally (use is not function >local in perl), and implicitly assuming it loads File::Spec. > >Ignoring the NO_PERL_MAKEMAKER caveats above I'd suggest something >like this: Sounds good! I wasn't sure whether I should adhere to the one-line header that was being used before, but I am all for whitespace if that is acceptable. This seems a bit much to emit from a Makefile - what do you think about adding template files for each header in the "perl/" directory and preprocessing them via "sed" in the Makefile? > 3. I may be squinting at this wrong but it seems to me that between >your v1 and v2 reading GITPERLLIB here no longer makes any sense at >all. You used to set it in git itself, now it takes priority but >nothing sets it, presumably you'd have some external wrapper script >that'll set it? $GITPERLLIB is (as far as I can tell) used for testing, so that PERL scripts invoked by tests can find the Git support libraries. I think it is still necessary in both RUNTIME_PREFIX_PERL and default worlds because tests run Git out of the repository root, so relative resolution logic based on installation paths will not work. Thanks again! -Dan
[PATCH v2 0/1] exec_cmd: RUNTIME_PREFIX on some POSIX systems
clutter. I'm not opposed to restructuring it (e.g., use a resolution function vector), but I thought I'd try formatting first. Let me know what you think! === Changes in "v1" from previous version: - Added comments and formatting to improve readability of platform-sepecific executable path resolution sleds in `git_get_exec_path`. - Consolidated "cached_exec_path" and "argv_exec_path" globals into "exec_path_value". - Use `strbuf_realpath` instead of `realpath` for procfs resolution. - Removed new environment variable exports. Git with RUNTIME_PREFIX no longer exports or consumes any additional environment information. - Updated PERL script resolution strategy: rather than having Git export the relative executable path to the PERL scripts, they now resolve it independently when RUNTIME_PREFIX_PERL is enabled. - Updated resolution strategy for "gettext()": use system_path() instead of special environment variable. - Added `sysctl` executable resolution support for BSDs that don't mount "procfs" by default (most of them). Dan Jacques (1): exec_cmd: RUNTIME_PREFIX on some POSIX systems .gitignore | 1 + Makefile | 88 +--- cache.h | 1 + common-main.c| 4 +- config.mak.uname | 7 ++ exec_cmd.c | 239 +++ exec_cmd.h | 4 +- gettext.c| 8 +- git.c| 2 +- 9 files changed, 304 insertions(+), 50 deletions(-) -- 2.15.0.448.gf294e3d99a-goog
[PATCH 1/1] exec_cmd: RUNTIME_PREFIX on some POSIX systems
Enable Git to resolve its own binary location using a variety of OS-specific and generic methods, including: - procfs via "/proc/self/exe" (Linux) - _NSGetExecutablePath (Darwin) - KERN_PROC_PATHNAME sysctl on BSDs. - argv0, if absolute (all, including Windows). This is used to enable RUNTIME_PREFIX support for non-Windows systems, notably Linux and Darwin. When configured with RUNTIME_PREFIX, Git will do a best-effort resolution of its executable path and automatically use this as its "exec_path" for relative helper and data lookups, unless explicitly overridden. Git's PERL tooling now responds to RUNTIME_PREFIX_PERL. When configured, Git's generated PERL scripts resolve the Git library location relative to their runtime paths instead of hard-coding them. Structural changes were made to Makefile to support selective PERL header generation. Small incidental formatting cleanup of "exec_cmd.c". Signed-off-by: Dan Jacques <d...@google.com> --- .gitignore | 1 + Makefile | 88 +--- cache.h | 1 + common-main.c| 4 +- config.mak.uname | 7 ++ exec_cmd.c | 239 +++ exec_cmd.h | 4 +- gettext.c| 8 +- git.c| 2 +- 9 files changed, 304 insertions(+), 50 deletions(-) diff --git a/.gitignore b/.gitignore index 833ef3b0b..89bd7bd8a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /GIT-LDFLAGS /GIT-PREFIX /GIT-PERL-DEFINES +/GIT-PERL-HEADER /GIT-PYTHON-VARS /GIT-SCRIPT-DEFINES /GIT-USER-AGENT diff --git a/Makefile b/Makefile index ee9d5eb11..6fddb8b8f 100644 --- a/Makefile +++ b/Makefile @@ -296,7 +296,8 @@ all:: # Define PERL_PATH to the path of your Perl binary (usually /usr/bin/perl). # # Define NO_PERL_MAKEMAKER if you cannot use Makefiles generated by perl's -# MakeMaker (e.g. using ActiveState under Cygwin). +# MakeMaker (e.g. using ActiveState under Cygwin). NO_PERL_MAKEMAKER is +# automatically enabled when using RUNTIME_PREFIX_PERL. # # Define NO_PERL if you do not want Perl scripts or libraries at all. # @@ -416,6 +417,16 @@ all:: # # Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function. # +# Define HAVE_BSD_KERN_PROC_SYSCTL if your platform supports the KERN_PROC BSD +# sysctl function. +# +# Define PROCFS_EXECUTABLE_PATH if your platform mounts a "procfs" filesystem +# capable of resolving the path of the current executable. If defined, this +# must be the canonical path for the "procfs" current executable path. +# +# Define HAVE_NS_GET_EXECUTABLE_PATH if your platform supports calling +# _NSGetExecutablePath to retrieve the path of the running executable. +# # Define HAVE_GETDELIM if your system has the getdelim() function. # # Define PAGER_ENV to a SP separated VAR=VAL pairs to define @@ -425,6 +436,16 @@ all:: # # to say "export LESS=FRX (and LV=-c) if the environment variable # LESS (and LV) is not set, respectively". +# +# Define RUNTIME_PREFIX to configure Git to resolve its ancillary tooling and +# support files relative to the location of the runtime binary, rather than +# hard-coding them into the binary. Git installations built with RUNTIME_PREFIX +# can be moved to arbitrary filesystem locations. Users may want to enable +# RUNTIME_PREFIX_PERL as well (see below). +# +# Define RUNTIME_PREFIX_PERL to configure Git's PERL commands to locate Git +# support libraries relative to their filesystem path instead of hard-coding +# it. RUNTIME_PREFIX_PERL also sets NO_PERL_MAKEMAKER. GIT-VERSION-FILE: FORCE @$(SHELL_PATH) ./GIT-VERSION-GEN @@ -462,6 +483,7 @@ ARFLAGS = rcs # mandir # infodir # htmldir +# localedir # This can help installing the suite in a relocatable way. prefix = $(HOME) @@ -485,6 +507,7 @@ pathsep = : mandir_relative = $(patsubst $(prefix)/%,%,$(mandir)) infodir_relative = $(patsubst $(prefix)/%,%,$(infodir)) htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir)) +localedir_relative = $(patsubst $(prefix)/%,%,$(localedir)) export prefix bindir sharedir sysconfdir gitwebdir localedir @@ -1522,9 +1545,6 @@ ifdef SHA1_MAX_BLOCK_SIZE LIB_OBJS += compat/sha1-chunked.o BASIC_CFLAGS += -DSHA1_MAX_BLOCK_SIZE="$(SHA1_MAX_BLOCK_SIZE)" endif -ifdef NO_PERL_MAKEMAKER - export NO_PERL_MAKEMAKER -endif ifdef NO_HSTRERROR COMPAT_CFLAGS += -DNO_HSTRERROR COMPAT_OBJS += compat/hstrerror.o @@ -1549,6 +1569,15 @@ ifdef RUNTIME_PREFIX COMPAT_CFLAGS += -DRUNTIME_PREFIX endif +ifdef RUNTIME_PREFIX_PERL + # Control PERL library location so its paths and contents are not dependent on + # the host's PERL version. See perl/Makefile for more information. + NO_PERL_MAKEMAKER = YesPlease +endif +ifdef NO_PERL_MAKEMAKER + export NO_PERL_MAKEMAKER +endif + ifdef NO_PTHREADS BASIC_CFLAGS += -DNO_PTHREADS else @@ -1628,10
[PATCH 1/1] exec_cmd: RUNTIME_PREFIX on some POSIX systems
Enable Git to resolve its own binary location using a variety of OS-specific and generic methods, including: - procfs via "/proc/self/exe" (Linux) - _NSGetExecutablePath (Darwin) - argv0, if absolute (all, including Windows). This is used to enable RUNTIME_PREFIX support for non-Windows systems, notably Linux and Darwin. When configured with RUNTIME_PREFIX, Git will do a best-effort resolution of its executable path and automatically use this as its "exec_path" for relative helper and data lookups, unless explicitly overridden. Git will also always export and consume its resolved "exec_path" using the EXEC_PATH_ENVIRONMENT regardless of whether the user has overridden it, simplifying future lookups and ensuring consistency in Git tooling execution. When building with a runtime prefix, Git's PERL libraries are now installed to a consistently-named directory. This path is resolved and exported to Git's delegate PERL invocations using the GITPERLLIB environment variable. This enables Git's delegate PERL scripts to import Git's own PERL libraries from a path relative to the executable. Small incidental formatting cleanup of "exec_cmd.c". Signed-off-by: Dan Jacques <d...@google.com> --- Makefile | 29 ++-- builtin/receive-pack.c | 2 +- cache.h| 2 + common-main.c | 4 +- config.mak.uname | 4 ++ exec_cmd.c | 189 +++-- exec_cmd.h | 6 +- gettext.c | 7 +- git.c | 7 +- http-backend.c | 2 +- shell.c| 2 +- upload-pack.c | 2 +- 12 files changed, 217 insertions(+), 39 deletions(-) diff --git a/Makefile b/Makefile index ee9d5eb11..80db01706 100644 --- a/Makefile +++ b/Makefile @@ -296,7 +296,8 @@ all:: # Define PERL_PATH to the path of your Perl binary (usually /usr/bin/perl). # # Define NO_PERL_MAKEMAKER if you cannot use Makefiles generated by perl's -# MakeMaker (e.g. using ActiveState under Cygwin). +# MakeMaker (e.g. using ActiveState under Cygwin, or building with a fixed +# runtime prefix). # # Define NO_PERL if you do not want Perl scripts or libraries at all. # @@ -462,6 +463,7 @@ ARFLAGS = rcs # mandir # infodir # htmldir +# localedir # This can help installing the suite in a relocatable way. prefix = $(HOME) @@ -485,6 +487,7 @@ pathsep = : mandir_relative = $(patsubst $(prefix)/%,%,$(mandir)) infodir_relative = $(patsubst $(prefix)/%,%,$(infodir)) htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir)) +localedir_relative = $(patsubst $(prefix)/%,%,$(localedir)) export prefix bindir sharedir sysconfdir gitwebdir localedir @@ -1522,9 +1525,6 @@ ifdef SHA1_MAX_BLOCK_SIZE LIB_OBJS += compat/sha1-chunked.o BASIC_CFLAGS += -DSHA1_MAX_BLOCK_SIZE="$(SHA1_MAX_BLOCK_SIZE)" endif -ifdef NO_PERL_MAKEMAKER - export NO_PERL_MAKEMAKER -endif ifdef NO_HSTRERROR COMPAT_CFLAGS += -DNO_HSTRERROR COMPAT_OBJS += compat/hstrerror.o @@ -1547,6 +1547,14 @@ else endif ifdef RUNTIME_PREFIX COMPAT_CFLAGS += -DRUNTIME_PREFIX + + # Control PERL library location so it can be referenced by relocatable + # code. + NO_PERL_MAKEMAKER = YesPlease +endif + +ifdef NO_PERL_MAKEMAKER + export NO_PERL_MAKEMAKER endif ifdef NO_PTHREADS @@ -1632,6 +1640,15 @@ ifdef HAVE_GETDELIM BASIC_CFLAGS += -DHAVE_GETDELIM endif +ifneq ($(PROCFS_EXECUTABLE_PATH),) + procfs_executable_path_SQ = $(subst ','\'',$(PROCFS_EXECUTABLE_PATH)) + BASIC_CFLAGS += '-DPROCFS_EXECUTABLE_PATH="$(procfs_executable_path_SQ)"' +endif + +ifdef HAVE_NS_GET_EXECUTABLE_PATH + BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH +endif + ifeq ($(TCLTK_PATH),) NO_TCLTK = NoThanks endif @@ -1714,6 +1731,7 @@ bindir_relative_SQ = $(subst ','\'',$(bindir_relative)) mandir_relative_SQ = $(subst ','\'',$(mandir_relative)) infodir_relative_SQ = $(subst ','\'',$(infodir_relative)) localedir_SQ = $(subst ','\'',$(localedir)) +localedir_relative_SQ = $(subst ','\'',$(localedir_relative)) gitexecdir_SQ = $(subst ','\'',$(gitexecdir)) template_dir_SQ = $(subst ','\'',$(template_dir)) htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative)) @@ -2130,6 +2148,7 @@ endif exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \ '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \ + '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \ '-DBINDIR="$(bindir_relative_SQ)"' \ '-DPREFIX="$(prefix_SQ)"' @@ -2147,7 +2166,7 @@ attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \ gettext.sp gettext.s gettext.o: GIT-PREFIX gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \ - -DGIT_LOCALE_PATH='"$(localedir_SQ)"' + -DGIT_LOCALE_PATH='"$(localedir_relative_SQ)"' http-push.s
[PATCH 0/1] RUNTIME_PREFIX on POSIX systems.
Hello! This would be my first contribution to the Git project, so please accept my apology in advance for any mistakes and let me know what I can do better. This patch expands support for the RUNTIME_PREFIX configuration flag, currently only used on Windows builds, to include Linux, Darwin, and FreeBSD. When Git is built with RUNTIME_PREFIX enabled, it resolves its ancillary paths relative to the runtime location of its executable rather than hard-coding them at compile-time, allowing a Git installation to be deployed to a path other than the one in which it was installed. It was useful to create Git distribution bundles that could unpack fully-functional Git deployments to arbitrary locations in support of the Chromium project. Chromium has been using Git bundles built with a patch similar to this one on its Linux and Mac continuous integration fleet (plus some developer systems) for almost a year now. RUNTIME_PREFIX remains an optional configuration flag, so standard Git builds will not see any changes. However, with this patch applied, Linux, Darwin, and FreeBSD users can now optionally use "config.mak" to enable RUNTIME_PREFIX and build relocatable Git distributions. An example "config.mak" that builds relocatable Git binaries for Linux/Mac is: # BEGIN: config.mak RUNTIME_PREFIX = YesPlease gitexecdir = libexec/git-core template_dir = share/git-core/templates sysconfdir = etc # END: config.mak Implementation notes: It is unfortunately not straightforward to resolve the full absolute path of the currently-running binary. On some operating systems, notably Windows, this path is executively supplied as argv[0]. On other operating systems, however, argv[0] is supplied by the invoker (shell, script, kernel, etc.), and is not a reliable source of information about the running Git binary. The specific method that this patch employs for binary directory resolution varies depending on the operating system. On Linux and FreeBSD, Git resolves "/proc/self/exe" and "/proc/curproc/file" respectively. On Darwin, Git uses the "_NSGetExecutablePath" function. On all operating systems, notably Windows, Git continues to fall back to resolution against argv[0] when it is an absolute path. When RUNTIME_PREFIX is enabled, the resolved runtime path needs to be passed to ancillary Git tools for their own resolution requirements: - C-source Git programs will use the EXEC_PATH_ENVIRONMENT environment variable that Git already exports, ensuring that any launched tools use the same runtime prefix as the entry point. - PERL tooling needs to know how to locate Git's support libraries. When RUNTIME_PREFIX is configured, Git now exports the GITPERLLIB environment variable, a mechanism that Git's PERL tooling supports that appears to be built for testing. PERL scripts installed using MakeMaker incorporate the builder system's PERL version into their installation path, making it inconsistent to hard-code; consequently, this patch opts to disable MakeMaker for RUNTIME_PREFIX builds in order to deterministically control the destination of Git's support libraries. - Git also exports the GIT_TEXTDOMAINDIR environment variable when RUNTIME_PREFIX is set so that its locale configuration can be leveraged by Git tooling gettext(). Please note that this patch affects Windows Git builds, since the Windows Git project uses RUNTIME_PREFIX to support arbitrary installation paths. Notably, PERL scripts are now always installed without MakeMaker (if they weren't before), and EXEC_PATH_ENVIRONMENT is preferred by tools instead of re-resolving argv[0]. Chromium uses the stock redistributable Windows Git package, so I haven't had an opportunity to test this patch on that platform. Please take a look and let me know what you think. Thanks! -Dan Dan Jacques (1): exec_cmd: RUNTIME_PREFIX on some POSIX systems Makefile | 29 ++-- builtin/receive-pack.c | 2 +- cache.h| 2 + common-main.c | 4 +- config.mak.uname | 4 ++ exec_cmd.c | 189 +++-- exec_cmd.h | 6 +- gettext.c | 7 +- git.c | 7 +- http-backend.c | 2 +- shell.c| 2 +- upload-pack.c | 2 +- 12 files changed, 217 insertions(+), 39 deletions(-) -- 2.15.0.448.gf294e3d99a-goog