[PATCH] Makefile: Check for perl script errors with perl -c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxx>
---

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@xxxxxxxxxxxx]

 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

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

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]