kconfig_lint: make sure if and endif statements are balanced
In Kconfig files, the 'if' and 'endif' statements need to match up. A file can't start an if statement that's completed in the next file. Add a check as the files are being parsed to make sure that they match up correctly. Change-Id: If51207ea037089ab84c768e5a868270468cf4c4f Signed-off-by: Martin Roth <martinroth@google.com> Reviewed-on: https://review.coreboot.org/13876 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
This commit is contained in:
parent
b97009ed43
commit
0e6c0e18e3
|
@ -447,6 +447,7 @@ sub build_and_parse_kconfig_tree {
|
||||||
my @inside_menu = (); # stack of menu names
|
my @inside_menu = (); # stack of menu names
|
||||||
my $inside_choice = "";
|
my $inside_choice = "";
|
||||||
my $configs_inside_choice;
|
my $configs_inside_choice;
|
||||||
|
my %fileinfo;
|
||||||
|
|
||||||
#start the tree off by loading the top level kconfig
|
#start the tree off by loading the top level kconfig
|
||||||
@config_to_parse = load_kconfig_file( $top_level_kconfig, "", 0, 0, "", 0 );
|
@config_to_parse = load_kconfig_file( $top_level_kconfig, "", 0, 0, "", 0 );
|
||||||
|
@ -601,12 +602,14 @@ sub build_and_parse_kconfig_tree {
|
||||||
my $expr = $1;
|
my $expr = $1;
|
||||||
push( @inside_if, $expr );
|
push( @inside_if, $expr );
|
||||||
handle_expressions( $expr, $inside_config, $filename, $line_no );
|
handle_expressions( $expr, $inside_config, $filename, $line_no );
|
||||||
|
$fileinfo{$filename}{iflevel}++;
|
||||||
}
|
}
|
||||||
|
|
||||||
# endif
|
# endif
|
||||||
elsif ( $line =~ /^\s*endif/ ) {
|
elsif ( $line =~ /^\s*endif/ ) {
|
||||||
$inside_config = "";
|
$inside_config = "";
|
||||||
pop(@inside_if);
|
pop(@inside_if);
|
||||||
|
$fileinfo{$filename}{iflevel}--;
|
||||||
}
|
}
|
||||||
|
|
||||||
#range <symbol> <symbol> [if <expr>]
|
#range <symbol> <symbol> [if <expr>]
|
||||||
|
@ -665,6 +668,16 @@ sub build_and_parse_kconfig_tree {
|
||||||
}
|
}
|
||||||
push @wholeconfig, @parseline;
|
push @wholeconfig, @parseline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach my $file ( keys %fileinfo ) {
|
||||||
|
if ( $fileinfo{$file}{iflevel} > 0 ) {
|
||||||
|
show_error("$file has $fileinfo{$file}{iflevel} more 'if' statement(s) than 'endif' statements.");
|
||||||
|
}
|
||||||
|
elsif ( $fileinfo{$file}{iflevel} < 0 ) {
|
||||||
|
show_error(
|
||||||
|
"$file has " . ( $fileinfo{$file}{iflevel} * -1 ) . " more 'endif' statement(s) than 'if' statements." );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue