util/lint: update kconfig_lint

* Add check for '#if defined' as well as #ifdef
* Add check for IS_ENABLED() around bools in #if statements.
* Fix an incomplete comment.

Change-Id: I0787eab80ae64f59664fb53f395389bf5ac2a067
Signed-off-by: Martin Roth <martinroth@google.com>
Reviewed-on: https://review.coreboot.org/20360
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Reviewed-by: Werner Zeh <werner.zeh@siemens.com>
This commit is contained in:
Martin Roth 2017-06-25 20:27:36 -06:00
parent 48f96739ed
commit 5b88301073
1 changed files with 33 additions and 2 deletions

View File

@ -193,7 +193,16 @@ sub check_for_ifdef {
#look for #ifdef SYMBOL #look for #ifdef SYMBOL
while ( my $line = shift @ifdef_symbols ) { while ( my $line = shift @ifdef_symbols ) {
if ( $line =~ /^([^:]+):(\d+):\s*#\s*ifn?def\s+CONFIG_(\w+)/ ) { if ( $line =~ /^([^:]+):(\d+):\s*#\s*ifn?def\s*\(?\s*CONFIG_(\w+)/ ) {
my $file = $1;
my $lineno = $2;
my $symbol = $3;
if ( ( exists $symbols{$symbol} ) && ( $symbols{$symbol}{type} ne "string" ) ) {
show_warning( "#ifdef 'CONFIG_$symbol' used at $file:$lineno."
. " Symbols of type '$symbols{$symbol}{type}' are always defined." );
}
} elsif ( $line =~ /^([^:]+):(\d+):\s*#\s*if\s+!?\s*defined\s*\(?\s*CONFIG_(\w+)/ ) {
my $file = $1; my $file = $1;
my $lineno = $2; my $lineno = $2;
my $symbol = $3; my $symbol = $3;
@ -320,7 +329,7 @@ sub check_is_enabled {
my $symbol = $2; my $symbol = $2;
$line = $1 . $3; $line = $1 . $3;
#make sure that #make sure that the type is bool
if ( exists $symbols{$symbol} ) { if ( exists $symbols{$symbol} ) {
if ( $symbols{$symbol}{type} ne "bool" ) { if ( $symbols{$symbol}{type} ne "bool" ) {
show_error( "IS_ENABLED(CONFIG_$symbol) used at $file:$lineno." show_error( "IS_ENABLED(CONFIG_$symbol) used at $file:$lineno."
@ -331,6 +340,28 @@ sub check_is_enabled {
show_error("IS_ENABLED() used on unknown value CONFIG_$symbol at $file:$lineno."); show_error("IS_ENABLED() used on unknown value CONFIG_$symbol at $file:$lineno.");
} }
} }
} elsif ( $line =~ /^([^:]+):(\d+):\s*#\s*(?:el)?if\s+!?\s*\(?\s*CONFIG_(\w+)\)?(\s*==\s*1)?.*?$/ ) {
my $file = $1;
my $lineno = $2;
my $symbol = $3;
# If the type is bool, give a warning that IS_ENABLED should be used
if ( exists $symbols{$symbol} ) {
if ( $symbols{$symbol}{type} eq "bool" ) {
show_error( "#if CONFIG_$symbol used at $file:$lineno."
. " IS_ENABLED should be used for type 'bool'" );
}
}
} elsif ( $line =~ /^([^:]+):(\d+):\s*#\s*(?:el)?if.*(?:&&|\|\|)\s+!?\s*\(?\s*CONFIG_(\w+)\)?(\s*==\s*1)?$/ ) {
my $file = $1;
my $lineno = $2;
my $symbol = $3;
# If the type is bool, give a warning that IS_ENABLED should be used
if ( exists $symbols{$symbol} ) {
if ( $symbols{$symbol}{type} eq "bool" ) {
show_error( "#if CONFIG_$symbol used at $file:$lineno."
. " IS_ENABLED should be used for type 'bool'" );
}
}
} }
} }
} }