From 06c537997cbdaab1e4af87ed677347247d169876 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 1 Jul 2001 22:51:38 +0000 Subject: [PATCH] 2001-06-29 Tom Tromey * tests/cond11.test: Use `=', not `=='. * tests/cond12.test: Look for automake in build directory, not source directory. 2001-06-29 Richard Boulton * automake.in (conditionals_true_when): Pass first parameters by reference, avoiding bug which put all parameters in @CONDS instead of @WHENS. Report by Kalle Olavi Niemitalo. Take a single WHEN instead of an array of WHENS. Remove FIXME; can't now have an empty @WHENS. (conditional_is_redundant): New sub. (variable_conditions_reduce): Check whether each condition is implied by any of the other conditions (other those already discarded), rather than checking only against those already considered (and kept). Also, fix sense of check: was keeping tautologous terms instead of discarding them. Use conditional_is_redundant instead of conditionals_true_when. * tests/Makefile.am (TESTS): Added cond11.test and cond12.test. * tests/cond11.test: New file. * tests/cond12.test: New file. --- ChangeLog | 24 ++++++++++++++ automake.in | 63 ++++++++++++++++++++++++----------- tests/Makefile.am | 2 ++ tests/Makefile.in | 2 ++ tests/cond11.test | 41 +++++++++++++++++++++++ tests/cond12.test | 83 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 196 insertions(+), 19 deletions(-) create mode 100755 tests/cond11.test create mode 100755 tests/cond12.test diff --git a/ChangeLog b/ChangeLog index 7e81f973..23ec324e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2001-06-29 Tom Tromey + + * tests/cond11.test: Use `=', not `=='. + * tests/cond12.test: Look for automake in build directory, not + source directory. + +2001-06-29 Richard Boulton + + * automake.in (conditionals_true_when): Pass first parameters by + reference, avoiding bug which put all parameters in @CONDS instead + of @WHENS. Report by Kalle Olavi Niemitalo. + Take a single WHEN instead of an array of WHENS. + Remove FIXME; can't now have an empty @WHENS. + (conditional_is_redundant): New sub. + (variable_conditions_reduce): Check whether each condition is + implied by any of the other conditions (other those already + discarded), rather than checking only against those already + considered (and kept). Also, fix sense of check: was keeping + tautologous terms instead of discarding them. Use + conditional_is_redundant instead of conditionals_true_when. + * tests/Makefile.am (TESTS): Added cond11.test and cond12.test. + * tests/cond11.test: New file. + * tests/cond12.test: New file. + 2001-06-29 Raja R Harinath * automake.in (saw_sources_p): Work even if there are more diff --git a/automake.in b/automake.in index 23d75313..b84b35f5 100755 --- a/automake.in +++ b/automake.in @@ -5392,31 +5392,51 @@ sub conditional_true_when ($$) # $BOOLEAN -# &conditionals_true_when (@CONDS, @WHENS) +# &conditionals_true_when (\@CONDS, $WHEN) # ---------------------------------------- -# Same as above, but true if all the @CONDS are true when *ALL* -# the @WHENS are sufficient. +# Same as above, but true only if all the @CONDS are true when $WHEN is true. # -# If there are no @CONDS, then return true, of course. *BUT*, even if there -# are @CONDS but @WHENS is empty, return true. This is counter intuitive, -# and against all the rules of logic, but is needed by the current code. -# FIXME: Do something saner when the logic of conditionals is understood. -sub conditionals_true_when (@@) +# If there are no @CONDS, then return true. +sub conditionals_true_when (\@$) { - my (@conds, @whens) = @_; + my ($condsref, $when) = @_; - foreach my $cond (@conds) + foreach my $cond (@$condsref) { - foreach my $when (@whens) - { - return 0 - unless conditional_true_when ($cond, $when); - } + return 0 unless conditional_true_when ($cond, $when); } return 1; } +# $BOOLEAN +# &conditional_is_redundant ($COND, @WHENS) +# ---------------------------------------- +# Determine whether $COND is redundant with respect to @WHENS. +# +# Returns true if $COND is true for any of the conditions in @WHENS. +# +# If there are no @WHENS, then behave as if @WHENS contained a single empty +# condition. +sub conditional_is_redundant ($@) +{ + my ($cond, @whens) = @_; + + if (@whens == 0) + { + return 1 if conditional_true_when ($cond, ""); + } + else + { + foreach my $when (@whens) + { + return 1 if conditional_true_when ($cond, $when); + } + } + + return 0; +} + # $NEGATION # condition_negate ($COND) @@ -5922,7 +5942,7 @@ sub variable_conditions_sub # If this condition cannot be true when the parent conditions # are true, then skip it. next - if ! conditionals_true_when ((@parent_conds), ($vcond)); + if ! conditionals_true_when (@parent_conds, $vcond); push (@this_conds, $vcond); @@ -5995,7 +6015,7 @@ sub variable_conditions_sub next if ! $ok; next - if ! conditionals_true_when ((@parent_conds), ($perm)); + if ! conditionals_true_when (@parent_conds, $perm); # This permutation was not already handled, and is valid # for the parents. @@ -6010,23 +6030,28 @@ sub variable_conditions_sub # Filter a list of conditionals so that only the exclusive ones are # retained. For example, if both `COND1_TRUE COND2_TRUE' and # `COND1_TRUE' are in the list, discard the latter. +# If the list is empty, return TRUE sub variable_conditions_reduce { my (@conds) = @_; my @ret = (); - foreach my $cond (@conds) + my $cond; + while(@conds > 0) { + $cond = shift(@conds); + # FALSE is absorbent. if ($cond eq 'FALSE') { return ('FALSE'); } - elsif (conditionals_true_when (($cond), (@ret))) + elsif (!conditional_is_redundant ($cond, @ret, @conds)) { push (@ret, $cond); } } + return "TRUE" if @ret == 0; return @ret; } diff --git a/tests/Makefile.am b/tests/Makefile.am index bfbb8422..9426cb99 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -61,6 +61,8 @@ cond7.test \ cond8.test \ cond9.test \ cond10.test \ +cond11.test \ +cond12.test \ condincl.test \ condincl2.test \ condlib.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index e5d18308..2daaa445 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -127,6 +127,8 @@ cond7.test \ cond8.test \ cond9.test \ cond10.test \ +cond11.test \ +cond12.test \ condincl.test \ condincl2.test \ condlib.test \ diff --git a/tests/cond11.test b/tests/cond11.test new file mode 100755 index 00000000..98c6e5c5 --- /dev/null +++ b/tests/cond11.test @@ -0,0 +1,41 @@ +#! /bin/sh + +# Test for bug in conditionals. From Richard Boulton. +# This checks that, if LDADD is set from a conditional variable +# and an AC_SUBST, the _DEPENDENCIES variable is set correctly. + +. $srcdir/defs || exit 1 + +cat > configure.in << 'END' +AC_INIT(Makefile.am) +AM_INIT_AUTOMAKE(foo,0.0) +AC_PROG_CC +AM_CONDITIONAL(USE_A,[test x = x]) +AC_OUTPUT(Makefile) +AC_SUBST(SUBSTVAR) +END + +cat > Makefile.am << 'END' + +if USE_A +foolibs=faz.la +else +foolibs= +endif + +noinst_PROGRAMS = foo +foo_SOURCES = foo.c +LDADD = $(SUBSTVAR) $(foolibs) +END + +: > config.guess +: > config.sub +: > compile + +$ACLOCAL || exit 1 +$AUTOMAKE || exit 1 + +#Should be two dependency setting lines +count=`grep 'foo_DEPENDENCIES =' Makefile.in | wc -l|sed 's/ //g'` +test "x$count" = "x2" && + grep '^.USE_A_TRUE.foo_DEPENDENCIES =' Makefile.in diff --git a/tests/cond12.test b/tests/cond12.test new file mode 100755 index 00000000..9d3d7b02 --- /dev/null +++ b/tests/cond12.test @@ -0,0 +1,83 @@ +#! /bin/sh + +# Test behaviour of variable_conditions_reduce() +# This checks the result of variable_conditions_reduce() for a wide variety +# of cases. + +. $srcdir/defs || exit 1 + +# FIXME: probably ought to let use override this like we do in `defs'. +amfile=../../automake + +head -n 1 $amfile >>automake_tmp +cat << 'END' >> automake_tmp +my $failed = 0; +sub check_reduce($$) { + my ($inref, $outref) = @_; + my @result = sort &Automake::variable_conditions_reduce(@$inref); + my $correct = 1; + $correct = 0 if (join(",", @result) ne join(",", @$outref)); + + if (! $correct) { + print '"'.join(",", @$inref) . '" => "' . + join(",", @result) . '" expected "' . + join(",", @$outref) . '"' . "\n"; + $failed = 1; + } +} + +# If no conditions are given, TRUE should be returned +check_reduce([""], ["TRUE"]); +# A single condition should be passed through unchanged +check_reduce(["FOO"], ["FOO"]); +check_reduce(["FALSE"], ["FALSE"]); +check_reduce(["TRUE"], ["TRUE"]); + +# TRUE and false should be discarded and overwhelm the result, respectively +check_reduce(["FOO", "TRUE"], ["FOO"]); +check_reduce(["FOO", "FALSE"], ["FALSE"]); + +# Repetitions should be removed +check_reduce(["FOO", "FOO"], ["FOO"]); +check_reduce(["TRUE", "FOO", "FOO"], ["FOO"]); +check_reduce(["FOO", "TRUE", "FOO"], ["FOO"]); +check_reduce(["FOO", "FOO", "TRUE"], ["FOO"]); + +# Two different conditions should be preserved, but TRUEs should be removed +check_reduce(["FOO", "BAR"], ["BAR,FOO"]); +check_reduce(["TRUE", "FOO", "BAR"], ["BAR,FOO"]); +check_reduce(["FOO", "TRUE", "BAR"], ["BAR,FOO"]); +check_reduce(["FOO", "BAR", "TRUE"], ["BAR,FOO"]); + +# A condition implied by another condition should be removed. +check_reduce(["FOO BAR", "BAR"], ["FOO BAR"]); +check_reduce(["BAR", "FOO BAR"], ["FOO BAR"]); +check_reduce(["TRUE", "FOO BAR", "BAR"], ["FOO BAR"]); +check_reduce(["FOO BAR", "TRUE", "BAR"], ["FOO BAR"]); +check_reduce(["FOO BAR", "BAR", "TRUE"], ["FOO BAR"]); + +check_reduce(["BAR FOO", "BAR"], ["BAR FOO"]); +check_reduce(["BAR", "BAR FOO"], ["BAR FOO"]); +check_reduce(["TRUE", "BAR FOO", "BAR"], ["BAR FOO"]); +check_reduce(["BAR FOO", "TRUE", "BAR"], ["BAR FOO"]); +check_reduce(["BAR FOO", "BAR", "TRUE"], ["BAR FOO"]); + +# Check that reduction happens even when there are two conditionals to remove. +check_reduce(["FOO", "FOO BAR", "BAR"], ["FOO BAR"]); +check_reduce(["FOO", "FOO BAR", "BAZ", "FOO BAZ"], ["FOO BAR", "FOO BAZ"]); +check_reduce(["FOO", "FOO BAR", "BAZ", "FOO BAZ", "FOO BAZ BAR"], ["FOO BAZ BAR"]); + +# Duplicated condionals should be removed +check_reduce(["FOO", "BAR", "BAR"], ["BAR,FOO"]); + +# Equivalent conditionals in different forms should be reduced: which one is +# left is unfortunately order dependent. +check_reduce(["BAR FOO", "FOO BAR"], ["FOO BAR"]); +check_reduce(["FOO BAR", "BAR FOO"], ["BAR FOO"]); + +exit $failed; +END +cat $amfile >>automake_tmp +chmod +x automake_tmp + +./automake_tmp -- 2.43.5