RUNTIME_PREFIX relocatable Git
v5 cover 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/[email protected]/
v2: https://public-inbox.org/git/[email protected]/
v3: https://public-inbox.org/git/[email protected]/
v4: https://public-inbox.org/git/[email protected]/
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 = YesPleaseRUNTIME_PREFIX_PERL = YesPlease
gitexecdir = libexec/git-coretemplate_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 <[email protected]>.
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 | 2 +- perl/header_templates/fixed_prefix.template.pl | 1 + perl/header_templates/runtime_prefix.template.pl | 32 +++ 12 files changed, 364 insertions(+), 53 deletions(-) create mode 100644 perl/header_templates/fixed_prefix.template.pl create mode 100644 perl/header_templates/runtime_prefix.template.pl
Signature · 1 line
2.15.0.chromium12
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.
Thanks-to: Ævar Arnfjörð Bjarmason <[email protected]>
Thanks-to: Johannes Schindelin <[email protected]>
--- .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
.gitignore +1 -0
@@ -3,6 +3,7 @@ /GIT-LDFLAGS /GIT-PREFIX /GIT-PERL-DEFINES +/GIT-PERL-HEADER /GIT-PYTHON-VARS /GIT-SCRIPT-DEFINES /GIT-USER-AGENT
Makefile +16 -11
@@ -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
perl/header_templates/fixed_prefix.template.pl new file +1 -0
@@ -0,0 +1 @@ +use lib (split(/@@PATHSEP@@/, $ENV{GITPERLLIB} || '@@INSTLIBDIR@@'));
Signature · 1 line
2.15.0.chromium12
PATCH v5 2/3 Makefile: add Perl runtime prefix support
In reply to Dan JacquesAdd 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, "<prefix>/share/perl5".
This change enables Git's Perl scripts to work when their Git installation is relocated or moved to another system.
Thanks-to: Ævar Arnfjörð Bjarmason <[email protected]>
Thanks-to: Johannes Schindelin <[email protected]>
--- 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
Makefile +52 -1
@@ -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)'; \ if test x"$$FLAGS" != x"`cat $@ 2>/dev/null`" ; then \
@@ -1997,6 +2045,9 @@ GIT-PERL-HEADER: $(PERL_HEADER_TEMPLATE) GIT-PERL-DEFINES Makefile sed -e 's=@@PATHSEP@@=$(pathsep)=g' \ -e 's=@@INSTLIBDIR@@='$$INSTLIBDIR'=g' \ -e 's=@@PERLLIBDIR@@='$(perllibdir_SQ)'=g' \ + -e 's=@@PERLLIBDIR_REL@@=$(perllibdir_relative_SQ)=g' \ + -e 's=@@GITEXECDIR_REL@@=$(gitexecdir_relative_SQ)=g' \ + -e 's=@@LOCALEDIR_REL@@=$(localedir_relative_SQ)=g' \ $< >$@+ && \ mv $@+ $@
@@ -2310,7 +2361,7 @@ endif perl/build/lib/%.pm: perl/%.pm $(QUIET_GEN)mkdir -p $(dir $@) && \ - sed -e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' < $< > $@ + sed -e 's|@@LOCALEDIR@@|$(perl_localedir_SQ)|g' < $< > $@ perl/build/man/man3/Git.3pm: perl/Git.pm $(QUIET_GEN)mkdir -p $(dir $@) && \
perl/Git/I18N.pm +1 -1
@@ -18,7 +18,7 @@ our @EXPORT_OK = @EXPORT; sub __bootstrap_locale_messages { our $TEXTDOMAIN = 'git'; - our $TEXTDOMAINDIR = $ENV{GIT_TEXTDOMAINDIR} || '@@LOCALEDIR@@'; + our $TEXTDOMAINDIR ||= $ENV{GIT_TEXTDOMAINDIR} || '@@LOCALEDIR@@'; require POSIX; POSIX->import(qw(setlocale));
perl/header_templates/runtime_prefix.template.pl new file +32 -0
@@ -0,0 +1,32 @@ +# BEGIN RUNTIME_PREFIX_PERL generated code. +# +# This finds our Git::* libraries relative to the script's runtime path. +sub __git_system_path { + my ($relpath) = @_; + my $gitexecdir_relative = '@@GITEXECDIR_REL@@'; + + # 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}$==; + return File::Spec->catdir($prefix, $relpath); +} + +BEGIN { + use lib split /@@PATHSEP@@/, + ( + $ENV{GITPERLLIB} || + do { + my $perllibdir = __git_system_path('@@PERLLIBDIR_REL@@'); + (-e $perllibdir) || die("Invalid system path ($relpath): $path"); + $perllibdir; + } + ); + + # Export the system locale directory to the I18N module. The locale directory + # is only installed if NO_GETTEXT is set. + $Git::I18N::TEXTDOMAINDIR = __git_system_path('@@LOCALEDIR_REL@@'); +} + +# END RUNTIME_PREFIX_PERL generated code.
Signature · 1 line
2.15.0.chromium12
Re: [PATCH v5 2/3] Makefile: add Perl runtime prefix support
On Mon, Jan 08 2018, Dan Jacques jotted:
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.
Quoted 3 lines
Enabling
RUNTIME_PREFIX_PERLoverrides the system-specific Perl script installation path generated by MakeMaker to force installation into a platform-neutral location, "<prefix>/share/perl5".
Not generated by MakeMaker anymore :)
From 3/3 (not not send 2 e-mails):
Review
Quoted 3 lines
(quoted diff) +3
-0+# 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.
Or there's another option...
perl/header_templates/runtime_prefix.template.pl line 12
Quoted 5 lines
perl/header_templates/runtime_prefix.template.pl new file +5
-0+ # 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.
perl/header_templates/runtime_prefix.template.pl line 13
Quoted 1 line
perl/header_templates/runtime_prefix.template.pl new file +1
-0+ 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.
Re: [PATCH v5 2/3] Makefile: add Perl runtime prefix support
On Mon, 08 Jan 2018, Ævar Arnfjörð Bjarmason replied:
Quoted 2 lines
Thanks, applied this on top of next and it works for me, i.e. install to
/tmp/gitand 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.
Quoted 5 lines
Quoted 3 lines
Enabling
RUNTIME_PREFIX_PERLoverrides the system-specific Perl script installation path generated by MakeMaker to force installation into a platform-neutral location, "<prefix>/share/perl5".Not generated by MakeMaker anymore :)
Hah good catch! I'll update the commit message.
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+# 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
*_PERLdefine still needed? Reading this explanation doesn't make sense to me, but I'm probably missing something.
Quoted 8 lines
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/gitbut 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.
Quoted 11 lines
perl/header_templates/runtime_prefix.template.pl line 12
Quoted 5 lines
perl/header_templates/runtime_prefix.template.pl new file +5
-0+ # 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-svnlike you can do/tmp/git2/libexec/git-core/git-status, i.e. will this never be false if invoked via "git"?
Quoted 2 lines
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.
Quoted 8 lines
perl/header_templates/runtime_prefix.template.pl line 13
Quoted 1 line
perl/header_templates/runtime_prefix.template.pl new file +1
-0+ 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;
Quoted 7 lines
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.
Re: [PATCH v5 2/3] Makefile: add Perl runtime prefix support
On Mon, Jan 08 2018, Dan Jacques jotted:
Quoted 35 lines
On Mon, 08 Jan 2018, Ævar Arnfjörð Bjarmason replied:
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+# 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
*_PERLdefine still needed? Reading this explanation doesn't make sense to me, but I'm probably missing something.Quoted 8 lines
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/gitbut 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_PREFIXresolution. 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.
Quoted 3 lines
I can foresee a future where Windows maintainers decide that
PERL_RUNTIME_PREFIXis fine for Windows and merge the two options; however, I didn't want to force that decision in the initial implementation.
Makes sense, well not really, But that's not your fault, but Windows's.
I do think you're being overly conservative here, the perl change is no more invasive than the C changes (less so actually), and from anyone who's not on Windows it makes sense to be able to enable this with just RUNTIME_PREFIX=YesPlease, and have NO_RUNTIME_PREFIX_PERL=NotNeededHere for Windows, if someone ends up needing it.
We usually hide stuff you might want in general, but isn't needed on one special snowflake platform behind NO_*, not the other way around.
Maybe others disagre...
Quoted 14 lines
Quoted 11 lines
perl/header_templates/runtime_prefix.template.pl line 12
Quoted 5 lines
perl/header_templates/runtime_prefix.template.pl new file +5
-0+ # 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-svnlike you can do/tmp/git2/libexec/git-core/git-status, i.e. will this never be false if invoked via "git"?Quoted 2 lines
I don't mind it, just wondering if I'm missing something and we need to use the fallback path in some "normal" codepath.
Quoted 7 lines
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_PATHis 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 whenGIT_EXEC_PATHis empty.
Both make sense.
Quoted 12 lines
Quoted 12 lines
perl/header_templates/runtime_prefix.template.pl line 13
Quoted 1 line
perl/header_templates/runtime_prefix.template.pl new file +1
-0+ 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.
Quoted 7 lines
Quoted 3 lines
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.
Yes, silly me. Nevermind.
Re: [PATCH v5 2/3] Makefile: add Perl runtime prefix support
In reply to Dan JacquesHi,
Quoted 19 lines · Dan Jacques
On Mon, 08 Jan 2018, Ævar Arnfjörð Bjarmason replied:
Quoted 8 lines
Quoted 3 lines
+# it. This is intentionally separate from
RUNTIME_PREFIXso that notably Windows +# can hard-code Perl library paths while still enablingRUNTIME_PREFIX+# resolution.Maybe we covered this in previous submissions, but refresh my memory, why is the
*_PERLdefine still needed? Reading this explanation doesn't make sense to me, but I'm probably missing something.Quoted 8 lines
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/gitbut then use a different version of the Git.pm from some system install, but I can't imagine why.
Quoted 6 lines
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_PREFIXresolution. 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.
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?
Ciao,
Johannes
Re: [PATCH v5 2/3] Makefile: add Perl runtime prefix support
Quoted 28 lines · Johannes Schindelin
Quoted 19 lines · Dan Jacques
On Mon, 08 Jan 2018, Ævar Arnfjörð Bjarmason replied:
Quoted 8 lines
Quoted 3 lines
+# it. This is intentionally separate from
RUNTIME_PREFIXso that notably Windows +# can hard-code Perl library paths while still enablingRUNTIME_PREFIX+# resolution.Maybe we covered this in previous submissions, but refresh my memory, why is the
*_PERLdefine still needed? Reading this explanation doesn't make sense to me, but I'm probably missing something.Quoted 8 lines
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/gitbut then use a different version of the Git.pm from some system install, but I can't imagine why.Quoted 6 lines
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_PREFIXresolution. 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.
Quoted 4 lines
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?
Wonderful to see that you two are in agreement. Will look forward to see a simplified solution in a later round ;-)
Re: [PATCH v5 2/3] Makefile: add Perl runtime prefix support
In reply to Johannes SchindelinQuoted 4 lines · Johannes Schindelin
Quoted 3 lines
Maybe we covered this in previous submissions, but refresh my memory, why is the
*_PERLdefine still needed? Reading this explanation doesn't make sense to me, but I'm probably missing something.
Quoted 13 lines
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 theRUNTIME_PREFIX_PERLhandling intoRUNTIME_PREFIXand 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?
Quoted 3 lines
BTW I managed to run your
runtime-prefixbranch 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, Jan 08 2018, Dan Jacques jotted:
Quoted 25 lines · Johannes Schindelin
Quoted 5 lines
Quoted 4 lines
Maybe we covered this in previous submissions, but refresh my memory, why is the
*_PERLdefine still needed? Reading this explanation doesn't make sense to me, but I'm probably missing something.Quoted 13 lines
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 theRUNTIME_PREFIX_PERLhandling intoRUNTIME_PREFIXand 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_PERLintoRUNTIME_PREFIXfor simplicity's sake.
Quoted 4 lines
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 thatNO_RUNTIME_PREFIX_PERLcan 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.
Re: [PATCH v5 2/3] Makefile: add Perl runtime prefix support
Quoted 9 lines · Ævar Arnfjörð Bjarmason
Quoted 4 lines
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 thatNO_RUNTIME_PREFIX_PERLcan 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
In reply to Ævar Arnfjörð BjarmasonHi,
Quoted 5 lines · Ævar Arnfjörð Bjarmason
On Mon, Jan 08 2018, Dan Jacques jotted:
From 3/3 (not not send 2 e-mails):
Quoted 7 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+# 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
*_PERLdefine 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).
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.)
What do you think? Should we just fold the RUNTIME_PREFIX_PERL handling into RUNTIME_PREFIX and be done with that part?
Ciao,
Johannes
PATCH v5 3/3 exec_cmd: RUNTIME_PREFIX on some POSIX systems
In reply to Dan JacquesEnable 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".
Thanks-to: Robbie Iannucci <[email protected]>
Thanks-to: Junio C Hamano <[email protected]>
--- 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(-)
Makefile +34 -2
@@ -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
cache.h +1 -0
@@ -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.
common-main.c +2 -2
@@ -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);
config.mak.uname +7 -0
@@ -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_DIRECTORIES = UnfortunatelyYes + HAVE_NS_GET_EXECUTABLE_PATH = YesPlease endif ifeq ($(uname_S),SunOS) NEEDS_SOCKET = YesPlease
@@ -206,6 +208,7 @@ ifeq ($(uname_S),FreeBSD) HAVE_PATHS_H = YesPlease GMTIME_UNRELIABLE_ERRORS = UnfortunatelyYes HAVE_BSD_SYSCTL = YesPlease + HAVE_BSD_KERN_PROC_SYSCTL = YesPlease PAGER_ENV = LESS=FRX LV=-c MORE=FRX FREAD_READS_DIRECTORIES = UnfortunatelyYes endif
@@ -218,6 +221,8 @@ ifeq ($(uname_S),OpenBSD) BASIC_LDFLAGS += -L/usr/local/lib HAVE_PATHS_H = YesPlease HAVE_BSD_SYSCTL = YesPlease + HAVE_BSD_KERN_PROC_SYSCTL = YesPlease + PROCFS_EXECUTABLE_PATH = /proc/curproc/file endif ifeq ($(uname_S),MirBSD) NO_STRCASESTR = YesPlease
@@ -236,6 +241,8 @@ ifeq ($(uname_S),NetBSD) USE_ST_TIMESPEC = YesPlease HAVE_PATHS_H = YesPlease HAVE_BSD_SYSCTL = YesPlease + HAVE_BSD_KERN_PROC_SYSCTL = YesPlease + PROCFS_EXECUTABLE_PATH = /proc/curproc/exe endif ifeq ($(uname_S),AIX) DEFAULT_PAGER = more
exec_cmd.c +210 -31
320 lines not on this page · raw message
exec_cmd.h +2 -2
@@ -3,8 +3,8 @@struct argv_array ; -extern void git_set_argv_exec_path (const char *exec_path); -extern void git_extract_argv0_path (const char *path); +extern void git_set_exec_path (const char *exec_path); +extern void git_resolve_executable_dir (const char *path);extern const char *git_exec_path (void );extern void setup_path (void );extern const char **prepare_git_cmd (struct argv_array *out,const char **argv);
gettext.c +5 -3
@@ -2,7 +2,8 @@* Copyright (c) 2010 Ævar Arnfjörð Bjarmason */ -#include "git-compat-util.h" +#include "cache.h" +#include "exec_cmd.h" #include "gettext.h" #include "strbuf.h" #include "utf8.h"
@@ -157,10 +158,11 @@ static void init_gettext_charset(const char *domain)void git_setup_gettext (void ) { -const char *podir =getenv ("GIT_TEXTDOMAINDIR" ); +const char *podir =getenv (GIT_TEXT_DOMAIN_DIR_ENVIRONMENT );if (!podir) - podir =GIT_LOCALE_PATH ; + podir =system_path (GIT_LOCALE_PATH ); +bindtextdomain ("git" , podir);setlocale (LC_MESSAGES ,"" );setlocale (LC_TIME ,"" );
git.c +1 -1
@@ -65,7 +65,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)*/ if (skip_prefix (cmd,"--exec-path" , &cmd)) {if (*cmd =='=' ) -git_set_argv_exec_path (cmd +1 ); +git_set_exec_path (cmd +1 );else {puts (git_exec_path ());exit (0 );
Signature · 1 line
2.15.0.chromium12