chiark / gitweb /
Warning reporting: Provide &:local+global directive
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 28 Dec 2019 18:26:09 +0000 (18:26 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 30 Dec 2019 11:35:16 +0000 (11:35 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
README
generate
tests/filter/Dir.mk.expected
tests/filter/Dir.sd.mk

diff --git a/README b/README
index 98fe313ac9dea5a3835c7df0a9857a57f441b279..41110ce410ac8ca098cff5e28cbd182951fcc4ee 100644 (file)
--- a/README
+++ b/README
@@ -277,6 +277,11 @@ So pathname syntax is a subset of:
        by the final warning state after processing all the toplevel
        input files (including Final.sd.mk).
 
+&:local+global [&]VARIABLE ...
+       Suppresses the warning about seeing both VARIABLE and
+       &VARIABLE.  Any & specified in the RHS is redundant: this
+       always affects both versions identically.
+
 &:changequote NEWQUOTE
        changes the escape sequence from & to literally NEWQUOTE
        NEWQUOTE may be any series of of non-whitespace characters,
@@ -392,6 +397,8 @@ suppressed with the &:warn directive.  The warning tags are:
        The same VARNAME was used both with and without an & prefix.
        This can be confusing.  Also, if you avoid this then you will
        get a warning iff you accidentally leave off a needed &.
+       (You can suppress this warning for a particular VARNAME with
+       the &:local+global directive.)
 
     single-char-var
        A variable expansion like $FBAR.  make's expansion rules
index 3caf4e65a0bac0d559c7d891904cefae29584179..61bbd507c683adc89d5fe648260737a7c0492e73 100755 (executable)
--- a/generate
+++ b/generate
@@ -289,9 +289,15 @@ sub process_input_mk ($$$$) {
                }
            }
            next;
+       } elsif (s#^\s*$esc\:local\+global\s+(\S.*)$##) {
+           foreach my $vn (split /\s+/, $1) {
+               $vn =~ s{^$esc}{};
+               $varref{$vn}{NoWarn} = 1;
+           }
+           next;
        } elsif (s#^\s*$esc\:(?=(-?)include|macro)##) {
            $buffering_output='';
-       } elsif (m#^\s*$esc\:([a-z][-0-9a-z_]*)#) {
+       } elsif (m#^\s*$esc\:([a-z][-+0-9a-z_]*)#) {
            err "unknown directive &:$1 or bad argumnt syntax";
        } elsif (s{^\s*${esc}TARGETS(?:_([0-9a-zA-Z_]+))?(?=\W)}{}) {
            my $t = $1 // 'all';
@@ -513,6 +519,7 @@ sub print_varref_warnings () {
     foreach my $vn (sort keys %varref) {
        my $vv = $varref{$vn};
        next unless $vv->{''} && $vv->{1};
+       next if $vv->{NoWarn};
        wrncore 'local+global', "saw both $vn and &$vn" or return;
        foreach my $amp ('', 1) {
            printf STDERR " saw %s%s at %s\n",
index 14cc88aa0e5ca4187f3072b3baed92afd3bd5b03..7eecb238dd9b05a69aa47d69581e0e0dc202c6ef 100644 (file)
@@ -12,6 +12,9 @@ TOP_WARN += 3
 # $(TOP_WARN)
 # $(TOP_WARN)
 
+# $(TOP_NOWARN1) $(NOWARN1)
+# $(TOP_NOWARN2) $(NOWARN2)
+
 ${eval ${call  some-macro, 42, $$x, {  $(foreach something) } }}
 
 # doctests:
index 3a20de356a9347c5f68b77521e3d5354ff27b850..1a4eb1fed85ffec1153efc6e5961153eebc1838b 100644 (file)
@@ -10,6 +10,10 @@ WARN += 3
 # $(&WARN)
 # &$WARN
 
+&:local+global NOWARN1 &NOWARN2
+# &$NOWARN1 $(NOWARN1)
+# &$NOWARN2 $(NOWARN2)
+
 &${ some-macro, 42, $x, { &$- $(foreach something) } }
 
 # doctests: