From: Akim Demaille Date: Fri, 22 Aug 2003 13:38:33 +0000 (+0000) Subject: Output stack traces in warnings. X-Git-Tag: AUTOCONF-2.57b~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=358bc50517980ce7ed8e7bb7237fd2969664d64b;p=thirdparty%2Fautoconf.git Output stack traces in warnings. * lib/m4sugar/m4sugar.m4 (_m4_warn): New. Replace the former... (m4_warn): Pass the call stack to _m4_warn. * bin/autom4te.in: Adjust to output the call stack. * tests/m4sugar.at (m4@&t@_warn): Adjust. --- diff --git a/ChangeLog b/ChangeLog index 1ed03087..f4df52fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2003-08-22 Akim Demaille + + Output stack traces in warnings. + + * lib/m4sugar/m4sugar.m4 (_m4_warn): New. + Replace the former... + (m4_warn): Pass the call stack to _m4_warn. + * bin/autom4te.in: Adjust to output the call stack. + * tests/m4sugar.at (m4@&t@_warn): Adjust. + 2003-08-22 Akim Demaille * lib/Autom4te/Request.pm, lib/Autom4te/C4che.pm: New. diff --git a/bin/autom4te.in b/bin/autom4te.in index 6a7bc80d..1a20d5a2 100644 --- a/bin/autom4te.in +++ b/bin/autom4te.in @@ -78,7 +78,7 @@ my %trace; # FIXME: What about `sinclude'? my @preselect = ('include', 'm4_pattern_allow', 'm4_pattern_forbid', - 'm4_warn'); + '_m4_warn'); # M4 include path. my @include; @@ -993,11 +993,23 @@ handle_m4 ($req, keys %{$req->macro}) # Issue the warnings each time autom4te was run. handle_traces ($req, "$tmp/warnings", - ('m4_warn' => "\$1::\$f:\$l::\$2\n\n")); + ('_m4_warn' => "\$1::\$f:\$l::\$2::\$3\n\n")); +# Warnings are separated by 2 \n. for (split (/\n{2,}/, contents ("$tmp/warnings"))) { - my ($cat, $loc, $msg) = split '::'; + # The message looks like: + # | syntax::input.as:5::ouch + # | ::input.as:4: baz is expanded from... + # | input.as:2: bar is expanded from... + # | input.as:3: foo is expanded from... + # | input.as:5: the top level + my ($cat, $loc, $msg, $stacktrace) = split ('::', $_, 4); msg $cat, $loc, "warning: $msg"; + for (split /\n/, $stacktrace) + { + my ($loc, $trace) = split (': ', $_, 2); + msg $cat, $loc, $trace; + } } # Now output... diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index 2fd34960..42210125 100644 --- a/lib/m4sugar/m4sugar.m4 +++ b/lib/m4sugar/m4sugar.m4 @@ -201,17 +201,29 @@ m4_define([m4_assert], [m4_fatal([assert failed: $1], [$2])])]) + ## ------------- ## ## 3. Warnings. ## ## ------------- ## +# _m4_warn(CATEGORY, MESSAGE, STACK-TRACE) +# ---------------------------------------- +# Report a MESSAGE to the user if the CATEGORY of warnings is enabled. +# This is for traces only. +# The STACK-TRACE is a \n-separated list of "LOCATION: MESSAGE". +m4_define([_m4_warn], []) + + # m4_warn(CATEGORY, MESSAGE) # -------------------------- -# Report a MESSAGE to the autoconf user if the CATEGORY of warnings -# is requested (in fact, not disabled). This is for traces only. -m4_define([m4_warn], []) - +# Report a MESSAGE to the user if the CATEGORY of warnings is enabled. +m4_define([m4_warn], +[_m4_warn([$1], [$2], +m4_ifdef([m4_expansion_stack], + [m4_defn([m4_expansion_stack]) +m4_location[: the top level]])) +]) diff --git a/tests/m4sugar.at b/tests/m4sugar.at index 99a4c300..716d8df8 100644 --- a/tests/m4sugar.at +++ b/tests/m4sugar.at @@ -42,29 +42,38 @@ AT_SETUP([[m4@&t@_warn]]) # warnings. But maybe autom4te should handle that by itself? AT_DATA_M4SUGAR([script.4s], -[[m4_warn([obsolete], [obsolete]) -m4_warn([cross], [cross]) +[[m4_init +m4_defun([cross_warning], +[m4_warn([cross], [cross]) +]) + +m4_warn([obsolete], [obsolete]) +cross_warning m4_warn([syntax], [syntax]) ]]) AT_CHECK_M4SUGAR([-o-], 0, [], -[script.4s:3: warning: syntax +[script.4s:8: warning: syntax ]) AT_CHECK_M4SUGAR([-o- -Wall -f], 0, [], -[script.4s:1: warning: obsolete -script.4s:2: warning: cross -script.4s:3: warning: syntax +[script.4s:6: warning: obsolete +script.4s:7: warning: cross +script.4s:4: cross_warning is expanded from... +script.4s:7: the top level +script.4s:8: warning: syntax ]) AT_CHECK_M4SUGAR([-o- -Wnone,cross -f], 0, [], -[script.4s:2: warning: cross +[script.4s:7: warning: cross +script.4s:4: cross_warning is expanded from... +script.4s:7: the top level ]) AT_CHECK_M4SUGAR([-o- -Wnone,cross,error -f], 1, [], -[[script.4s:2: error: cross -script.4s:2: the top level -autom4te: m4 failed with exit status: 1 +[[script.4s:7: warning: cross +script.4s:4: cross_warning is expanded from... +script.4s:7: the top level ]]) AT_CLEANUP