automake-ng
[Top][All Lists]
Advanced

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

[Automake-NG] [PATCH 1/2] [ng] vartypos: allow user to whitelist false p


From: Stefano Lattarini
Subject: [Automake-NG] [PATCH 1/2] [ng] vartypos: allow user to whitelist false positives
Date: Wed, 6 Jun 2012 18:15:47 +0200

It can happen that the user legitimately employs what the new Automake-NG
make runtime warnings would take for an erroneous usage; for example, GNU
coreutils 8.17 uses something like this is its build system (see file
'src/Makefile.am'):

    # Shared files.
    copy_LDADD =
    cp_LDADD += $(copy_LDADD)
    ginstall_LDADD += $(copy_LDADD)
    mv_LDADD += $(copy_LDADD)
    ...
    copy_LDADD += $(LIB_SELINUX)       # for selinux use
    copy_LDADD += $(LIB_CLOCK_GETTIME) # for gettime, settime, ...
    copy_LDADD += $(LIB_XATTR)         # for various xattr functions
    ...

Since it does so without having a program called 'copy' anywhere, the
Makefile generated by Automake complains like this:

    Makefile:2544: variable 'copy_LDADD' is defined but no program
    Makefile:2544:   or library has 'copy' as canonical name
    Makefile:2546: *** Some Automake-NG error occurred.  Stop.

Instead of forcing the coreutils developers to heavily edit their Makefile,
it is better to allow them to whitelist their suspicious usages as correct.
And such a whitelisting capability is a good idea even regardless this
motivation, since it helps enforcing the Autotools- philosophy "the user is
always right" (as long as he is explicit enough).

* lib/am/check-typos (.am/vartypos/whitelisted-vars ): Also add the contents
of the user-reserved variable '$(AM_VARTYPOS_WHITELIST)' (note that it is
still undocumented).
* t/vartypos-whitelist.sh: New test.

Signed-off-by: Stefano Lattarini <address@hidden>
---

 I plan to push this soon, because it is required by the GNU coreutils
 "fork" that uses Automake-NG.

 lib/am/check-typos.am   |    4 ++
 t/vartypos-whitelist.sh |  109 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+)
 create mode 100755 t/vartypos-whitelist.sh

diff --git a/lib/am/check-typos.am b/lib/am/check-typos.am
index 82e19c9..71769c9 100644
--- a/lib/am/check-typos.am
+++ b/lib/am/check-typos.am
@@ -48,6 +48,10 @@ ifeq "$(am__using_parallel_tests)" "yes"
              $(filter %_LOG_DRIVER,$(.VARIABLES)))
 endif
 
+# Allow the user to add his own whitelist.
+# FIXME: this is still undocumtend!
+.am/vartypos/whitelisted-vars += $(AM_VARTYPOS_WHITELIST)
+
 # Canonicalized names of programs and libraries (vanilla or libtool) that
 # have been declared.
 .am/vartypos/known-canon-proglibs := \
diff --git a/t/vartypos-whitelist.sh b/t/vartypos-whitelist.sh
new file mode 100755
index 0000000..7c718b2
--- /dev/null
+++ b/t/vartypos-whitelist.sh
@@ -0,0 +1,109 @@
+#! /bin/sh
+# Copyright (C) 2010-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/>.
+
+# Make sure we allow the use to whitelist false positives in our
+# detection of variable typos.  Inspired by the GNU coreutils (8.17)
+# build system.
+
+required=cc
+. ./defs || Exit 1
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_RANLIB
+AC_SUBST([LIBSELINUX], ["$l_selinux"])
+AC_OUTPUT
+END
+
+l_selinux=; export l_selinux=
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = cp mv rm
+noinst_LIBRARIES = libremove.a libcopy.a
+remove_LDADD = libremove.a
+copy_LDADD = libcopy.a
+copy_LDADD += @LIBSELINUX@
+cp_LDADD = $(copy_LDADD)
+rm_LDADD = $(remove_LDADD)
+mv_LDADD = $(copy_LDADD) $(remove_LDADD)
+AM_VARTYPOS_WHITELIST = copy_LDADD remove_LDADD
+EXTRA_DIST = libcopy.h libremove.h
+END
+
+echo 'extern void cu_copy (void);' > libcopy.h
+echo 'extern void cu_remove (void);' > libremove.h
+
+cat > libcopy.c << 'END'
+#include "libcopy.h"
+void cu_copy (void) { return; }
+END
+
+cat > libremove.c << 'END'
+#include "libremove.h"
+void cu_remove (void) { return; }
+END
+
+cat > cp.c <<'END'
+#include "libcopy.h"
+int main (void)
+{
+  cu_copy ();
+  return 0;
+}
+END
+
+cat > rm.c <<'END'
+#include "libremove.h"
+int main (void)
+{
+  cu_remove ();
+  return 0;
+}
+END
+
+cat > mv.c <<'END'
+#include "libremove.h"
+#include "libcopy.h"
+int main (void)
+{
+  cu_copy ();
+  cu_remove ();
+  return 0;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+$MAKE
+
+# If we remove the whitelisting, failure ensues.
+$MAKE AM_VARTYPOS_WHITELIST= 2>stderr && { cat stderr; Exit 1; }
+cat stderr >&2
+grep "'copy_LDADD' is defined but no program" stderr
+grep "'remove_LDADD' is defined but no program" stderr
+$MAKE AM_VARTYPOS_WHITELIST=remove_LDADD 2>stderr && { cat stderr; Exit 1; }
+cat stderr >&2
+grep "'copy_LDADD' is defined but no program" stderr
+grep "remove_LDADD" stderr && Exit 1
+
+# Sanity check the distribution.
+$MAKE distcheck
+
+:
-- 
1.7.9.5




reply via email to

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