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

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Brandon Casey
Use double quotes to protect against paths which may contain spaces.

Signed-off-by: Brandon Casey <[hidden email]>
---
 perl/Makefile |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

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

Junio C Hamano
Brandon Casey <[hidden email]> 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.

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

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

Brandon Casey
Junio C Hamano wrote:
> Brandon Casey <[hidden email]> 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

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

Junio C Hamano
Brandon Casey <[hidden email]> writes:

> Junio C Hamano wrote:
>> Brandon Casey <[hidden email]> 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?
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

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

Brandon Casey
Junio C Hamano wrote:

> Brandon Casey <[hidden email]> writes:
>
>> Junio C Hamano wrote:
>>> Brandon Casey <[hidden email]> 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


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))

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

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

Junio C Hamano
Brandon Casey <[hidden email]> 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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

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

Brandon Casey
Signed-off-by: Brandon Casey <[hidden email]>
---


Junio C Hamano wrote:
> Brandon Casey <[hidden email]> 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(-)

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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

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

Brandon Casey
In reply to this post by Junio C Hamano
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 <[hidden email]>
---
 perl/Makefile |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

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

Brandon Casey
In reply to this post by Junio C Hamano
Junio C Hamano wrote:
> Brandon Casey <[hidden email]> 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

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

Brandon Casey
Brandon Casey wrote:

> Junio C Hamano wrote:
>> Brandon Casey <[hidden email]> 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---
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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html