automake-patches
[Top][All Lists]
Advanced

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

[PATCH] dryrun: fix regression with '$(am__make_dryrun)'


From: Stefano Lattarini
Subject: [PATCH] dryrun: fix regression with '$(am__make_dryrun)'
Date: Tue, 7 Feb 2012 11:18:22 +0100

In commit v1.11-683-gda0964e of 05-02-2012, we introduced a new
variable '$(am__make_dryrun)' that could be used in recipes to
determine whether make is running in dry mode (e.g., as with
"make -n").  Unfortunately, the idiom we used fails to take into
account the case in which $(MAKEFLAGS) contains one or more variable
definitions whose value is a whitespace-separated list; for example,
if we invoke make as:

  make check TESTS="n1.test n2.test"

then the better make implementations out there (at least modern
GNU make and BSD make) will export MAKEFLAGS to the following
value:

  TESTS=n1.test\ n2.test

So a shell loop like the one we used in $(am__make_dryrun):

  for flag in $$MAKEFLAGS; do ...

won't behave as expected: the shell word-splitting rules will break
up the entry for TESTS into the two distinct entries "TESTS=n1.test\"
and "n2.test", and this second entry will goad our $(am__make_dryrun)
code into thinking that make is performing a dry run!

So now we simply loop over the expanded value of $(MAKEFLAGS).
This solves the regression, but alas, is more brittle in case the
users passes on the command line a macro value containing unbalanced
" or ' quotes, or shell metacharacters like, say, '`' or '('.  This
should almost never happen though, so we don't worry about it now;
we will revisit the issue only when and if we receive bug reports in
this area.

* lib/am/header-vars.am (am__make_dryrun): Fix.
* tests/make-dryrun.test: New test.
* tests/list-of-tests.mk: Add it.
---
 lib/am/header-vars.am  |    3 +-
 tests/list-of-tests.mk |    1 +
 tests/make-dryrun.test |   67 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 1 deletions(-)
 create mode 100755 tests/make-dryrun.test

diff --git a/lib/am/header-vars.am b/lib/am/header-vars.am
index 0f05731..1078a3d 100644
--- a/lib/am/header-vars.am
+++ b/lib/am/header-vars.am
@@ -35,8 +35,9 @@ VPATH = @srcdir@
 am__make_dryrun = \
   { \
     am__dry=no; \
-    for am__flg in $$MAKEFLAGS; do \
+    for am__flg in : $(MAKEFLAGS); do \
       case $$am__flg in \
+        :) ;; \
         *=*|--*) ;; \
         *n*) am__dry=yes; break;; \
       esac; \
diff --git a/tests/list-of-tests.mk b/tests/list-of-tests.mk
index c35589f..bc64d61 100644
--- a/tests/list-of-tests.mk
+++ b/tests/list-of-tests.mk
@@ -548,6 +548,7 @@ makej.test \
 makej2.test \
 maken.test \
 maken3.test \
+make-dryrun.test \
 makevars.test \
 man.test \
 man2.test \
diff --git a/tests/make-dryrun.test b/tests/make-dryrun.test
new file mode 100755
index 0000000..072d02f
--- /dev/null
+++ b/tests/make-dryrun.test
@@ -0,0 +1,67 @@
+#! /bin/sh
+# Copyright (C) 2012 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check that $(am__make_dryrun) works as expected.
+
+. ./defs || Exit 1
+
+set -e
+
+mkdir sub
+
+echo AC_OUTPUT >> configure.in
+
+cat > Makefile.am <<'END'
+all:
+       : Dummy, nothing to do.
+foo:
+       $(MAKE) all
+notdry:
+       @echo ":: $$MAKEFLAGS ::"; : For debugging.
+       $(am__make_dryrun) && exit 1; exit 0
+dry:
+       address@hidden ":: $$MAKEFLAGS ::"; : For debugging.
+       +$(am__make_dryrun) || exit 1; echo ok > from-dry-mode
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+$MAKE notdry
+
+# Test against a known regressions.  This was especially
+# heinous, since make running in normal mode was sometimes
+# mistaken for make running in dry mode.
+$MAKE notdry TESTS="n1.test n2.test"
+$MAKE notdry TESTS="n1 n2" AM_MAKEFLAGS="TESTS='n1 n2'"
+$MAKE notdry TESTS="n1 n2" AM_MAKEFLAGS='TESTS="n1 n2"'
+$MAKE notdry FOOFLAGS="-n -n -knf2 \\n --none -n"
+$MAKE notdry BARFLAGS="-n \"n\" '-n' --none -n"
+
+if echo 'all: ; @+printf %sbb%s aa cc' | $MAKE -n -f - | grep aabbcc; then
+  $MAKE -n dry
+  test -f from-dry-mode
+  rm -f from-dry-mode
+fi
+
+if using_gmake; then
+  $MAKE --dry-run -k dry
+  test -f from-dry-mode
+fi
+
+:
-- 
1.7.7.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]