public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
* [PATCH] Makefile: Check for perl script errors with perl -c
@ 2010-04-17  2:29 Matthew Ogilvie
  2010-04-17  7:27 ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Ogilvie @ 2010-04-17  2:29 UTC (permalink / raw)
  To: git, gitster; +Cc: Matthew Ogilvie

This allows you to notice trivial syntax errors in perl scripts earlier,
for example before running t/* tests that generate a lot of
separate errors.

You have to set USE_PERL_CHECK to enable this, because it uses
the non-standard PIPESTATUS bashism to grep out "{script} syntax OK"
useless noise.

Signed-off-by: Matthew Ogilvie <mmogilvi_git@miniinfo•net>
---

I'm not sure anyone will think this is worth including, but I'm
used to "make" (and the compiler) detecting trivial errors
in compiled langauges, and was getting annoyed that it wasn't
doing something similar for perl scripts (especially since in git you
are really expected to "make" the scripts anyway).

The whole tradeoff between noise ("{script} syntax OK"), portability
(PIPESTATUS is a bashism), or really ugly contortions with redirecting
extra file descriptors (to avoid PIPESTATUS) seems to be the biggest
downside of the idea behind this patch.

--
Matthew Ogilvie   [mmogilvi_git@miniinfo•net]

 Makefile |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile
index 910f471..1e827bb 100644
--- a/Makefile
+++ b/Makefile
@@ -168,6 +168,10 @@ all::
 #
 # Define NO_PERL if you do not want Perl scripts or libraries at all.
 #
+# Define USE_PERL_CHECK if you want the makefile to run "perl -cw" to
+# check perl scripts for basic errors.  This requires that your
+# $SHELL_PATH supports the ${PIPESTATUS[0]} variable, like bash.
+#
 # Define NO_PYTHON if you do not want Python scripts or libraries at all.
 #
 # Define NO_TCLTK if you do not want Tcl/Tk GUI.
@@ -1553,6 +1557,14 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl
 	    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
 	    $@.perl >$@+ && \
 	chmod +x $@+ && \
+	if test x"$(USE_PERL_CHECK)" != x"" ; then \
+	    '$(PERL_PATH_SQ)' -cw $@+ 2>&1 | grep -v '^$@+ syntax OK$$' 1>&2 ; \
+	    perlStat="$${PIPESTATUS[0]}" && \
+	    if test x"$$perlStat" != x"0" ; then \
+	        echo '"$(PERL_PATH_SQ) -c $@+" failed' 1>&2 ; \
+	        exit "$$perlStat" ; \
+	    fi ; \
+	fi && \
 	mv $@+ $@
 
 
-- 
1.7.0.GIT

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-04-17 17:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-17  2:29 [PATCH] Makefile: Check for perl script errors with perl -c Matthew Ogilvie
2010-04-17  7:27 ` Jeff King
2010-04-17 17:05   ` Matthew Ogilvie
2010-04-17 17:55     ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox