[Top][All Lists]

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

[PATCH] warn: allow aclocal to silence m4_require warnings

From: Eric Blake
Subject: [PATCH] warn: allow aclocal to silence m4_require warnings
Date: Fri, 9 Nov 2012 14:23:32 -0700

From: Stefano Lattarini <address@hidden>

We introduce a new witness macro, m4_require_silent_probe, for use by
aclocal during the Autoconf-without-aclocal-m4 language.  This will let
aclocal process AC_CONFIG_MACRO_DIRS without emitting spurious warnings.
In fact, if aclocal doesn't suppress require warnings, then, when some macro
expanded in calls AC_REQUIRE on another macro that is defined
in one of the local m4 macro dirs specified with AC_CONFIG_MACRO_DIRS, the
*first* autom4te invocation issued by aclocal, not yet being able to "see"
the m4 macro definitions in the local m4 dirs, will prints spurious
warnings like: warning: MY_BAR is m4_require'd but not m4_defun'd MY_FOO is expanded from...

Expose the use of this macro in our testsuite.

Originally reported by Nick Bowler; see point (4) of:

* lib/m4sugar/m4sugar.m4 (_m4_require_call): Make warnings in the
-Wsyntax category depend on the witness macro.
* tests/ (m4@&address@hidden: warning message): New test.
* doc/autoconf.texi (Prerequisite Macros): Document how aclocal
can silence AC_REQUIRE (m4_require) warnings.

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

Stefano, this is a heavily reworked version of your 3/3 patch; since
it was originally your idea to inject the witness macro definition
via piping through autom4te's stdin, I've kept the git authorship
tied to you.  Let me know if I should flip it to me, although it's
definitely something we've co-authored.

Question: Should I actually document the witness macro in the manual,
or is it something where the testsuite ensures we won't break stability,
and where not documenting it other than via the testsuite will avoid
other users mistakenly defining it?

 doc/autoconf.texi      |  7 +++++++
 lib/m4sugar/m4sugar.m4 |  8 +++++++-
 tests/       | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 66b5311..eb69038 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -14636,6 +14636,13 @@ Prerequisite Macros
 at the beginning of a macro.  You can use @code{dnl} to avoid the empty
 lines they leave.

+Autoconf will normally warn if an @code{AC_REQUIRE} call refers to a
+macro that has not been defined.  However, the @command{aclocal} tool
+relies on parsing an incomplete set of input files to trace which macros
+have been required, in order to then pull in additional files that
+provide those macros; for this particular use case, pre-defining the
+macro @code{m4_require_silent_probe} will avoid the warnings.
 @node Suggested Ordering
 @subsection Suggested Ordering
 @cindex Macros, ordering
diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4
index 12a9ab7..94c4ba8 100644
--- a/lib/m4sugar/m4sugar.m4
+++ b/lib/m4sugar/m4sugar.m4
@@ -2080,13 +2080,19 @@ m4_if([$0], [m4_require], [[m4_defun]], 
[[AC_DEFUN]])['d macro])])]dnl
 # This is called frequently, so minimize the number of macro invocations
 # by avoiding dnl and other overhead on the common path.
+# The use of a witness macro protecting the warning allows aclocal
+# to silence any warnings when probing for what macros are required
+# and must therefore be located, when using the Autoconf-without-aclocal-m4
+# autom4te language.  For more background, see:
 [m4_pushdef([_m4_divert_grow], m4_decr(_m4_divert_grow))]dnl
 [m4_pushdef([_m4_diverting([$1])])m4_pushdef([_m4_diverting], [$1])]dnl
 [m4_divert_push(_m4_divert_grow, [-])]dnl
 [m4_if([$2], [], [$1], [$2])
 m4_provide_if([$1], [m4_set_remove([_m4_provide], [$1])],
-  [m4_warn([syntax], [$1 is m4_require'd but not m4_defun'd])])]dnl
+  [m4_ifndef([m4_require_silent_probe],
+    [m4_warn([syntax], [$1 is m4_require'd but not m4_defun'd])])])]dnl
 [_m4_diverting([$1])], [_m4_diverting])])
diff --git a/tests/ b/tests/
index 997e2dd..0fbd3c2 100644
--- a/tests/
+++ b/tests/
@@ -429,6 +429,57 @@ autom4te: m4 failed with exit status: 1

+## ----------------------------- ##
+## m4_require: warning message.  ##
+## ----------------------------- ##
+AT_SETUP([m4@&address@hidden: warning message])
+AT_KEYWORDS([m4@&address@hidden m4@&address@hidden)
+# Mirror the job of aclocal on a typical scenario: the user invokes a
+# single macro that comes from one included file, which in turn requires
+# another macro from a second file.  When using the incomplete set of
+# files, we want a warning, unless we are merely learning which additional
+# macros are needed in order to regenerate the list of files to include.
+[[m4_defun([foo], [m4_require([bar])])
+[[m4_defun([bar], [BAR])
+AT_CHECK_M4SUGAR([], [0], [],
+[[script.4s:3: warning: bar is m4@&address@hidden'd but not 
+script1.4s:1: foo is expanded from...
+script.4s:3: the top level
+# Inline expansion of AT_CHECK_M4SUGAR, mirroring how aclocal will
+# inject a definition of our witness macro for a silent run.
+echo 'm4@&address@hidden([m4@&address@hidden) |
+  AT_CHECK_AUTOM4TE([--language=m4sugar - script.4s -o script],
+[0], [], [])
+# Now that we've recomupted the set of include files, things should work.
+AT_CHECK_M4SUGAR([], [0], [], [])
 ## ----------------------------------- ##
 ## m4_require: circular dependencies.  ##
 ## ----------------------------------- ##

reply via email to

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