From 08e825fede28f22ce3fbaf494c3e06360ed74d7a Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 28 Dec 2019 18:26:09 +0000 Subject: [PATCH 1/1] Warning reporting: Provide &:local+global directive Signed-off-by: Ian Jackson --- README | 7 +++++++ generate | 9 ++++++++- tests/filter/Dir.mk.expected | 3 +++ tests/filter/Dir.sd.mk | 4 ++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README b/README index 98fe313..41110ce 100644 --- 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 diff --git a/generate b/generate index 3caf4e6..61bbd50 100755 --- 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", diff --git a/tests/filter/Dir.mk.expected b/tests/filter/Dir.mk.expected index 14cc88a..7eecb23 100644 --- a/tests/filter/Dir.mk.expected +++ b/tests/filter/Dir.mk.expected @@ -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: diff --git a/tests/filter/Dir.sd.mk b/tests/filter/Dir.sd.mk index 3a20de3..1a4eb1f 100644 --- a/tests/filter/Dir.sd.mk +++ b/tests/filter/Dir.sd.mk @@ -10,6 +10,10 @@ WARN += 3 # $(&WARN) # &$WARN +&:local+global NOWARN1 &NOWARN2 +# &$NOWARN1 $(NOWARN1) +# &$NOWARN2 $(NOWARN2) + &${ some-macro, 42, $x, { &$- $(foreach something) } } # doctests: -- 2.30.2