diff options
author | Stefano Lattarini <stefano.lattarini@gmail.com> | 2012-06-06 17:37:12 +0200 |
---|---|---|
committer | Stefano Lattarini <stefano.lattarini@gmail.com> | 2012-06-06 17:37:21 +0200 |
commit | 0a5dd0b2f92fcac769cfdb3bf2ffac80bcfa5a42 (patch) | |
tree | 371e83866505fffb4c72bf087a4788d67f4c46ac /t/vartypos-whitelist.sh | |
parent | ddc05a1f8013cecc1276414c50a7142272240ba4 (diff) | |
download | automake-0a5dd0b2f92fcac769cfdb3bf2ffac80bcfa5a42.tar.gz |
[ng] vartypos: allow user to whitelist false positives
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 <stefano.lattarini@gmail.com>
Diffstat (limited to 't/vartypos-whitelist.sh')
-rwxr-xr-x | t/vartypos-whitelist.sh | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/t/vartypos-whitelist.sh b/t/vartypos-whitelist.sh new file mode 100755 index 000000000..7c718b2dc --- /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 + +: |