From f49235499d9f2ddde6262ee06d140e6e96adb419 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Fri, 23 Aug 2002 13:32:55 +0000 Subject: [PATCH] For PR automake/347: * automake.in (MACRO_PATTERN): Allow `.' in variable names. (scan_variable_expansions, check_variable_expansions): New functions. (macro_define): Call check_variable_expansions. (read_am_file): Likewise, when outputing rules. (variable_conditions_recursive_sub): Simplify using scan_variable_expansions. * tests/vars3.test: New file. * tests/Makefile.am (TESTS): Add vars3.test. * tests/colneq.test: Use -Wno-portability. --- ChangeLog | 11 +++++ automake.in | 121 +++++++++++++++++++++++++++++++--------------- tests/Makefile.am | 1 + tests/Makefile.in | 2 + tests/colneq.test | 1 + tests/vars3.test | 69 ++++++++++++++++++++++++++ 6 files changed, 166 insertions(+), 39 deletions(-) create mode 100755 tests/vars3.test diff --git a/ChangeLog b/ChangeLog index 0e962ff8b..ac54725f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2002-08-23 Alexandre Duret-Lutz + For PR automake/347: + * automake.in (MACRO_PATTERN): Allow `.' in variable names. + (scan_variable_expansions, check_variable_expansions): New functions. + (macro_define): Call check_variable_expansions. + (read_am_file): Likewise, when outputing rules. + (variable_conditions_recursive_sub): Simplify using + scan_variable_expansions. + * tests/vars3.test: New file. + * tests/Makefile.am (TESTS): Add vars3.test. + * tests/colneq.test: Use -Wno-portability. + * lib/Automake/Channels.pm (buffering, backlog): New variables. (buffer_messages, flush_messages): New functions. (@EXPORT): Add buffer_messages and flush_messages. diff --git a/automake.in b/automake.in index ddad1e3b1..302a736e4 100755 --- a/automake.in +++ b/automake.in @@ -156,7 +156,7 @@ my $SUFFIX_RULE_PATTERN = # Only recognize leading spaces, not leading tabs. If we recognize # leading tabs here then we need to make the reader smarter, because # otherwise it will think rules like `foo=bar; \' are errors. -my $MACRO_PATTERN = '^[A-Za-z0-9_@]+' . "\$"; +my $MACRO_PATTERN = '^[.A-Za-z0-9_@]+' . "\$"; my $ASSIGNMENT_PATTERN = '^ *([^ \t=:+]*)\s*([:+]?)=\s*(.*)' . "\$"; # This pattern recognizes a Gnits version id and sets $1 if the # release is an alpha release. We also allow a suffix which can be @@ -1337,10 +1337,10 @@ sub accept_extensions (@) # var_SUFFIXES_trigger ($TYPE, $VALUE) # ------------------------------------ -# This is called automagically by define_macro() when SUFFIXES +# This is called automagically by macro_define() when SUFFIXES # is defined ($TYPE eq '') or appended ($TYPE eq '+'). # The work here needs to be performed as a side-effect of the -# define_macro() call because SUFFIXES definitions impact +# macro_define() call because SUFFIXES definitions impact # on $KNOWN_EXTENSIONS_PATTERN, and $KNOWN_EXTENSIONS_PATTERN # are used when parsing the input am file. sub var_SUFFIXES_trigger ($$) @@ -3402,8 +3402,7 @@ sub handle_ltlibraries } } -# See if any _SOURCES variable were misspelled. Also, make sure that -# EXTRA_ variables don't contain configure substitutions. +# See if any _SOURCES variable were misspelled. sub check_typos () { # It is ok if the user sets this particular variable. @@ -6169,6 +6168,8 @@ sub macro_define ($$$$$$) "$var: variable names starting with `_' are not portable") if $var =~ /^_/; + check_variable_expansions ($value, $where); + $cond ||= 'TRUE'; # An Automake variable must be consistently defined with the same @@ -6573,7 +6574,56 @@ sub variable_conditionally_defined ($) return 0; } +# @LIST +# &scan_variable_expansions ($TEXT) +# --------------------------------- +# Return the list of variable names expanded in $TEXT. +# Note that unlike some other functions, $TEXT is not split +# on spaces before we check for subvariables. +sub scan_variable_expansions ($) +{ + my ($text) = @_; + my @result = (); + + # Strip comments. + $text =~ s/#.*$//; + + # Record each use of ${stuff} or $(stuff) that do not follow a $. + while ($text =~ /(? Makefile.am << 'END' +AUTOMAKE_OPTIONS = -Wno-portability ICONS := $(wildcard *.xbm) data_DATA = $(ICONS) END diff --git a/tests/vars3.test b/tests/vars3.test new file mode 100755 index 000000000..b7463ceab --- /dev/null +++ b/tests/vars3.test @@ -0,0 +1,69 @@ +#! /bin/sh + +# Check that Automake warns about variables containing spaces +# and other non-POSIX characters. + +. $srcdir/defs || exit 1 + +set -e + +cat >Makefile.am <<'EOF' +L01 = $(shell echo *) +L02 = $$(not an error) +L03 = $$(this is)$${ok too} +L04 = $(nextvariableisbad)$(addsuffix .a, $(A)) +L05 = "$(bad boy)" +L06 = $(this:is= ok) +L07 = ${three errors}${on this} $(long line) +L08$(o u c h): $(wildcard *.c) + ${another error} + echo $${ok-this is} +L11: $(thisis) $(ok) + ${here} +EOF + +$ACLOCAL +# Make sure this warning is print in the `portability' category. +$AUTOMAKE --warnings=no-error,none,portability 2>stderr +cat stderr + +# Lines number are printed in error message. +# Use them to make sure errors are diagnosed against the right lines. + +# No error expected for these lines. +grep 1: stderr +grep 2: stderr && exit 1 +grep 3: stderr && exit 1 +grep 4: stderr +grep 5: stderr +grep 6: stderr && exit 1 +grep 7: stderr +grep 8: stderr +grep 9: stderr +grep 10: stderr && exit 1 +grep 11: stderr && exit 1 +grep 12: stderr && exit 1 + +# Now check some individual values. +grep 'shell echo' stderr +grep 'nextvariableisbad' stderr && exit 1 +grep 'addsuffix' stderr +grep 'bad boy' stderr +grep 'ok' stderr && exit 1 +grep 'three errors' stderr +grep 'on this' stderr +grep 'long line' stderr +grep 'o u c h' stderr +grep 'wildcard' stderr +grep 'another error' stderr +grep 'thisis' stderr && exit 1 +grep 'here' stderr && exit 1 + +# None of these errors be diagnosed with -Wno-portability +$AUTOMAKE -Wno-portability + +# Likewise if we add this in the Makefile.am +# (although this makes some difference internally: AUTOMAKE_OPTIONS is +# processed far later). +echo 'AUTOMAKE_OPTIONS = -Wno-portability' >> Makefile.am +$AUTOMAKE -- 2.47.2