threads / patch / 14850

patchperl/Makefile: handle paths with spaces in the NO_PERL_MAKEMAKER section

Subject: [PATCH] perl/Makefile: handle paths with spaces in the NO_PERL_MAKEMAKER section

## tl;dr

10 messages between Aug 5, 2008 and Aug 7, 2008. Diffs are folded; open one to read it.

replies: 9people: 2as markdown or json

Brandon Casey· Aug 5, 2008, 23:23 UTC · lore
Use double quotes to protect against paths which may contain spaces.
Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---
 perl/Makefile |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
Show changes to perl/Makefile +4 −4
diff --git a/perl/Makefile b/perl/Makefile
index b8547db..e3dd1a5 100644
--- a/perl/Makefile
+++ b/perl/Makefile
@@ -29,11 +29,11 @@ $(makfile): ../GIT-CFLAGS Makefile
 	'$(PERL_PATH_SQ)' -MError -e 'exit($$Error::VERSION < 0.15009)' || \
 	echo '	cp private-Error.pm blib/lib/Error.pm' >> $@
 	echo install: >> $@
-	echo '	mkdir -p $(instdir_SQ)' >> $@
-	echo '	$(RM) $(instdir_SQ)/Git.pm; cp Git.pm $(instdir_SQ)' >> $@
-	echo '	$(RM) $(instdir_SQ)/Error.pm' >> $@
+	echo '	mkdir -p "$(instdir_SQ)"' >> $@
+	echo '	$(RM) "$(instdir_SQ)/Git.pm"; cp Git.pm "$(instdir_SQ)"' >> $@
+	echo '	$(RM) "$(instdir_SQ)/Error.pm"' >> $@
 	'$(PERL_PATH_SQ)' -MError -e 'exit($$Error::VERSION < 0.15009)' || \
-	echo '	cp private-Error.pm $(instdir_SQ)/Error.pm' >> $@
+	echo '	cp private-Error.pm "$(instdir_SQ)/Error.pm"' >> $@
 	echo instlibdir: >> $@
 	echo '	echo $(instdir_SQ)' >> $@
 else
-- 
1.6.0.rc1.87.g56c9f.dirty
Junio C Hamano· Aug 5, 2008, 23:46 UTC · re: Brandon Casey · lore

Re: [PATCH] perl/Makefile: handle paths with spaces in the NO_PERL_MAKEMAKER section

Brandon Casey <casey@nrlssc.navy.mil> writes:
> Use double quotes to protect against paths which may contain spaces.
> ...
> +	echo '	mkdir -p "$(instdir_SQ)"' >> $@

Is this sufficient? We seem to apply double-sq when writing shell scriptlet in GIT-BUILD-OPTIONS from the main Makefile, and I suspect you would need to do something similar.

Brandon Casey· Aug 6, 2008, 14:25 UTC · re: Junio C Hamano · lore

Re: [PATCH] perl/Makefile: handle paths with spaces in the NO_PERL_MAKEMAKER section

Junio C Hamano wrote:
Show 9 quoted lines
> Brandon Casey <casey@nrlssc.navy.mil> writes:
> 
>> Use double quotes to protect against paths which may contain spaces.
>> ...
>> +	echo '	mkdir -p "$(instdir_SQ)"' >> $@
> 
> Is this sufficient?  We seem to apply double-sq when writing shell
> scriptlet in GIT-BUILD-OPTIONS from the main Makefile, and I suspect you
> would need to do something similar.

It seems to be sufficient. The double quotes survived into my perl.mak file and the two perl modules were installed correctly when I supplied a prefix with spaces. Is there something else to be concerned about?

perl.mak:
all: private-Error.pm Git.pm
        mkdir -p blib/lib
        rm -f blib/lib/Git.pm; cp Git.pm blib/lib/
        rm -f blib/lib/Error.pm
        cp private-Error.pm blib/lib/Error.pm
install:
        mkdir -p "/home/casey/opt/SunOS spaces/sun4u/lib"
        rm -f "/home/casey/opt/SunOS spaces/sun4u/lib/Git.pm"; cp Git.pm "/home/casey/opt/SunOS spaces/sun4u/lib"
        rm -f "/home/casey/opt/SunOS spaces/sun4u/lib/Error.pm"
        cp private-Error.pm "/home/casey/opt/SunOS spaces/sun4u/lib/Error.pm"
instlibdir:
        echo /home/casey/opt/SunOS spaces/sun4u/lib
-brandon
Junio C Hamano· Aug 6, 2008, 15:33 UTC · re: Brandon Casey · lore

