As discussed on the bug-autoconf list. The heuristics cannot be made perfect (code commonly calls AC_MSG_RESULT more often than AC_MSG_CHECKING; and scenarios like the obsolete AC_COMPILE_CHECK, or improperly nested AC_CACHE_CHECK, can alter the balance), but should be decent enough for most well-written configure.ac. And, as was pointed out, the presence or absence of "(cached)" on stdout doesn't impact the correctness of the configure results.
From: Eric Blake <[email protected]> Date: Mon, 2 Mar 2009 09:19:19 -0700 Subject: [PATCH] Silence AC_CACHE_VAL if not part of AC_MSG sequence. * lib/autoconf/general.m4 (AC_MSG_CHECKING, AC_MSG_RESULT): Track pairs of calls. (AC_CACHE_VAL): Don't output '(cached) ' if not following AC_MSG_CHECKING. (AC_MSG_RESULT_UNQUOTED): Adjust client. * tests/base.at (AC_CACHE_VAL): New test. * doc/autoconf.texi (Caching Results) <AC_CACHE_VAL>: Document the improved semantics. Suggested by Bruno Haible. Signed-off-by: Eric Blake <[email protected]> --- ChangeLog | 13 ++++++++++++ doc/autoconf.texi | 9 +++++-- lib/autoconf/general.m4 | 18 +++++++++------- tests/base.at | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 08f9e29..7546c75 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2009-03-02 Eric Blake <[email protected]> + + Silence AC_CACHE_VAL if not part of AC_MSG sequence. + * lib/autoconf/general.m4 (AC_MSG_CHECKING, AC_MSG_RESULT): Track + pairs of calls. + (AC_CACHE_VAL): Don't output '(cached) ' if not following + AC_MSG_CHECKING. + (AC_MSG_RESULT_UNQUOTED): Adjust client. + * tests/base.at (AC_CACHE_VAL): New test. + * doc/autoconf.texi (Caching Results) <AC_CACHE_VAL>: Document the + improved semantics. + Suggested by Bruno Haible. + 2009-02-24 Eric Blake <[email protected]> Use pkgdatadir consistently. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 0c0740b..9e3fc46 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -8980,10 +8980,13 @@ Caching Results @defmac AC_CACHE_VAL (@var{cache-id}, @var{commands-to-set-it}) @acindex{CACHE_VAL} Ensure that the results of the check identified by @var{cache-id} are -available. If the results of the check were in the cache file that was -read, and @command{configure} was not given the @option{--quiet} or +available. If the results of the check were supplied by the cache, then +use those results; additionally, if this macro occurs between an +...@code{ac_msg_checking} and @code{AC_MSG_RESULT} pair, and +...@command{configure} was not given the @option{--quiet} or @option{--silent} option, print a message saying that the result was -cached; otherwise, run the shell commands @var{commands-to-set-it}. If +cached. If the cache does not have a value yet, run the shell commands +...@var{commands-to-set-it}. If the shell commands are run to determine the value, the value is saved in the cache file just before @command{configure} creates its output files. @xref{Cache Variable Names}, for how to choose the name of the diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4 index 83254ed..02c36ff 100644 --- a/lib/autoconf/general.m4 +++ b/lib/autoconf/general.m4 @@ -2014,7 +2014,9 @@ rm -f confcache[]dnl # AC_CACHE_VAL(CACHE-ID, COMMANDS-TO-SET-IT) # ------------------------------------------ # The name of shell var CACHE-ID must contain `_cv_' in order to get saved. -# Should be dnl'ed. Try to catch common mistakes. +# Should be dnl'ed. Try to catch common mistakes. Output "(cached)" if +# the cache was used, this macro is in an AC_MSG_CHECKING/AC_MSG_RESULT +# pair, and the --silent option to configure was not used. m4_defun([AC_CACHE_VAL], [AS_LITERAL_IF([$1], [m4_if(m4_index(m4_quote($1), [_cv_]), [-1], [AC_DIAGNOSE([syntax], @@ -2028,7 +2030,7 @@ m4_if(m4_index([$2], [AC_SUBST]), [-1], [], [$0($1, ...): suspicious presence of an AC_SUBST in the second argument, ]dnl [where no actions should be taken])])dnl AS_VAR_SET_IF([$1], - [_AS_ECHO_N([(cached) ])], + m4_ifdef([_AC_MSG_CHECKING], [[_AS_ECHO_N([(cached) ])]]), [$2]) ]) @@ -2214,16 +2216,16 @@ m4_define([AC_WARNING], # ------------------------ m4_define([AC_MSG_CHECKING], [{ _AS_ECHO_LOG([checking $1]) -_AS_ECHO_N([checking $1... ]); }dnl -]) +_AS_ECHO_N([checking $1... ]); }]dnl +[m4_define([_AC_MSG_CHECKING])]) # AC_MSG_RESULT(RESULT) # --------------------- m4_define([AC_MSG_RESULT], [{ _AS_ECHO_LOG([result: $1]) -_AS_ECHO([$1]); }dnl -]) +_AS_ECHO([$1]); }]dnl +[m4_ifdef([_AC_MSG_CHECKING], [m4_undefine([_AC_MSG_CHECKING])])]) # AC_MSG_WARN(PROBLEM) @@ -2259,8 +2261,8 @@ AU_DEFUN([AC_CHECKING], # No escaping, so it performed also backtick substitution. AU_DEFUN([AC_MSG_RESULT_UNQUOTED], [_AS_ECHO_UNQUOTED([$as_me:${as_lineno-$LINENO}: result: $1], AS_MESSAGE_LOG_FD) -_AS_ECHO_UNQUOTED([$1])[]dnl -]) +_AS_ECHO_UNQUOTED([$1])[]]dnl +[m4_ifdef([_AC_MSG_CHECKING], [m4_undefine([_AC_MSG_CHECKING])])]) # AU::AC_VERBOSE(STRING) diff --git a/tests/base.at b/tests/base.at index b5ee30f..6d3c9bc 100644 --- a/tests/base.at +++ b/tests/base.at @@ -234,6 +234,57 @@ AT_CHECK_CONFIGURE([-q]) AT_CLEANUP +## -------------- ## +## AC_CACHE_VAR. ## +## -------------- ## + +# Make sure AC_CACHE_VAL is silent with -q or when outside +# AC_MSG_CHECKING/AC_MSG_RESULT. + +AT_SETUP([AC_CACHE_VAL]) + +AT_DATA_AUTOCONF([configure.ac], +[[AC_INIT +AS_UNSET([my_cv_foo]) +dnl When uncommented, this line serves as a silent cache primer. +# AC_CACHE_VAL([my_cv_foo], [my_cv_foo=0]) +AC_MSG_CHECKING([first]) +AC_CACHE_VAL([my_cv_foo], [my_cv_foo=1]) +AC_MSG_RESULT([$my_cv_foo]) +dnl It is a common idiom to have one CHECKING and multiple RESULTS. +AC_MSG_CHECKING([second]) +AC_CACHE_VAL([my_cv_foo], [my_cv_foo=2]) +if test $my_cv_foo = 2 ; then + AC_MSG_RESULT([2]) +else + AC_MSG_RESULT([$my_cv_foo]) +fi +AC_CACHE_VAL([my_cv_foo], [my_cv_foo=3]) +echo $my_cv_foo +]]) + +AT_CHECK_AUTOCONF +AT_CHECK_CONFIGURE([], [], +[[checking first... 1 +checking second... (cached) 1 +1 +]]) + +sed 's/^# //' configure.ac > t +mv -f t configure.ac +AT_CHECK_AUTOCONF +AT_CHECK_CONFIGURE([], [], +[[checking first... (cached) 0 +checking second... (cached) 0 +0 +]]) + +AT_CHECK_CONFIGURE([-q], [], [[0 +]]) + +AT_CLEANUP + + ## ---------------- ## ## AC_COMPUTE_INT. ## ## ---------------- ## -- 1.6.1.2
