git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
MOMatthew Ogilvie <mmogilvi_git@miniinfo.net>
Date
Apr 17, 2010, 02:29 UTC
Message-ID
<1271471380-17701-1-git-send-email-mmogilvi_git@miniinfo.net>

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
Next: Jeff King
Message 1 of 4 in “Makefile: Check for perl script errors with perl -c”
  1. Makefile: Check for perl script errors with perl -cMatthew Ogilvie, Apr 17, 2010
  2. Jeff KingApr 17, 2010
  3. Matthew OgilvieApr 17, 2010
  4. Jeff KingApr 17, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.