Re: [PATCH] perl/Makefile: handle paths with spaces in the NO_PERL_MAKEMAKER section

Brandon Casey <casey@nrlssc.navy.mil> writes:
Show 14 quoted lines
> Junio C Hamano wrote:
>> Brandon Casey <casey@nrlssc.navy.mil> writes:
>> 
>>> Use double quotes to protect against paths which may contain spaces.
>>> ...
>>> +	echo '	mkdir -p "$(instdir_SQ)"' >> $@
>> 
>> Is this sufficient?  We seem to apply double-sq when writing shell
>> scriptlet in GIT-BUILD-OPTIONS from the main Makefile, and I suspect you
>> would need to do something similar.
>
> It seems to be sufficient. The double quotes survived into my perl.mak file
> and the two perl modules were installed correctly when I supplied a prefix
> with spaces. Is there something else to be concerned about?

I think the generic way GIT-BUILD-OPTIONS writing is done covers cases where the installation directory has funnies other than whitespace, e.g. double quotes. Is your 'echo "$(instdir_SQ)"' sufficient?

Brandon Casey· Aug 6, 2008, 19:31 UTC · re: Junio C Hamano · lore

Re: [PATCH] perl/Makefile: handle paths with spaces in the NO_PERL_MAKEMAKER section

Junio C Hamano wrote:
Show 18 quoted lines
> Brandon Casey <casey@nrlssc.navy.mil> writes:
> 
>> Junio C Hamano wrote:
>>> Brandon Casey <casey@nrlssc.navy.mil> writes:
>>>
>>>> Use double quotes to protect against paths which may contain spaces.
>>>> ...
>>>> +	echo '	mkdir -p "$(instdir_SQ)"' >> $@
>>> Is this sufficient?  We seem to apply double-sq when writing shell
>>> scriptlet in GIT-BUILD-OPTIONS from the main Makefile, and I suspect you
>>> would need to do something similar.
>> It seems to be sufficient. The double quotes survived into my perl.mak file
>> and the two perl modules were installed correctly when I supplied a prefix
>> with spaces. Is there something else to be concerned about?
> 
> I think the generic way GIT-BUILD-OPTIONS writing is done covers cases
> where the installation directory has funnies other than whitespace, e.g. 
> double quotes.  Is your 'echo "$(instdir_SQ)"' sufficient?
DOUBLE QUOTE ISSUE:

I added a double quote to my prefix, and the build fails at compiling config.c line 589. The failure is caused by the macro ETC_GITCONFIG which is set in the Makefile and contains the prefix string, which contains the single double quote. This of course causes a syntax error. So it looks like the cleansing done to ETC_GITCONFIG doesn't handle this.

Doing this allows me to compile:
    ETC_GITCONFIG_SQ = $(subst ",\",$(subst ','\'',$(ETC_GITCONFIG)))

The patch at the end of this email applies the same treatment to the other variables I needed to get git to compile. If this is the correct fix, then the other variables used as macros in git source files would need to be hunted down... at least SHA1_HEADER_SQ, but maybe others?

SPACE ISSUE:

Also, the installation of the perl modules fails when I have a space in the path and NO_PERL_MAKEMAKER is _not_ set. IOW the perl makemaker install fails for me when there is a space in the path. This has nothing to do with the double quote I was talking about above, I think it would fail with double quote too.

The line assigning PREFIX in my perl.mak looks like:
    PREFIX = /home/casey/opt/test spaces/
Shouldn't that argument have quotes around it?
The errors look like:

make -C perl prefix='/home/casey/opt/test spaces/' DESTDIR='' install make[1]: Entering directory `/home/casey/scratch/git/master/perl' make[2]: Entering directory `/home/casey/scratch/git/master/perl' Installing /home/casey/opt/test/private-Error.3pm Installing /home/casey/opt/test/Git.3pm Writing /home/casey/opt/test Can't open file /home/casey/opt/test: Is a directory at /usr/lib/perl5/5.8.5/ExtUtils/Install.pm line 209 make[2]: *** [pure_site_install] Error 255 make[2]: Leaving directory `/home/casey/scratch/git/master/perl' make[1]: *** [install] Error 2 make[1]: Leaving directory `/home/casey/scratch/git/master/perl' make: *** [install] Error 2

private-Error.3pm and Git.3pm showed up in /home/casey/opt/test/

There are problems here with spaces, single quotes, and double quotes. I'll follow up in another email.

MakeMaker version 6.17 (Revision: 1.133) perl v5.8.5

-brandon
Show changes to Makefile +6 −6
diff --git a/Makefile b/Makefile
index 0d373f7..affc288 100644
--- a/Makefile
+++ b/Makefile
@@ -1031,15 +1031,15 @@ endif
 # Shell quote (do not use $(call) to accommodate ancient setups);
 
 SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER))
-ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG))
+ETC_GITCONFIG_SQ = $(subst ",\",$(subst ','\'',$(ETC_GITCONFIG)))
 
 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
 bindir_SQ = $(subst ','\'',$(bindir))
-mandir_SQ = $(subst ','\'',$(mandir))
-infodir_SQ = $(subst ','\'',$(infodir))
-gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
-template_dir_SQ = $(subst ','\'',$(template_dir))
-htmldir_SQ = $(subst ','\'',$(htmldir))
+mandir_SQ = $(subst ",\",$(subst ','\'',$(mandir)))
+infodir_SQ = $(subst ",\",$(subst ','\'',$(infodir)))
+gitexecdir_SQ = $(subst ",\",$(subst ','\'',$(gitexecdir)))
+template_dir_SQ = $(subst ",\",$(subst ','\'',$(template_dir)))
+htmldir_SQ = $(subst ",\",$(subst ','\'',$(htmldir)))
 prefix_SQ = $(subst ','\'',$(prefix))
 
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
Junio C Hamano· Aug 6, 2008, 20:15 UTC · re: Brandon Casey · lore

Re: [PATCH] perl/Makefile: handle paths with spaces in the NO_PERL_MAKEMAKER section

Brandon Casey <casey@nrlssc.navy.mil> writes:
> There are problems here with spaces, single quotes, and double quotes.
> I'll follow up in another email.

I guess we've opened up a large can of worms. Let's have the minimum fix that says "We do support whitespace in these paths but no other funnies" and leave the more intrusive one for post 1.6.0, for now.

Brandon Casey· Aug 6, 2008, 21:38 UTC · re: Junio C Hamano · lore

[PATCH] perl/Makefile: handle paths with spaces by adding additional quoting

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---
Junio C Hamano wrote:
Show 8 quoted lines
> Brandon Casey <casey@nrlssc.navy.mil> writes:
> 
>> There are problems here with spaces, single quotes, and double quotes.
>> I'll follow up in another email.
> 
> I guess we've opened up a large can of worms.  Let's have the minimum fix
> that says "We do support whitespace in these paths but no other funnies"
> and leave the more intrusive one for post 1.6.0, for now.
That is this patch.
BUT. It produces some strangeties in the perl.mak file.
PREFIX looks great:
    PREFIX = '/home/casey/opt/test spaces/'
but then down in the $(MAKE_APERL_FILE) section we get something like:
    PREFIX=''/home/casey/opt/test spaces/''
because MakeMaker was already single quoting it.
Everything compiles and installs correctly for me.

In addition to putting a space in the prefix path, I also tried semicolon, colon, and backslash. semicolon didn't work, but it didn't work before either. colon and backslash worked. A backslash in the prefix path produced some complaints when compiling some of the source files caused by the macros that I mentioned earlier that are used by some of the files. The warning was 'unknown escape sequence ...'. The backslash was interpreted as an escape sequence and then just dropped, so the path compiled into the object files was wrong. I guess this doesn't happen on windows?

Summary: with this patch spaces in the prefix path work. It didn't break
         anything that I tested.
Maybe there's a MakeMaker expert in the audience?
-brandon
 perl/Makefile |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to perl/Makefile +1 −1
diff --git a/perl/Makefile b/perl/Makefile
index b8547db..6d2a200 100644
--- a/perl/Makefile
+++ b/perl/Makefile
@@ -38,7 +38,7 @@ $(makfile): ../GIT-CFLAGS Makefile
 	echo '	echo $(instdir_SQ)' >> $@
 else
 $(makfile): Makefile.PL ../GIT-CFLAGS
-	$(PERL_PATH) $< PREFIX='$(prefix_SQ)'
+	$(PERL_PATH) $< PREFIX=\''$(prefix_SQ)'\'
 endif
 
 # this is just added comfort for calling make directly in perl dir
-- 
1.5.6.2
Brandon Casey· Aug 6, 2008, 22:16 UTC · re: Junio C Hamano · lore

Re: [PATCH] perl/Makefile: handle paths with spaces in the NO_PERL_MAKEMAKER section

Junio C Hamano wrote:
Show 8 quoted lines
> Brandon Casey <casey@nrlssc.navy.mil> writes:
> 
>> There are problems here with spaces, single quotes, and double quotes.
>> I'll follow up in another email.
> 
> I guess we've opened up a large can of worms.  Let's have the minimum fix
> that says "We do support whitespace in these paths but no other funnies"
> and leave the more intrusive one for post 1.6.0, for now.
I think those two patches I just sent are enough.

You can apply the double-quote escaping patch I sent earlier if you want (the one that escapes double quotes in the macros compiled in c programs). But we'd have a problem installing the perl scripts using MakeMaker, and we'd have a problem _running_ the perl scripts since the single double quote causes a syntax error in the perl script. Let's wait till someone wants to have " in their path shows up (and let them figure out how to fix it).

-brandon
Brandon Casey· Aug 7, 2008, 00:23 UTC · re: Brandon Casey · lore

Re: [PATCH] perl/Makefile: handle paths with spaces in the NO_PERL_MAKEMAKER section

Brandon Casey wrote:
Show 18 quoted lines
> Junio C Hamano wrote:
>> Brandon Casey <casey@nrlssc.navy.mil> writes:
>>
>>> There are problems here with spaces, single quotes, and double quotes.
>>> I'll follow up in another email.
>> I guess we've opened up a large can of worms.  Let's have the minimum fix
>> that says "We do support whitespace in these paths but no other funnies"
>> and leave the more intrusive one for post 1.6.0, for now.
> 
> I think those two patches I just sent are enough.
> 
> You can apply the double-quote escaping patch I sent earlier if you want
> (the one that escapes double quotes in the macros compiled in c programs).
> But we'd have a problem installing the perl scripts using MakeMaker, and
> we'd have a problem _running_ the perl scripts since the single double
> quote causes a syntax error in the perl script. Let's wait till someone
> wants to have " in their path shows up (and let them figure out how to
> fix it).

ok, here's a patch that allows me to compile, install using MakeMaker, and actually use the perl scripts generated by the make file when the installation prefix contains odd characters like double quote, single quote, space or semi-colon. The patch below includes that patch I mentioned about escaping double quotes for c macros.

-brandon
--->8---
Show changes to 4 files +12 −12

Makefile, gitweb/gitweb.perl, perl/Makefile, perl/Makefile.PL

diff --git a/Makefile b/Makefile
index 0d373f7..21241b4 100644
--- a/Makefile
+++ b/Makefile
@@ -1031,15 +1031,15 @@ endif
 # Shell quote (do not use $(call) to accommodate ancient setups);
 
 SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER))
-ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG))
+ETC_GITCONFIG_SQ = $(subst ",\",$(subst ','\'',$(ETC_GITCONFIG)))
 
 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
 bindir_SQ = $(subst ','\'',$(bindir))
-mandir_SQ = $(subst ','\'',$(mandir))
-infodir_SQ = $(subst ','\'',$(infodir))
-gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
-template_dir_SQ = $(subst ','\'',$(template_dir))
-htmldir_SQ = $(subst ','\'',$(htmldir))
+mandir_SQ = $(subst ",\",$(subst ','\'',$(mandir)))
+infodir_SQ = $(subst ",\",$(subst ','\'',$(infodir)))
+gitexecdir_SQ = $(subst ",\",$(subst ','\'',$(gitexecdir)))
+template_dir_SQ = $(subst ",\",$(subst ','\'',$(template_dir)))
+htmldir_SQ = $(subst ",\",$(subst ','\'',$(htmldir)))
 prefix_SQ = $(subst ','\'',$(prefix))
 
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
@@ -1116,11 +1116,11 @@ perl/perl.mak: GIT-CFLAGS perl/Makefile perl/Makefile.PL
 
 $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl
 	$(QUIET_GEN)$(RM) $@ $@+ && \
-	INSTLIBDIR=`MAKEFLAGS= $(MAKE) -C perl -s --no-print-directory instlibdir` && \
+	INSTLIBDIR=`MAKEFLAGS= $(MAKE) -C perl -s --no-print-directory instlibdir | sed -e 's/"/\\\\\\\"/g'` && \
 	sed -e '1{' \
 	    -e '	s|#!.*perl|#!$(PERL_PATH_SQ)|' \
 	    -e '	h' \
-	    -e '	s=.*=use lib (split(/:/, $$ENV{GITPERLLIB} || "@@INSTLIBDIR@@"));=' \
+	    -e '	s=.*=use lib (split(/:/, $$ENV{GITPERLLIB} || q"@@INSTLIBDIR@@"));=' \
 	    -e '	H' \
 	    -e '	x' \
 	    -e '}' \
@@ -1134,7 +1134,7 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl
 	$(QUIET_GEN)$(RM) $@ $@+ && \
 	sed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' \
 	    -e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
-	    -e 's|++GIT_BINDIR++|$(bindir)|g' \
+	    -e 's|++GIT_BINDIR++|$(subst ",\\",$(bindir_SQ))|g' \
 	    -e 's|++GITWEB_CONFIG++|$(GITWEB_CONFIG)|g' \
 	    -e 's|++GITWEB_CONFIG_SYSTEM++|$(GITWEB_CONFIG_SYSTEM)|g' \
 	    -e 's|++GITWEB_HOME_LINK_STR++|$(GITWEB_HOME_LINK_STR)|g' \
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 90cd99b..155b1ac 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -29,7 +29,7 @@ our $my_uri = $cgi->url(-absolute => 1);
 
 # core git executable to use
 # this can just be "git" if your webserver has a sensible PATH
-our $GIT = "++GIT_BINDIR++/git";
+our $GIT = q"++GIT_BINDIR++/git";
 
 # absolute fs-path which will be prepended to the project path
 #our $projectroot = "/pub/scm";
diff --git a/perl/Makefile b/perl/Makefile
index dcbd2dd..2597d60 100644
--- a/perl/Makefile
+++ b/perl/Makefile
@@ -39,7 +39,7 @@ $(makfile): ../GIT-CFLAGS Makefile
 	echo "	echo "\''$(subst ','\'',$(instdir_SQ))'\' >> $@
 else
 $(makfile): Makefile.PL ../GIT-CFLAGS
-	$(PERL_PATH) $< PREFIX=\''$(prefix_SQ)'\'
+	$(PERL_PATH) $< PREFIX=\''$(subst ','\'',$(prefix_SQ))'\'
 endif
 
 # this is just added comfort for calling make directly in perl dir
diff --git a/perl/Makefile.PL b/perl/Makefile.PL
index 320253e..e1e465c 100644
--- a/perl/Makefile.PL
+++ b/perl/Makefile.PL
@@ -3,7 +3,7 @@ use ExtUtils::MakeMaker;
 sub MY::postamble {
 	return <<'MAKE_FRAG';
 instlibdir:
-	@echo '$(INSTALLSITELIB)'
+	@echo $(INSTALLSITELIB)
 
 MAKE_FRAG
 }
-- 
1.5.6.2
Brandon Casey· Aug 6, 2008, 21:48 UTC · re: Junio C Hamano · lore

[PATCH] perl/Makefile: make NO_PERL_MAKEMAKER section more robust

This adds the double single quote escaping that is performed for GIT_BUILD_OPTIONS to the paths in the install section to protect against paths with spaces, quotes or other funny characters in them.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---
 perl/Makefile |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
Show changes to perl/Makefile +6 −5
diff --git a/perl/Makefile b/perl/Makefile
index b8547db..4c6b2a2 100644
--- a/perl/Makefile
+++ b/perl/Makefile
@@ -29,13 +29,14 @@ $(makfile): ../GIT-CFLAGS Makefile
 	'$(PERL_PATH_SQ)' -MError -e 'exit($$Error::VERSION < 0.15009)' || \
 	echo '	cp private-Error.pm blib/lib/Error.pm' >> $@
 	echo install: >> $@
-	echo '	mkdir -p $(instdir_SQ)' >> $@
-	echo '	$(RM) $(instdir_SQ)/Git.pm; cp Git.pm $(instdir_SQ)' >> $@
-	echo '	$(RM) $(instdir_SQ)/Error.pm' >> $@
+	echo "	mkdir -p "\''$(subst ','\'',$(instdir_SQ))'\' >> $@
+	echo "	$(RM) "\''$(subst ','\'',$(instdir_SQ))/Git.pm'\' >> $@
+	echo "	cp Git.pm "\''$(subst ','\'',$(instdir_SQ))'\' >> $@
+	echo "	$(RM) "\''$(subst ','\'',$(instdir_SQ))/Error.pm'\' >> $@
 	'$(PERL_PATH_SQ)' -MError -e 'exit($$Error::VERSION < 0.15009)' || \
-	echo '	cp private-Error.pm $(instdir_SQ)/Error.pm' >> $@
+	echo "	cp private-Error.pm "\''$(subst ','\'',$(instdir_SQ))/Error.pm'\' >> $@
 	echo instlibdir: >> $@
-	echo '	echo $(instdir_SQ)' >> $@
+	echo "	echo "\''$(subst ','\'',$(instdir_SQ))'\' >> $@
 else
 $(makfile): Makefile.PL ../GIT-CFLAGS
 	$(PERL_PATH) $< PREFIX='$(prefix_SQ)'
-- 
1.6.0.rc1.89.g2e7ef.dirty

← back to recent threads