| 1 |
#!/usr/bin/env perl |
| 2 |
# |
| 3 |
# SPDX-License-Identifier: GPL-2.0-only |
| 4 |
|
| 5 |
# perltidy -l=123 |
| 6 |
|
| 7 |
package kconfig_lint; |
| 8 |
|
| 9 |
use strict; |
| 10 |
use warnings; |
| 11 |
use English qw( -no_match_vars ); |
| 12 |
use File::Find; |
| 13 |
use Getopt::Long; |
| 14 |
use Getopt::Std; |
| 15 |
|
| 16 |
# If taint mode is enabled, Untaint the path - git and grep must be in /bin, /usr/bin or /usr/local/bin |
| 17 |
if ( ${^TAINT} ) { |
| 18 |
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin'; |
| 19 |
delete @ENV{ 'IFS', 'CDPATH', 'ENV', 'BASH_ENV' }; |
| 20 |
} |
| 21 |
|
| 22 |
my $suppress_error_output = 0; # flag to prevent error text |
| 23 |
my $suppress_warning_output = 0; # flag to prevent warning text |
| 24 |
my $show_note_output = 0; # flag to show minor notes text |
| 25 |
my $print_full_output = 0; # flag to print wholeconfig output |
| 26 |
my $output_file = "-"; # filename of output - set stdout by default |
| 27 |
my $dont_use_git_grep = 0; |
| 28 |
my $include_site_local = 0; |
| 29 |
|
| 30 |
# Globals |
| 31 |
my $top_dir = "."; # Directory where Kconfig is run |
| 32 |
my $root_dir = "src"; # Directory of the top level Kconfig file |
| 33 |
my $errors_found = 0; # count of errors |
| 34 |
my $warnings_found = 0; |
| 35 |
my $exclude_dirs_and_files = |
| 36 |
'^build/\|^coreboot-builds/\|^configs/\|^util/\|^\.git/\|^payloads\|^Documentation\|^3rdparty\|^src/vendorcode/amd/opensil/genoa_poc/opensil' |
| 37 |
. '\|' . # directories to exclude when searching for used symbols |
| 38 |
'\.config\|\.txt$\|\.tex$\|\.tags\|/kconfig.h\|\.fmd'; #files to exclude when looking for symbols |
| 39 |
my $payload_files_to_check='payloads/Makefile.mk payloads/external/Makefile.mk'; |
| 40 |
my $config_file = ""; # name of config file to load symbol values from. |
| 41 |
my @wholeconfig; # document the entire kconfig structure |
| 42 |
my %loaded_files; # list of each Kconfig file loaded |
| 43 |
my %symbols; # main structure of all symbols declared |
| 44 |
my %referenced_symbols; # list of symbols referenced by expressions or select statements |
| 45 |
my %used_symbols; # structure of symbols used in the tree, and where they're found |
| 46 |
my @collected_symbols; # |
| 47 |
my %selected_symbols; # list of symbols that are enabled by a select statement |
| 48 |
|
| 49 |
my $exclude_unused = '_SPECIFIC_OPTIONS'; |
| 50 |
|
| 51 |
Main(); |
| 52 |
|
| 53 |
#------------------------------------------------------------------------------- |
| 54 |
# Main |
| 55 |
# |
| 56 |
# Start by loading and parsing the top level Kconfig, this pulls in the other |
| 57 |
# files. Parsing the tree creates several arrays and hashes that can be used |
| 58 |
# to check for errors |
| 59 |
#------------------------------------------------------------------------------- |
| 60 |
sub Main { |
| 61 |
|
| 62 |
check_arguments(); |
| 63 |
if ( !($dont_use_git_grep || `git rev-parse --is-inside-work-tree`) ) { |
| 64 |
$dont_use_git_grep = 1; |
| 65 |
print STDERR "\nGit grep unavailable, falling back to regular grep...\n"; |
| 66 |
} |
| 67 |
if ( !$include_site_local) { |
| 68 |
$exclude_dirs_and_files = "^site-local\|" . $exclude_dirs_and_files; |
| 69 |
} |
| 70 |
|
| 71 |
open( STDOUT, "> $output_file" ) or die "Can't open $output_file for output: $!\n"; |
| 72 |
|
| 73 |
if ( defined $top_dir ) { |
| 74 |
chdir $top_dir or die "Error: can't cd to $top_dir\n"; |
| 75 |
} |
| 76 |
|
| 77 |
die "Error: $top_dir/$root_dir does not exist.\n" unless ( -d $root_dir ); |
| 78 |
|
| 79 |
#load the Kconfig tree, checking what we can and building up all the hash tables |
| 80 |
build_and_parse_kconfig_tree("$root_dir/Kconfig"); |
| 81 |
|
| 82 |
load_config($config_file) if ($config_file); |
| 83 |
|
| 84 |
check_type(); |
| 85 |
check_defaults(); |
| 86 |
check_referenced_symbols(); |
| 87 |
|
| 88 |
collect_used_symbols(); |
| 89 |
check_used_symbols(); |
| 90 |
check_for_ifdef(); |
| 91 |
check_for_def(); |
| 92 |
check_config_macro(); |
| 93 |
check_selected_symbols(); |
| 94 |
|
| 95 |
# Run checks based on the data that was found |
| 96 |
if ( ( !$suppress_warning_output ) && ( ${^TAINT} == 0 ) ) { |
| 97 |
|
| 98 |
# The find function is tainted - only run it if taint checking |
| 99 |
# is disabled and warnings are enabled. |
| 100 |
find( \&check_if_file_referenced, $root_dir ); |
| 101 |
} |
| 102 |
|
| 103 |
print_wholeconfig(); |
| 104 |
|
| 105 |
if ($errors_found) { |
| 106 |
print "# $errors_found errors"; |
| 107 |
if ($warnings_found) { |
| 108 |
print ", $warnings_found warnings"; |
| 109 |
} |
| 110 |
print "\n"; |
| 111 |
} |
| 112 |
|
| 113 |
exit( $errors_found + $warnings_found ); |
| 114 |
} |
| 115 |
|
| 116 |
#------------------------------------------------------------------------------- |
| 117 |
# Print and count errors |
| 118 |
#------------------------------------------------------------------------------- |
| 119 |
sub show_error { |
| 120 |
my ($error_msg) = @_; |
| 121 |
unless ($suppress_error_output) { |
| 122 |
print "#!!!!! Error: $error_msg\n"; |
| 123 |
$errors_found++; |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
#------------------------------------------------------------------------------- |
| 128 |
# Print and count warnings |
| 129 |
#------------------------------------------------------------------------------- |
| 130 |
sub show_warning { |
| 131 |
my ($warning_msg) = @_; |
| 132 |
unless ($suppress_warning_output) { |
| 133 |
print "#!!!!! Warning: $warning_msg\n"; |
| 134 |
$warnings_found++; |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
#------------------------------------------------------------------------------- |
| 139 |
# check selected symbols for validity |
| 140 |
# they must be bools |
| 141 |
# they cannot select symbols created in 'choice' blocks |
| 142 |
#------------------------------------------------------------------------------- |
| 143 |
sub check_selected_symbols { |
| 144 |
|
| 145 |
#loop through symbols found in expressions and used by 'select' keywords |
| 146 |
foreach my $symbol ( sort ( keys %selected_symbols ) ) { |
| 147 |
my $type_failure = 0; |
| 148 |
my $choice_failure = 0; |
| 149 |
|
| 150 |
#errors selecting symbols that don't exist are already printed, so we |
| 151 |
#don't need to print them again here |
| 152 |
|
| 153 |
#make sure the selected symbols are bools |
| 154 |
if ( ( exists $symbols{$symbol} ) && ( $symbols{$symbol}{type} ne "bool" ) ) { |
| 155 |
$type_failure = 1; |
| 156 |
} |
| 157 |
|
| 158 |
#make sure we're not selecting choice symbols |
| 159 |
if ( ( exists $symbols{$symbol} ) && ( $symbols{$symbol}{choice} ) ) { |
| 160 |
$choice_failure = 1; |
| 161 |
} |
| 162 |
|
| 163 |
#loop through each instance of the symbol to print out all of the failures |
| 164 |
for ( my $i = 0 ; $i <= $referenced_symbols{$symbol}{count} ; $i++ ) { |
| 165 |
next if ( !exists $selected_symbols{$symbol}{$i} ); |
| 166 |
my $file = $referenced_symbols{$symbol}{$i}{filename}; |
| 167 |
my $lineno = $referenced_symbols{$symbol}{$i}{line_no}; |
| 168 |
if ($type_failure) { |
| 169 |
show_error( |
| 170 |
"CONFIG_$symbol' selected at $file:$lineno." . " Selects only work on symbols of type bool." ); |
| 171 |
} |
| 172 |
if ($choice_failure) { |
| 173 |
show_error( |
| 174 |
"'CONFIG_$symbol' selected at $file:$lineno." . " Symbols created in a choice cannot be selected." ); |
| 175 |
} |
| 176 |
} |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
#------------------------------------------------------------------------------- |
| 181 |
# check_for_ifdef - Look for instances of #ifdef CONFIG_[symbol_name] and |
| 182 |
# #if defined(CONFIG_[symbol_name]). |
| 183 |
# |
| 184 |
# #ifdef symbol is valid for strings, but bool, hex, and INT are always defined. |
| 185 |
# #if defined(symbol) && symbol is also a valid construct. |
| 186 |
#------------------------------------------------------------------------------- |
| 187 |
sub check_for_ifdef { |
| 188 |
my @ifdef_symbols = @collected_symbols; |
| 189 |
|
| 190 |
#look for #ifdef SYMBOL |
| 191 |
while ( my $line = shift @ifdef_symbols ) { |
| 192 |
if ( $line =~ /^([^:]+):(\d+):\s*#\s*ifn?def\s*\(?\s*CONFIG(?:_|\()(\w+)/ ) { |
| 193 |
my $file = $1; |
| 194 |
my $lineno = $2; |
| 195 |
my $symbol = $3; |
| 196 |
|
| 197 |
if ( ( exists $symbols{$symbol} ) && ( $symbols{$symbol}{type} ne "string" ) ) { |
| 198 |
show_error( "#ifdef 'CONFIG_$symbol' used at $file:$lineno." |
| 199 |
. " Symbols of type '$symbols{$symbol}{type}' are always defined." ); |
| 200 |
} |
| 201 |
} elsif ( $line =~ /^([^:]+):(\d+):.+defined\s*\(?\s*CONFIG(?:_|\()(\w+)/ ) { |
| 202 |
my $file = $1; |
| 203 |
my $lineno = $2; |
| 204 |
my $symbol = $3; |
| 205 |
|
| 206 |
if ( ( exists $symbols{$symbol} ) && ( $symbols{$symbol}{type} ne "string" ) ) { |
| 207 |
show_error( "defined(CONFIG_$symbol) used at $file:$lineno." |
| 208 |
. " Symbols of type '$symbols{$symbol}{type}' are always defined." ); |
| 209 |
} |
| 210 |
} |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
#------------------------------------------------------------------------------- |
| 215 |
# check_for_def - Look for instances of #define CONFIG_[symbol_name] |
| 216 |
# |
| 217 |
# Symbols should not be redefined outside of Kconfig, and #defines should not |
| 218 |
# look like symbols |
| 219 |
#------------------------------------------------------------------------------- |
| 220 |
sub check_for_def { |
| 221 |
my @def_symbols = @collected_symbols; |
| 222 |
|
| 223 |
#look for #ifdef SYMBOL |
| 224 |
while ( my $line = shift @def_symbols ) { |
| 225 |
if ( $line =~ /^([^:]+):(\d+):\s*#\s*define\s+CONFIG_(\w+)/ ) { |
| 226 |
my $file = $1; |
| 227 |
my $lineno = $2; |
| 228 |
my $symbol = $3; |
| 229 |
|
| 230 |
if ( ( exists $symbols{$symbol} ) ) { |
| 231 |
show_error("#define of symbol 'CONFIG_$symbol' used at $file:$lineno."); |
| 232 |
} |
| 233 |
else { |
| 234 |
show_error( "#define 'CONFIG_$symbol' used at $file:$lineno." |
| 235 |
. " Other #defines should not look like Kconfig symbols." ); |
| 236 |
} |
| 237 |
} |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
#------------------------------------------------------------------------------- |
| 242 |
# check_type - Make sure that all symbols have a type defined. |
| 243 |
# |
| 244 |
# Conflicting types are found when parsing the Kconfig tree. |
| 245 |
#------------------------------------------------------------------------------- |
| 246 |
sub check_type { |
| 247 |
|
| 248 |
# loop through each defined symbol |
| 249 |
foreach my $sym ( sort ( keys %symbols ) ) { |
| 250 |
|
| 251 |
# Make sure there's a type set for the symbol |
| 252 |
if (!defined $symbols{$sym}{type}) { |
| 253 |
|
| 254 |
#loop through each instance of that symbol |
| 255 |
for ( my $sym_num = 0 ; $sym_num <= $symbols{$sym}{count} ; $sym_num++ ) { |
| 256 |
|
| 257 |
my $filename = $symbols{$sym}{$sym_num}{file}; |
| 258 |
my $line_no = $symbols{$sym}{$sym_num}{line_no}; |
| 259 |
|
| 260 |
show_error("No type defined for symbol $sym defined at $filename:$line_no."); |
| 261 |
} |
| 262 |
} |
| 263 |
} |
| 264 |
} |
| 265 |
|
| 266 |
#------------------------------------------------------------------------------- |
| 267 |
# check_config_macro - The CONFIG() macro is only valid for symbols of type |
| 268 |
# bool. It would probably work on type hex or int if the value was 0 or 1, |
| 269 |
# but this seems like a bad plan. Using it on strings is dead out. |
| 270 |
# |
| 271 |
# The IS_ENABLED() macro is forbidden in coreboot now. Though, as long as |
| 272 |
# we keep its definition in libpayload for compatibility, we have to check |
| 273 |
# that it doesn't sneak back in. |
| 274 |
#------------------------------------------------------------------------------- |
| 275 |
sub check_config_macro { |
| 276 |
my @is_enabled_symbols = @collected_symbols; |
| 277 |
|
| 278 |
#sort through symbols found by grep and store them in a hash for easy access |
| 279 |
while ( my $line = shift @is_enabled_symbols ) { |
| 280 |
if ( $line =~ /^([^:]+):(\d+):(.+\bCONFIG\(.*)/ ) { |
| 281 |
my $file = $1; |
| 282 |
my $lineno = $2; |
| 283 |
$line = $3; |
| 284 |
while ( $line =~ /(.*)\bCONFIG\(([^)]*)\)(.*)/ ) { |
| 285 |
my $symbol = $2; |
| 286 |
$line = $1 . $3; |
| 287 |
|
| 288 |
#make sure that the type is bool |
| 289 |
if ( exists $symbols{$symbol} ) { |
| 290 |
if ( $symbols{$symbol}{type} ne "bool" ) { |
| 291 |
show_error( "CONFIG($symbol) used at $file:$lineno." |
| 292 |
. " CONFIG() is only valid for type 'bool', not '$symbols{$symbol}{type}'." ); |
| 293 |
} |
| 294 |
} elsif ($symbol =~ /\S+##\S+/ ) { |
| 295 |
show_warning( "C preprocessor macro CONFIG_$symbol found at $file:$lineno." ); |
| 296 |
} else { |
| 297 |
show_error("CONFIG() used on unknown value ($symbol) at $file:$lineno."); |
| 298 |
} |
| 299 |
} |
| 300 |
} elsif ( $line =~ /^([^:]+):(\d+):(.+IS_ENABLED.*)/ ) { |
| 301 |
my $file = $1; |
| 302 |
my $lineno = $2; |
| 303 |
$line = $3; |
| 304 |
if ( ( $line !~ /(.*)IS_ENABLED\s*\(\s*CONFIG_(\w+)(.*)/ ) && ( $line !~ /(\/[\*\/])(.*)IS_ENABLED/ ) ) { |
| 305 |
show_error("# uninterpreted IS_ENABLED at $file:$lineno: $line"); |
| 306 |
next; |
| 307 |
} |
| 308 |
while ( $line =~ /(.*)IS_ENABLED\s*\(\s*CONFIG_(\w+)(.*)/ ) { |
| 309 |
my $symbol = $2; |
| 310 |
$line = $1 . $3; |
| 311 |
show_error("IS_ENABLED(CONFIG_$symbol) at $file:$lineno is deprecated. Use CONFIG($symbol) instead."); |
| 312 |
} |
| 313 |
} elsif ( $line =~ /^([^:]+):(\d+):\s*#\s*(?:el)?if\s+!?\s*\(?\s*CONFIG_(\w+)\)?(\s*==\s*1)?.*?$/ ) { |
| 314 |
my $file = $1; |
| 315 |
my $lineno = $2; |
| 316 |
my $symbol = $3; |
| 317 |
# If the type is bool, give a warning that CONFIG() should be used |
| 318 |
if ( exists $symbols{$symbol} ) { |
| 319 |
if ( $symbols{$symbol}{type} eq "bool" ) { |
| 320 |
show_error( "#if CONFIG_$symbol used at $file:$lineno." |
| 321 |
. " CONFIG($symbol) should be used for type 'bool'" ); |
| 322 |
} |
| 323 |
} |
| 324 |
} elsif ( $line =~ /^([^:]+):(\d+):\s*#\s*(?:el)?if.*(?:&&|\|\|)\s+!?\s*\(?\s*CONFIG_(\w+)\)?(\s*==\s*1)?$/ ) { |
| 325 |
my $file = $1; |
| 326 |
my $lineno = $2; |
| 327 |
my $symbol = $3; |
| 328 |
# If the type is bool, give a warning that CONFIG() should be used |
| 329 |
if ( exists $symbols{$symbol} ) { |
| 330 |
if ( $symbols{$symbol}{type} eq "bool" ) { |
| 331 |
show_error( "#if CONFIG_$symbol used at $file:$lineno." |
| 332 |
. " CONFIG($symbol) should be used for type 'bool'" ); |
| 333 |
} |
| 334 |
} |
| 335 |
} elsif ( $line =~ /^([^:]+):(\d+):(.+\bCONFIG_.+)/ ) { |
| 336 |
my $file = $1; |
| 337 |
my $lineno = $2; |
| 338 |
$line = $3; |
| 339 |
if ( $file =~ /.*\.(c|h|asl|ld)/ ) { |
| 340 |
while ( $line =~ /(.*)\bCONFIG_(\w+)(.*)/ && $1 !~ /\/\/|\/\*/ ) { |
| 341 |
my $symbol = $2; |
| 342 |
$line = $1 . $3; |
| 343 |
if ( exists $symbols{$symbol} ) { |
| 344 |
if ( $symbols{$symbol}{type} eq "bool" ) { |
| 345 |
show_error( "Naked reference to CONFIG_$symbol used at $file:$lineno." |
| 346 |
. " A 'bool' Kconfig should always be accessed through CONFIG($symbol)." ); |
| 347 |
} |
| 348 |
} else { |
| 349 |
show_warning( "Unknown config option CONFIG_$symbol used at $file:$lineno." ); |
| 350 |
} |
| 351 |
} |
| 352 |
} |
| 353 |
} |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
#------------------------------------------------------------------------------- |
| 358 |
# check_defaults - Look for defaults that come after a default with no |
| 359 |
# dependencies. |
| 360 |
# |
| 361 |
# TODO - check for defaults with the same dependencies |
| 362 |
#------------------------------------------------------------------------------- |
| 363 |
sub check_defaults { |
| 364 |
|
| 365 |
# loop through each defined symbol |
| 366 |
foreach my $sym ( sort ( keys %symbols ) ) { |
| 367 |
my $default_set = 0; |
| 368 |
my $default_filename = ""; |
| 369 |
my $default_line_no = ""; |
| 370 |
|
| 371 |
#loop through each instance of that symbol |
| 372 |
for ( my $sym_num = 0 ; $sym_num <= $symbols{$sym}{count} ; $sym_num++ ) { |
| 373 |
|
| 374 |
#loop through any defaults for that instance of that symbol, if there are any |
| 375 |
next unless ( exists $symbols{$sym}{$sym_num}{default_max} ); |
| 376 |
for ( my $def_num = 0 ; $def_num <= $symbols{$sym}{$sym_num}{default_max} ; $def_num++ ) { |
| 377 |
|
| 378 |
my $filename = $symbols{$sym}{$sym_num}{file}; |
| 379 |
my $line_no = $symbols{$sym}{$sym_num}{default}{$def_num}{default_line_no}; |
| 380 |
|
| 381 |
# Make sure there's a type set for the symbol |
| 382 |
next if (!defined $symbols{$sym}{type}); |
| 383 |
|
| 384 |
# Symbols created/used inside a choice must not have a default set. The default is set by the choice itself. |
| 385 |
if ($symbols{$sym}{choice}) { |
| 386 |
show_error("Defining a default for symbol '$sym' at $filename:$line_no, used inside choice at " |
| 387 |
. "$symbols{$sym}{choice}, is not allowed."); |
| 388 |
} |
| 389 |
|
| 390 |
# skip good defaults |
| 391 |
if (! ((($symbols{$sym}{type} eq "hex") && ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /^0x/)) || |
| 392 |
(($symbols{$sym}{type} eq "int") && ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /^[-0-9]+$/)) || |
| 393 |
(($symbols{$sym}{type} eq "string") && ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /^".*"$/)) || |
| 394 |
(($symbols{$sym}{type} eq "bool") && ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /^[yn]$/))) |
| 395 |
) { |
| 396 |
|
| 397 |
my ($checksym) = $symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /(\w+)/; |
| 398 |
|
| 399 |
if (! exists $symbols{$checksym}) { |
| 400 |
|
| 401 |
# verify the symbol type against the default value |
| 402 |
if ($symbols{$sym}{type} eq "hex") { |
| 403 |
show_error("non hex default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) used for hex symbol $sym at $filename:$line_no."); |
| 404 |
} elsif ($symbols{$sym}{type} eq "int") { |
| 405 |
show_error("non int default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) used for int symbol $sym at $filename:$line_no."); |
| 406 |
} elsif ($symbols{$sym}{type} eq "string") { |
| 407 |
# TODO: Remove special MAINBOARD_DIR check |
| 408 |
if ($sym ne "MAINBOARD_DIR") { |
| 409 |
show_error("no quotes around default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) used for string symbol $sym at $filename:$line_no."); |
| 410 |
} |
| 411 |
} elsif ($symbols{$sym}{type} eq "bool") { |
| 412 |
if ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /[01YN]/) { |
| 413 |
show_error("default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) for bool symbol $sym uses value other than y/n at $filename:$line_no."); |
| 414 |
} else { |
| 415 |
show_error("non bool default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) used for bool symbol $sym at $filename:$line_no."); |
| 416 |
} |
| 417 |
} |
| 418 |
} |
| 419 |
} |
| 420 |
|
| 421 |
#if a default is already set, display an error |
| 422 |
if ($default_set) { |
| 423 |
show_error( "Default for '$sym' referenced at $filename:$line_no will never be set" |
| 424 |
. " - overridden by default set at $default_filename:$default_line_no" ); |
| 425 |
} |
| 426 |
else { |
| 427 |
#if no default is set, see if this is a default with no dependencies |
| 428 |
unless ( ( exists $symbols{$sym}{$sym_num}{default}{$def_num}{default_depends_on} ) |
| 429 |
|| ( exists $symbols{$sym}{$sym_num}{max_dependency} ) ) |
| 430 |
{ |
| 431 |
$default_set = 1; |
| 432 |
$default_filename = $symbols{$sym}{$sym_num}{file}; |
| 433 |
$default_line_no = $symbols{$sym}{$sym_num}{default}{$def_num}{default_line_no}; |
| 434 |
} |
| 435 |
} |
| 436 |
} |
| 437 |
} |
| 438 |
} |
| 439 |
} |
| 440 |
|
| 441 |
#------------------------------------------------------------------------------- |
| 442 |
# check_referenced_symbols - Make sure the symbols referenced by expressions and |
| 443 |
# select statements are actually valid symbols. |
| 444 |
#------------------------------------------------------------------------------- |
| 445 |
sub check_referenced_symbols { |
| 446 |
|
| 447 |
#loop through symbols found in expressions and used by 'select' keywords |
| 448 |
foreach my $key ( sort ( keys %referenced_symbols ) ) { |
| 449 |
|
| 450 |
#make sure the symbol was defined by a 'config' or 'choice' keyword |
| 451 |
next if ( exists $symbols{$key} ); |
| 452 |
|
| 453 |
#loop through each instance of the symbol to print out all of the invalid references |
| 454 |
for ( my $i = 0 ; $i <= $referenced_symbols{$key}{count} ; $i++ ) { |
| 455 |
my $filename = $referenced_symbols{$key}{$i}{filename}; |
| 456 |
my $line_no = $referenced_symbols{$key}{$i}{line_no}; |
| 457 |
show_error("Undefined Symbol '$key' used at $filename:$line_no."); |
| 458 |
} |
| 459 |
} |
| 460 |
} |
| 461 |
|
| 462 |
#------------------------------------------------------------------------------- |
| 463 |
#------------------------------------------------------------------------------- |
| 464 |
sub collect_used_symbols { |
| 465 |
# find all references to CONFIG_ statements in the tree |
| 466 |
|
| 467 |
if ($dont_use_git_grep) { |
| 468 |
@collected_symbols = `grep -Irn -- "CONFIG\\(_\\|(\\)" | grep -v '$exclude_dirs_and_files'; grep -In -- "CONFIG\\(_\\|(\\)" $payload_files_to_check`; |
| 469 |
} |
| 470 |
else { |
| 471 |
@collected_symbols = `git grep -In -- "CONFIG\\(_\\|(\\)" | grep -v '$exclude_dirs_and_files'; git grep -In -- "CONFIG\\(_\\|(\\)" $payload_files_to_check`; |
| 472 |
} |
| 473 |
|
| 474 |
my @used_symbols = @collected_symbols; |
| 475 |
|
| 476 |
#sort through symbols found by grep and store them in a hash for easy access |
| 477 |
while ( my $line = shift @used_symbols ) { |
| 478 |
while ( $line =~ /[^A-Za-z0-9_]CONFIG(?:_|\()([A-Za-z0-9_]+)/g ) { |
| 479 |
my $symbol = $1; |
| 480 |
my $filename = ""; |
| 481 |
if ( $line =~ /^([^:]+):/ ) { |
| 482 |
$filename = $1; |
| 483 |
} |
| 484 |
|
| 485 |
if ( exists $used_symbols{$symbol}{count} ) { |
| 486 |
$used_symbols{$symbol}{count}++; |
| 487 |
} |
| 488 |
else { |
| 489 |
$used_symbols{$symbol}{count} = 0; |
| 490 |
} |
| 491 |
$used_symbols{$symbol}{"num_$used_symbols{$symbol}{count}"} = $filename; |
| 492 |
} |
| 493 |
} |
| 494 |
} |
| 495 |
|
| 496 |
#------------------------------------------------------------------------------- |
| 497 |
# check_used_symbols - Checks to see whether or not the created symbols are |
| 498 |
# actually used. |
| 499 |
#------------------------------------------------------------------------------- |
| 500 |
sub check_used_symbols { |
| 501 |
# loop through all defined symbols and see if they're used anywhere |
| 502 |
foreach my $key ( sort ( keys %symbols ) ) { |
| 503 |
|
| 504 |
if ( $key =~ /$exclude_unused/ ) { |
| 505 |
next; |
| 506 |
} |
| 507 |
|
| 508 |
#see if they're used internal to Kconfig |
| 509 |
next if ( exists $referenced_symbols{$key} ); |
| 510 |
|
| 511 |
#see if they're used externally |
| 512 |
next if exists $used_symbols{$key}; |
| 513 |
|
| 514 |
#loop through the definitions to print out all the places the symbol is defined. |
| 515 |
for ( my $i = 0 ; $i <= $symbols{$key}{count} ; $i++ ) { |
| 516 |
my $filename = $symbols{$key}{$i}{file}; |
| 517 |
my $line_no = $symbols{$key}{$i}{line_no}; |
| 518 |
show_warning("Unused symbol '$key' referenced at $filename:$line_no."); |
| 519 |
} |
| 520 |
} |
| 521 |
} |
| 522 |
|
| 523 |
#------------------------------------------------------------------------------- |
| 524 |
# build_and_parse_kconfig_tree |
| 525 |
#------------------------------------------------------------------------------- |
| 526 |
#load the initial file and start parsing it |
| 527 |
sub build_and_parse_kconfig_tree { |
| 528 |
my ($top_level_kconfig) = @_; |
| 529 |
my @config_to_parse; |
| 530 |
my @parseline; |
| 531 |
my $inside_help = 0; # set to line number of 'help' keyword if this line is inside a help block |
| 532 |
my @inside_if = (); # stack of if dependencies |
| 533 |
my $inside_config = ""; # set to symbol name of the config section |
| 534 |
my @inside_menu = (); # stack of menu names |
| 535 |
my $inside_choice = ""; |
| 536 |
my $choice_symbol = ""; |
| 537 |
my $configs_inside_choice; |
| 538 |
my %fileinfo; |
| 539 |
|
| 540 |
#start the tree off by loading the top level kconfig |
| 541 |
@config_to_parse = load_kconfig_file( $top_level_kconfig, "", 0, 0, "", 0 ); |
| 542 |
|
| 543 |
while ( ( @parseline = shift(@config_to_parse) ) && ( exists $parseline[0]{text} ) ) { |
| 544 |
my $line = $parseline[0]{text}; |
| 545 |
my $filename = $parseline[0]{filename}; |
| 546 |
my $line_no = $parseline[0]{file_line_no}; |
| 547 |
|
| 548 |
#handle help - help text: "help" or "---help---" |
| 549 |
my $lastline_was_help = $inside_help; |
| 550 |
$inside_help = handle_help( $line, $inside_help, $inside_config, $inside_choice, $filename, $line_no ); |
| 551 |
$parseline[0]{inside_help} = $inside_help; |
| 552 |
|
| 553 |
#look for basic issues in the line, strip crlf |
| 554 |
$line = simple_line_checks( $line, $filename, $line_no ); |
| 555 |
|
| 556 |
#strip comments |
| 557 |
$line =~ s/\s*#.*$//; |
| 558 |
|
| 559 |
#don't parse any more if we're inside a help block |
| 560 |
if ($inside_help) { |
| 561 |
#do nothing |
| 562 |
} |
| 563 |
|
| 564 |
#handle config |
| 565 |
elsif ( $line =~ /^\s*config\s+/ ) { |
| 566 |
$line =~ /^\s*config\s+([^"\s]+)\s*(?>#.*)?$/; |
| 567 |
my $symbol = $1; |
| 568 |
$inside_config = $symbol; |
| 569 |
if ($inside_choice) { |
| 570 |
$configs_inside_choice++; |
| 571 |
} |
| 572 |
add_symbol( $symbol, \@inside_menu, $filename, $line_no, \@inside_if, $inside_choice ); |
| 573 |
} |
| 574 |
|
| 575 |
#bool|hex|int|string|tristate <expr> [if <expr>] |
| 576 |
elsif ( $line =~ /^\s*(bool|string|hex|int|tristate)/ ) { |
| 577 |
$line =~ /^\s*(bool|string|hex|int|tristate)\s*(.*)/; |
| 578 |
my ( $type, $prompt ) = ( $1, $2 ); |
| 579 |
handle_type( $type, $inside_config, $filename, $line_no ); |
| 580 |
handle_prompt( $prompt, $type, \@inside_menu, $inside_config, $inside_choice, $filename, $line_no ); |
| 581 |
} |
| 582 |
|
| 583 |
# def_bool|def_tristate <expr> [if <expr>] |
| 584 |
elsif ( $line =~ /^\s*(def_bool|def_tristate)/ ) { |
| 585 |
$line =~ /^\s*(def_bool|def_tristate)\s+(.*)/; |
| 586 |
my ( $orgtype, $default ) = ( $1, $2 ); |
| 587 |
( my $type = $orgtype ) =~ s/def_//; |
| 588 |
handle_type( $type, $inside_config, $filename, $line_no ); |
| 589 |
handle_default( $default, $orgtype, $inside_config, $inside_choice, $filename, $line_no ); |
| 590 |
} |
| 591 |
|
| 592 |
#prompt <prompt> [if <expr>] |
| 593 |
elsif ( $line =~ /^\s*prompt/ ) { |
| 594 |
$line =~ /^\s*prompt\s+(.+)/; |
| 595 |
handle_prompt( $1, "prompt", \@inside_menu, $inside_config, $inside_choice, $filename, $line_no ); |
| 596 |
} |
| 597 |
|
| 598 |
# default <expr> [if <expr>] |
| 599 |
elsif ( $line =~ /^\s*default/ ) { |
| 600 |
$line =~ /^\s*default\s+(.*)/; |
| 601 |
my $default = $1; |
| 602 |
handle_default( $default, "default", $inside_config, $inside_choice, $filename, $line_no ); |
| 603 |
} |
| 604 |
|
| 605 |
# depends on <expr> |
| 606 |
elsif ( $line =~ /^\s*depends\s+on/ ) { |
| 607 |
$line =~ /^\s*depends\s+on\s+(.*)$/; |
| 608 |
my $expr = $1; |
| 609 |
handle_depends( $expr, $inside_config, $inside_choice, $filename, $line_no ); |
| 610 |
handle_expressions( $expr, $inside_config, $filename, $line_no ); |
| 611 |
} |
| 612 |
|
| 613 |
# comment <prompt> |
| 614 |
elsif ( $line =~ /^\s*comment/ ) { |
| 615 |
$inside_config = ""; |
| 616 |
} |
| 617 |
|
| 618 |
# choice [symbol] |
| 619 |
elsif ( $line =~ /^\s*choice/ ) { |
| 620 |
if ( $line =~ /^\s*choice\s*([A-Za-z0-9_]+)$/ ) { |
| 621 |
my $symbol = $1; |
| 622 |
add_symbol( $symbol, \@inside_menu, $filename, $line_no, \@inside_if ); |
| 623 |
handle_type( "bool", $symbol, $filename, $line_no ); |
| 624 |
$choice_symbol = $symbol; |
| 625 |
} |
| 626 |
$inside_config = ""; |
| 627 |
$inside_choice = "$filename:$line_no"; |
| 628 |
$configs_inside_choice = 0; |
| 629 |
|
| 630 |
# Kconfig verifies that choice blocks have a prompt |
| 631 |
} |
| 632 |
|
| 633 |
# endchoice |
| 634 |
elsif ( $line =~ /^\s*endchoice/ ) { |
| 635 |
$inside_config = ""; |
| 636 |
if ( !$inside_choice ) { |
| 637 |
show_error("'endchoice' keyword not within a choice block at $filename:$line_no."); |
| 638 |
} |
| 639 |
|
| 640 |
$inside_choice = ""; |
| 641 |
if (( $configs_inside_choice == 0 ) && |
| 642 |
( $choice_symbol eq "" )) { |
| 643 |
show_error("unnamed choice block has no symbols at $filename:$line_no."); |
| 644 |
} |
| 645 |
$configs_inside_choice = 0; |
| 646 |
$choice_symbol=""; |
| 647 |
} |
| 648 |
|
| 649 |
# [optional] |
| 650 |
elsif ( $line =~ /^\s*optional/ ) { |
| 651 |
if ($inside_config) { |
| 652 |
show_error( "Keyword 'optional' appears inside config for '$inside_config'" |
| 653 |
. " at $filename:$line_no. This is not valid." ); |
| 654 |
} |
| 655 |
if ( !$inside_choice ) { |
| 656 |
show_error( "Keyword 'optional' appears outside of a choice block" |
| 657 |
. " at $filename:$line_no. This is not valid." ); |
| 658 |
} |
| 659 |
} |
| 660 |
|
| 661 |
# mainmenu <prompt> |
| 662 |
elsif ( $line =~ /^\s*mainmenu/ ) { |
| 663 |
$inside_config = ""; |
| 664 |
|
| 665 |
# Kconfig alread checks for multiple 'mainmenu' entries and mainmenu entries with no prompt |
| 666 |
# Possible check: look for 'mainmenu ""' |
| 667 |
# Possible check: verify that a mainmenu has been specified |
| 668 |
} |
| 669 |
|
| 670 |
# menu <prompt> |
| 671 |
elsif ( $line =~ /^\s*menu/ ) { |
| 672 |
$line =~ /^\s*menu\s+(.*)/; |
| 673 |
my $menu = $1; |
| 674 |
if ( $menu =~ /^\s*"([^"]*)"\s*$/ ) { |
| 675 |
$menu = $1; |
| 676 |
} |
| 677 |
|
| 678 |
$inside_config = ""; |
| 679 |
$inside_choice = ""; |
| 680 |
push( @inside_menu, $menu ); |
| 681 |
} |
| 682 |
|
| 683 |
# visible if <expr> |
| 684 |
elsif ( $line =~ /^\s*visible if.*$/ ) { |
| 685 |
# Must come directly after menu line (and on a separate line) |
| 686 |
# but kconfig already checks for that. |
| 687 |
# Ignore it. |
| 688 |
} |
| 689 |
|
| 690 |
# endmenu |
| 691 |
elsif ( $line =~ /^\s*endmenu/ ) { |
| 692 |
$inside_config = ""; |
| 693 |
$inside_choice = ""; |
| 694 |
pop @inside_menu; |
| 695 |
} |
| 696 |
|
| 697 |
# "if" <expr> |
| 698 |
elsif ( $line =~ /^\s*if/ ) { |
| 699 |
$inside_config = ""; |
| 700 |
$line =~ /^\s*if\s+(.*)$/; |
| 701 |
my $expr = $1; |
| 702 |
push( @inside_if, $expr ); |
| 703 |
handle_expressions( $expr, $inside_config, $filename, $line_no ); |
| 704 |
$fileinfo{$filename}{iflevel}++; |
| 705 |
} |
| 706 |
|
| 707 |
# endif |
| 708 |
elsif ( $line =~ /^\s*endif/ ) { |
| 709 |
$inside_config = ""; |
| 710 |
pop(@inside_if); |
| 711 |
$fileinfo{$filename}{iflevel}--; |
| 712 |
} |
| 713 |
|
| 714 |
#range <symbol> <symbol> [if <expr>] |
| 715 |
elsif ( $line =~ /^\s*range/ ) { |
| 716 |
$line =~ /^\s*range\s+(\S+)\s+(.*)$/; |
| 717 |
handle_range( $1, $2, $inside_config, $filename, $line_no ); |
| 718 |
} |
| 719 |
|
| 720 |
# select <symbol> [if <expr>] |
| 721 |
elsif ( $line =~ /^\s*select/ ) { |
| 722 |
unless ($inside_config) { |
| 723 |
show_error("Keyword 'select' appears outside of config at $filename:$line_no. This is not valid."); |
| 724 |
} |
| 725 |
|
| 726 |
if ( $line =~ /^\s*select\s+(.*)$/ ) { |
| 727 |
$line = $1; |
| 728 |
my $expression; |
| 729 |
( $line, $expression ) = handle_if_line( $line, $inside_config, $filename, $line_no ); |
| 730 |
if ($line) { |
| 731 |
add_referenced_symbol( $line, $filename, $line_no, 'select' ); |
| 732 |
} |
| 733 |
} |
| 734 |
} |
| 735 |
|
| 736 |
# source <prompt> |
| 737 |
elsif ( $line =~ /^\s*source\s+"?([^"\s]+)"?\s*(?>#.*)?$/ ) { |
| 738 |
my $input_file = $1; |
| 739 |
$parseline[0]{text} = "# '$line'\n"; |
| 740 |
if ( $line !~ "site-local" || $include_site_local ) { |
| 741 |
my @newfile = load_kconfig_file( $input_file, $filename, $line_no, 0, $filename, $line_no ); |
| 742 |
unshift( @config_to_parse, @newfile ); |
| 743 |
} |
| 744 |
} |
| 745 |
elsif ( |
| 746 |
( $line =~ /^\s*#/ ) || #comments |
| 747 |
( $line =~ /^\s*$/ ) #blank lines |
| 748 |
) |
| 749 |
{ |
| 750 |
# do nothing |
| 751 |
} |
| 752 |
else { |
| 753 |
if ($lastline_was_help) { |
| 754 |
show_error("The line \"$line\" ($filename:$line_no) wasn't recognized - supposed to be inside help?"); |
| 755 |
} |
| 756 |
else { |
| 757 |
show_error("The line \"$line\" ($filename:$line_no) wasn't recognized"); |
| 758 |
} |
| 759 |
} |
| 760 |
|
| 761 |
if ( defined $inside_menu[0] ) { |
| 762 |
$parseline[0]{menus} = ""; |
| 763 |
} |
| 764 |
else { |
| 765 |
$parseline[0]{menus} = "top"; |
| 766 |
} |
| 767 |
|
| 768 |
my $i = 0; |
| 769 |
while ( defined $inside_menu[$i] ) { |
| 770 |
$parseline[0]{menus} .= "$inside_menu[$i]"; |
| 771 |
$i++; |
| 772 |
if ( defined $inside_menu[$i] ) { |
| 773 |
$parseline[0]{menus} .= "->"; |
| 774 |
} |
| 775 |
} |
| 776 |
push @wholeconfig, @parseline; |
| 777 |
} |
| 778 |
|
| 779 |
foreach my $file ( keys %fileinfo ) { |
| 780 |
if ( $fileinfo{$file}{iflevel} > 0 ) { |
| 781 |
show_error("$file has $fileinfo{$file}{iflevel} more 'if' statement(s) than 'endif' statements."); |
| 782 |
} |
| 783 |
elsif ( $fileinfo{$file}{iflevel} < 0 ) { |
| 784 |
show_error( |
| 785 |
"$file has " . ( $fileinfo{$file}{iflevel} * -1 ) . " more 'endif' statement(s) than 'if' statements." ); |
| 786 |
} |
| 787 |
} |
| 788 |
} |
| 789 |
|
| 790 |
#------------------------------------------------------------------------------- |
| 791 |
#------------------------------------------------------------------------------- |
| 792 |
sub handle_depends { |
| 793 |
my ( $expr, $inside_config, $inside_choice, $filename, $line_no ) = @_; |
| 794 |
|
| 795 |
if ($inside_config) { |
| 796 |
my $sym_num = $symbols{$inside_config}{count}; |
| 797 |
if ( exists $symbols{$inside_config}{$sym_num}{max_dependency} ) { |
| 798 |
$symbols{$inside_config}{$sym_num}{max_dependency}++; |
| 799 |
} |
| 800 |
else { |
| 801 |
$symbols{$inside_config}{$sym_num}{max_dependency} = 0; |
| 802 |
} |
| 803 |
|
| 804 |
my $dep_num = $symbols{$inside_config}{$sym_num}{max_dependency}; |
| 805 |
$symbols{$inside_config}{$sym_num}{dependency}{$dep_num} = $expr; |
| 806 |
} |
| 807 |
} |
| 808 |
|
| 809 |
#------------------------------------------------------------------------------- |
| 810 |
#------------------------------------------------------------------------------- |
| 811 |
sub add_symbol { |
| 812 |
my ( $symbol, $menu_array_ref, $filename, $line_no, $ifref, $inside_choice ) = @_; |
| 813 |
my @inside_if = @{$ifref}; |
| 814 |
|
| 815 |
#initialize the symbol or increment the use count. |
| 816 |
if ( ( !exists $symbols{$symbol} ) || ( !exists $symbols{$symbol}{count} ) ) { |
| 817 |
$symbols{$symbol}{count} = 0; |
| 818 |
# remember the location of the choice (or "") |
| 819 |
$symbols{$symbol}{choice} = $inside_choice; |
| 820 |
} |
| 821 |
else { |
| 822 |
$symbols{$symbol}{count}++; |
| 823 |
if ( $inside_choice && $symbols{$symbol}{choice} ) { |
| 824 |
show_error( "$symbol entry at $filename:$line_no has already been created inside another choice block " |
| 825 |
. "at $symbols{$symbol}{0}{file}:$symbols{$symbol}{0}{line_no}." ); |
| 826 |
} |
| 827 |
} |
| 828 |
|
| 829 |
# add the location of this instance |
| 830 |
my $symcount = $symbols{$symbol}{count}; |
| 831 |
$symbols{$symbol}{$symcount}{file} = $filename; |
| 832 |
$symbols{$symbol}{$symcount}{line_no} = $line_no; |
| 833 |
|
| 834 |
#Add the menu structure |
| 835 |
if ( defined @$menu_array_ref[0] ) { |
| 836 |
$symbols{$symbol}{$symcount}{menu} = $menu_array_ref; |
| 837 |
} |
| 838 |
|
| 839 |
#Add any 'if' statements that the symbol is inside as dependencies |
| 840 |
if (@inside_if) { |
| 841 |
my $dep_num = 0; |
| 842 |
for my $dependency (@inside_if) { |
| 843 |
$symbols{$symbol}{$symcount}{dependency}{$dep_num} = $dependency; |
| 844 |
$symbols{$symbol}{$symcount}{max_dependency} = $dep_num; |
| 845 |
$dep_num++; |
| 846 |
} |
| 847 |
} |
| 848 |
} |
| 849 |
|
| 850 |
#------------------------------------------------------------------------------- |
| 851 |
# handle range |
| 852 |
#------------------------------------------------------------------------------- |
| 853 |
sub handle_range { |
| 854 |
my ( $range1, $range2, $inside_config, $filename, $line_no ) = @_; |
| 855 |
|
| 856 |
my $expression; |
| 857 |
( $range2, $expression ) = handle_if_line( $range2, $inside_config, $filename, $line_no ); |
| 858 |
|
| 859 |
# Use bigint for large hexadecimal values |
| 860 |
use bigint; |
| 861 |
$range1 =~ /^\s*(?:0x)?([A-Fa-f0-9]+)\s*$/; |
| 862 |
my $checkrange1 = Math::BigInt->new($1); |
| 863 |
$range2 =~ /^\s*(?:0x)?([A-Fa-f0-9]+)\s*$/; |
| 864 |
my $checkrange2 = Math::BigInt->new($1); |
| 865 |
|
| 866 |
if ( $checkrange1 && $checkrange2 && ( $checkrange1 > $checkrange2 ) ) { |
| 867 |
show_error("Range entry in $filename line $line_no value 1 ($range1) is greater than value 2 ($range2)."); |
| 868 |
} |
| 869 |
|
| 870 |
if ($inside_config) { |
| 871 |
if ( exists( $symbols{$inside_config}{range1} ) ) { |
| 872 |
# Convert existing range values to BigInt objects |
| 873 |
$symbols{$inside_config}{range1} = Math::BigInt->new($symbols{$inside_config}{range1}); |
| 874 |
$symbols{$inside_config}{range2} = Math::BigInt->new($symbols{$inside_config}{range2}); |
| 875 |
|
| 876 |
if ( ( $symbols{$inside_config}{range1} != $checkrange1 ) || ( $symbols{$inside_config}{range2} != $checkrange2 ) ) { |
| 877 |
if ($show_note_output) { |
| 878 |
print "#!!!!! Note: Config '$inside_config' range entry $range1 $range2 at $filename:$line_no does"; |
| 879 |
print " not match the previously defined range $symbols{$inside_config}{range1}" |
| 880 |
. " $symbols{$inside_config}{range2}"; |
| 881 |
print " defined at $symbols{$inside_config}{range_file}:$symbols{$inside_config}{range_line_no}.\n"; |
| 882 |
} |
| 883 |
} |
| 884 |
} |
| 885 |
else { |
| 886 |
$symbols{$inside_config}{range1} = $checkrange1; |
| 887 |
$symbols{$inside_config}{range2} = $checkrange2; |
| 888 |
$symbols{$inside_config}{range_file} = $filename; |
| 889 |
$symbols{$inside_config}{range_line_no} = $line_no; |
| 890 |
} |
| 891 |
} |
| 892 |
else { |
| 893 |
show_error("Range entry at $filename:$line_no is not inside a config block."); |
| 894 |
} |
| 895 |
} |
| 896 |
|
| 897 |
#------------------------------------------------------------------------------- |
| 898 |
# handle_default |
| 899 |
#------------------------------------------------------------------------------- |
| 900 |
sub handle_default { |
| 901 |
my ( $default, $name, $inside_config, $inside_choice, $filename, $line_no ) = @_; |
| 902 |
my $expression; |
| 903 |
( $default, $expression ) = handle_if_line( $default, $inside_config, $filename, $line_no ); |
| 904 |
|
| 905 |
if ($inside_config) { |
| 906 |
handle_expressions( $default, $inside_config, $filename, $line_no ); |
| 907 |
my $sym_num = $symbols{$inside_config}{count}; |
| 908 |
|
| 909 |
unless ( exists $symbols{$inside_config}{$sym_num}{default_max} ) { |
| 910 |
$symbols{$inside_config}{$sym_num}{default_max} = 0; |
| 911 |
} |
| 912 |
my $default_max = $symbols{$inside_config}{$sym_num}{default_max}; |
| 913 |
$symbols{$inside_config}{$sym_num}{default}{$default_max}{default} = $default; |
| 914 |
$symbols{$inside_config}{$sym_num}{default}{$default_max}{default_line_no} = $line_no; |
| 915 |
if ($expression) { |
| 916 |
$symbols{$inside_config}{$sym_num}{default}{$default_max}{default_depends_on} = $expression; |
| 917 |
} |
| 918 |
} |
| 919 |
elsif ($inside_choice) { |
| 920 |
handle_expressions( $default, $inside_config, $filename, $line_no ); |
| 921 |
} |
| 922 |
else { |
| 923 |
show_error("$name entry at $filename:$line_no is not inside a config or choice block."); |
| 924 |
} |
| 925 |
} |
| 926 |
|
| 927 |
#------------------------------------------------------------------------------- |
| 928 |
# handle_if_line |
| 929 |
#------------------------------------------------------------------------------- |
| 930 |
sub handle_if_line { |
| 931 |
my ( $exprline, $inside_config, $filename, $line_no ) = @_; |
| 932 |
|
| 933 |
if ( $exprline !~ /if/ ) { |
| 934 |
return ( $exprline, "" ); |
| 935 |
} |
| 936 |
|
| 937 |
#remove any quotes that might have an 'if' in them |
| 938 |
my $savequote; |
| 939 |
if ( $exprline =~ /^\s*("[^"]+")/ ) { |
| 940 |
$savequote = $1; |
| 941 |
$exprline =~ s/^\s*("[^"]+")//; |
| 942 |
} |
| 943 |
|
| 944 |
my $expr = ""; |
| 945 |
if ( $exprline =~ /\s*if\s+(.*)$/ ) { |
| 946 |
$expr = $1; |
| 947 |
$exprline =~ s/\s*if\s+.*$//; |
| 948 |
|
| 949 |
if ($expr) { |
| 950 |
handle_expressions( $expr, $inside_config, $filename, $line_no ); |
| 951 |
} |
| 952 |
} |
| 953 |
|
| 954 |
if ($savequote) { |
| 955 |
$exprline = $savequote; |
| 956 |
} |
| 957 |
|
| 958 |
return ( $exprline, $expr ); |
| 959 |
} |
| 960 |
|
| 961 |
#------------------------------------------------------------------------------- |
| 962 |
# handle_symbol - log which symbols are being used |
| 963 |
#------------------------------------------------------------------------------- |
| 964 |
sub handle_symbol { |
| 965 |
my ( $symbol, $filename, $line_no ) = @_; |
| 966 |
|
| 967 |
#filter constant symbols first |
| 968 |
if ( $symbol =~ /^[yn]$/ ) { # constant y/n |
| 969 |
return; |
| 970 |
} |
| 971 |
if ( $symbol =~ /^-?(?:0x)?\p{XDigit}+$/ ) { # int/hex values |
| 972 |
return; |
| 973 |
} |
| 974 |
if ( $symbol =~ /^"[^"]*"$/ ) { # string values |
| 975 |
return; |
| 976 |
} |
| 977 |
|
| 978 |
if ( $symbol =~ /^([A-Za-z0-9_]+)$/ ) { # actual symbol |
| 979 |
add_referenced_symbol( $1, $filename, $line_no, 'expression' ); |
| 980 |
} |
| 981 |
else { |
| 982 |
show_error("Unrecognized expression: expected symbol, " |
| 983 |
. "found '$symbol' in $filename line $line_no."); |
| 984 |
} |
| 985 |
} |
| 986 |
|
| 987 |
#------------------------------------------------------------------------------- |
| 988 |
# handle_expressions - find symbols in expressions |
| 989 |
#------------------------------------------------------------------------------- |
| 990 |
sub handle_expressions { |
| 991 |
my ( $exprline, $inside_config, $filename, $line_no ) = @_; |
| 992 |
|
| 993 |
my $strip = qr/\s*(.*[^\s]+)\s*/; |
| 994 |
|
| 995 |
my $parens = qr/(\((?:[^\(\)]++|(?-1))*\))/; |
| 996 |
my $quotes = qr/"[^"]*"/; |
| 997 |
my $balanced = qr/((?:$parens|$quotes|[^\(\)"])+)/; |
| 998 |
|
| 999 |
if ( $exprline =~ /^\s*$balanced\s*(?:\|\||&&)\s*(.+)$/ ) { |
| 1000 |
# <expr> '||' <expr>, <expr> '&&' <expr> (8)(7) |
| 1001 |
my ( $lhs, $rhs ) = ( $1, $3 ); |
| 1002 |
handle_expressions( $lhs, $inside_config, $filename, $line_no ); |
| 1003 |
handle_expressions( $rhs, $inside_config, $filename, $line_no ); |
| 1004 |
} |
| 1005 |
elsif ( $exprline =~ /^\s*!(.+)$/ ) { |
| 1006 |
# '!' <expr> (6) |
| 1007 |
handle_expressions( $1, $inside_config, $filename, $line_no ); |
| 1008 |
} |
| 1009 |
elsif ( $exprline =~ /^\s*$parens\s*$/ ) { |
| 1010 |
# '(' <expr> ')' (5) |
| 1011 |
$exprline =~ /^\s*\((.*)\)\s*$/; |
| 1012 |
handle_expressions( $1, $inside_config, $filename, $line_no ); |
| 1013 |
} |
| 1014 |
elsif ( $exprline =~ /^\s*($quotes|[^"\s]+)\s*(?:[<>]=?|!=)$strip$/ ) { |
| 1015 |
# <symbol> '<' <symbol>, <symbol> '!=' <symbol>, etc. (4)(3) |
| 1016 |
my ( $lhs, $rhs ) = ( $1, $2 ); |
| 1017 |
handle_symbol( $lhs, $filename, $line_no ); |
| 1018 |
handle_symbol( $rhs, $filename, $line_no ); |
| 1019 |
} |
| 1020 |
elsif ( $exprline =~ /^\s*($quotes|[^"\s]+)\s*=$strip$/ ) { |
| 1021 |
# <symbol> '=' <symbol> (2) |
| 1022 |
my ( $lhs, $rhs ) = ( $1, $2 ); |
| 1023 |
handle_symbol( $lhs, $filename, $line_no ); |
| 1024 |
handle_symbol( $rhs, $filename, $line_no ); |
| 1025 |
} |
| 1026 |
elsif ( $exprline =~ /^$strip$/ ) { |
| 1027 |
# <symbol> (1) |
| 1028 |
handle_symbol( $1, $filename, $line_no ); |
| 1029 |
} |
| 1030 |
} |
| 1031 |
|
| 1032 |
#------------------------------------------------------------------------------- |
| 1033 |
# add_referenced_symbol |
| 1034 |
#------------------------------------------------------------------------------- |
| 1035 |
sub add_referenced_symbol { |
| 1036 |
my ( $symbol, $filename, $line_no, $reftype ) = @_; |
| 1037 |
if ( exists $referenced_symbols{$symbol} ) { |
| 1038 |
$referenced_symbols{$symbol}{count}++; |
| 1039 |
$referenced_symbols{$symbol}{ $referenced_symbols{$symbol}{count} }{filename} = $filename; |
| 1040 |
$referenced_symbols{$symbol}{ $referenced_symbols{$symbol}{count} }{line_no} = $line_no; |
| 1041 |
} |
| 1042 |
else { |
| 1043 |
$referenced_symbols{$symbol}{count} = 0; |
| 1044 |
$referenced_symbols{$symbol}{0}{filename} = $filename; |
| 1045 |
$referenced_symbols{$symbol}{0}{line_no} = $line_no; |
| 1046 |
} |
| 1047 |
|
| 1048 |
#mark the symbol as being selected, use referenced symbols for location |
| 1049 |
if ( $reftype eq 'select' ) { |
| 1050 |
$selected_symbols{$symbol}{ $referenced_symbols{$symbol}{count} } = 1; |
| 1051 |
} |
| 1052 |
} |
| 1053 |
|
| 1054 |
#------------------------------------------------------------------------------- |
| 1055 |
# handle_help |
| 1056 |
#------------------------------------------------------------------------------- |
| 1057 |
{ |
| 1058 |
#create a non-global static variable by enclosing it and the subroutine |
| 1059 |
my $help_whitespace = ""; #string to show length of the help whitespace |
| 1060 |
my $help_keyword_whitespace = ""; |
| 1061 |
|
| 1062 |
sub handle_help { |
| 1063 |
my ( $line, $inside_help, $inside_config, $inside_choice, $filename, $line_no ) = @_; |
| 1064 |
|
| 1065 |
if ($inside_help) { |
| 1066 |
|
| 1067 |
#get the indentation level if it's not already set. |
| 1068 |
if ( ( !$help_whitespace ) && ( $line !~ /^[\r\n]+/ ) ) { |
| 1069 |
$line =~ /^(\s+)/; #find the indentation level. |
| 1070 |
$help_whitespace = $1; |
| 1071 |
if ( !$help_whitespace ) { |
| 1072 |
show_error("$filename:$line_no - help text starts with no whitespace."); |
| 1073 |
return $inside_help; |
| 1074 |
} |
| 1075 |
elsif ($help_keyword_whitespace eq $help_whitespace) { |
| 1076 |
show_error("$filename:$line_no - help text needs additional indentation."); |
| 1077 |
return $inside_help; |
| 1078 |
} |
| 1079 |
} |
| 1080 |
|
| 1081 |
#help ends at the first line which has a smaller indentation than the first line of the help text. |
| 1082 |
if ( ( $line !~ /^$help_whitespace/ ) && ( $line !~ /^[\r\n]+/ ) ) { |
| 1083 |
$inside_help = 0; |
| 1084 |
$help_whitespace = ""; |
| 1085 |
$help_keyword_whitespace = ""; |
| 1086 |
} |
| 1087 |
else { #if it's not ended, add the line to the helptext array for the symbol's instance |
| 1088 |
if ($inside_config) { |
| 1089 |
my $sym_num = $symbols{$inside_config}{count}; |
| 1090 |
if ($help_whitespace) { $line =~ s/^$help_whitespace//; } |
| 1091 |
push( @{ $symbols{$inside_config}{$sym_num}{helptext} }, $line ); |
| 1092 |
} |
| 1093 |
if ( ($help_keyword_whitespace eq $help_whitespace) && ( $line !~ /^[\r\n]+/ ) ) { |
| 1094 |
show_error("$filename:$line_no - help text needs additional indentation."); |
| 1095 |
} |
| 1096 |
} |
| 1097 |
} |
| 1098 |
elsif ( ( $line =~ /^(\s*)help/ ) || ( $line =~ /^(\s*)---help---/ ) ) { |
| 1099 |
$inside_help = $line_no; |
| 1100 |
$line =~ /^(\s+)/; |
| 1101 |
$help_keyword_whitespace = $1; |
| 1102 |
if ( ( !$inside_config ) && ( !$inside_choice ) ) { |
| 1103 |
if ($show_note_output) { |
| 1104 |
print "# Note: $filename:$line_no help is not inside a config or choice block.\n"; |
| 1105 |
} |
| 1106 |
} |
| 1107 |
elsif ($inside_config) { |
| 1108 |
$help_whitespace = ""; |
| 1109 |
my $sym_num = $symbols{$inside_config}{count}; |
| 1110 |
$symbols{$inside_config}{$sym_num}{help_line_no} = $line_no; |
| 1111 |
$symbols{$inside_config}{$sym_num}{helptext} = (); |
| 1112 |
} |
| 1113 |
} |
| 1114 |
return $inside_help; |
| 1115 |
} |
| 1116 |
} |
| 1117 |
|
| 1118 |
#------------------------------------------------------------------------------- |
| 1119 |
# handle_type |
| 1120 |
#------------------------------------------------------------------------------- |
| 1121 |
sub handle_type { |
| 1122 |
my ( $type, $inside_config, $filename, $line_no ) = @_; |
| 1123 |
|
| 1124 |
my $expression; |
| 1125 |
( $type, $expression ) = handle_if_line( $type, $inside_config, $filename, $line_no ); |
| 1126 |
|
| 1127 |
if ( $type =~ /tristate/ ) { |
| 1128 |
show_error("$filename:$line_no - tristate types are not used."); |
| 1129 |
} |
| 1130 |
|
| 1131 |
if ($inside_config) { |
| 1132 |
if ( exists( $symbols{$inside_config}{type} ) ) { |
| 1133 |
if ( $symbols{$inside_config}{type} !~ /$type/ ) { |
| 1134 |
show_error( "Config '$inside_config' type entry $type" |
| 1135 |
. " at $filename:$line_no does not match $symbols{$inside_config}{type}" |
| 1136 |
. " defined at $symbols{$inside_config}{type_file}:$symbols{$inside_config}{type_line_no}." ); |
| 1137 |
} |
| 1138 |
} |
| 1139 |
else { |
| 1140 |
$symbols{$inside_config}{type} = $type; |
| 1141 |
$symbols{$inside_config}{type_file} = $filename; |
| 1142 |
$symbols{$inside_config}{type_line_no} = $line_no; |
| 1143 |
} |
| 1144 |
} |
| 1145 |
else { |
| 1146 |
show_error("Type entry at $filename:$line_no is not inside a config block."); |
| 1147 |
} |
| 1148 |
} |
| 1149 |
|
| 1150 |
#------------------------------------------------------------------------------- |
| 1151 |
# handle_prompt |
| 1152 |
#------------------------------------------------------------------------------- |
| 1153 |
sub handle_prompt { |
| 1154 |
my ( $prompt, $name, $menu_array_ref, $inside_config, $inside_choice, $filename, $line_no ) = @_; |
| 1155 |
|
| 1156 |
my $expression; |
| 1157 |
( $prompt, $expression ) = handle_if_line( $prompt, $inside_config, $filename, $line_no ); |
| 1158 |
|
| 1159 |
if ($inside_config) { |
| 1160 |
if ( $prompt !~ /^\s*$/ ) { |
| 1161 |
if ( $prompt =~ /^\s*"([^"]*)"\s*$/ ) { |
| 1162 |
$prompt = $1; |
| 1163 |
} |
| 1164 |
|
| 1165 |
#display an error if there's a prompt at the top menu level |
| 1166 |
if ( !defined @$menu_array_ref[0] ) { |
| 1167 |
show_error( "Symbol '$inside_config' with prompt '$prompt' appears outside of a menu" |
| 1168 |
. " at $filename:$line_no." ); |
| 1169 |
} |
| 1170 |
|
| 1171 |
my $sym_num = $symbols{$inside_config}{count}; |
| 1172 |
if ( !exists $symbols{$inside_config}{$sym_num}{prompt_max} ) { |
| 1173 |
$symbols{$inside_config}{$sym_num}{prompt_max} = 0; |
| 1174 |
} |
| 1175 |
else { |
| 1176 |
$symbols{$inside_config}{$sym_num}{prompt_max}++; |
| 1177 |
} |
| 1178 |
my $prompt_max = $symbols{$inside_config}{$sym_num}{prompt_max}; |
| 1179 |
$symbols{$inside_config}{$sym_num}{prompt}{$prompt_max}{prompt} = $prompt; |
| 1180 |
$symbols{$inside_config}{$sym_num}{prompt}{$prompt_max}{prompt_line_no} = $line_no; |
| 1181 |
|
| 1182 |
$symbols{$inside_config}{$sym_num}{prompt}{$prompt_max}{prompt_menu} = @$menu_array_ref; |
| 1183 |
if ($expression) { |
| 1184 |
$symbols{$inside_config}{$sym_num}{prompt}{$prompt_max}{prompt_depends_on} = $expression; |
| 1185 |
} |
| 1186 |
} |
| 1187 |
} |
| 1188 |
elsif ($inside_choice) { |
| 1189 |
|
| 1190 |
#do nothing |
| 1191 |
} |
| 1192 |
else { |
| 1193 |
show_error("$name entry at $filename:$line_no is not inside a config or choice block."); |
| 1194 |
} |
| 1195 |
} |
| 1196 |
|
| 1197 |
#------------------------------------------------------------------------------- |
| 1198 |
# simple_line_checks - Does some basic checks on the current line, then cleans the line |
| 1199 |
# up for further processing. |
| 1200 |
#------------------------------------------------------------------------------- |
| 1201 |
sub simple_line_checks { |
| 1202 |
my ( $line, $filename, $line_no ) = @_; |
| 1203 |
|
| 1204 |
#check for spaces instead of tabs |
| 1205 |
if ( $line =~ /^ +/ ) { |
| 1206 |
show_error("$filename:$line_no starts with a space."); |
| 1207 |
} |
| 1208 |
|
| 1209 |
#verify a linefeed at the end of the line |
| 1210 |
if ( $line !~ /.*\n/ ) { |
| 1211 |
show_error( "$filename:$line_no does not end with linefeed." |
| 1212 |
. " This can cause the line to not be recognized by the Kconfig parser.\n#($line)" ); |
| 1213 |
$line =~ s/\s*$//; |
| 1214 |
} |
| 1215 |
else { |
| 1216 |
chop($line); |
| 1217 |
} |
| 1218 |
|
| 1219 |
return $line; |
| 1220 |
} |
| 1221 |
|
| 1222 |
#------------------------------------------------------------------------------- |
| 1223 |
# load_kconfig_file - Loads a single Kconfig file or expands * wildcard |
| 1224 |
#------------------------------------------------------------------------------- |
| 1225 |
sub load_kconfig_file { |
| 1226 |
my ( $input_file, $loadfile, $loadline, $expanded, $topfile, $topline ) = @_; |
| 1227 |
my @file_data; |
| 1228 |
my @dir_file_data; |
| 1229 |
|
| 1230 |
#recursively handle coreboot's new source glob operator |
| 1231 |
if ( $input_file =~ /^(.*?)\/(\w*)\*(\w*)\/(.*)$/ ) { |
| 1232 |
my $dir_prefix = $1; |
| 1233 |
my $dir_glob_prefix = $2; |
| 1234 |
my $dir_glob_suffix = $3; |
| 1235 |
my $dir_suffix = $4; |
| 1236 |
if ( -d "$dir_prefix" ) { |
| 1237 |
|
| 1238 |
opendir( D, "$dir_prefix" ) || die "Can't open directory '$dir_prefix'\n"; |
| 1239 |
my @dirlist = sort { $a cmp $b } readdir(D); |
| 1240 |
closedir(D); |
| 1241 |
|
| 1242 |
while ( my $directory = shift @dirlist ) { |
| 1243 |
|
| 1244 |
#ignore non-directory files |
| 1245 |
if ( ( -d "$dir_prefix/$directory" ) && !( $directory =~ /^\..*/ ) |
| 1246 |
&& ( $directory =~ /\Q$dir_glob_prefix\E.*\Q$dir_glob_suffix\E/ ) ) { |
| 1247 |
push @dir_file_data, |
| 1248 |
load_kconfig_file( "$dir_prefix/$directory/$dir_suffix", |
| 1249 |
$input_file, $loadline, 1, $loadfile, $loadline ); |
| 1250 |
} |
| 1251 |
} |
| 1252 |
} |
| 1253 |
|
| 1254 |
#the directory should exist when using a glob |
| 1255 |
else { |
| 1256 |
show_error("Could not find dir '$dir_prefix'"); |
| 1257 |
} |
| 1258 |
} |
| 1259 |
|
| 1260 |
#if the file exists, try to load it. |
| 1261 |
elsif ( -e "$input_file" ) { |
| 1262 |
|
| 1263 |
#throw a warning if the file has already been loaded. |
| 1264 |
if ( exists $loaded_files{$input_file} ) { |
| 1265 |
show_warning("'$input_file' sourced at $loadfile:$loadline was already loaded by $loaded_files{$input_file}"); |
| 1266 |
} |
| 1267 |
|
| 1268 |
#load the file's contents and mark the file as loaded for checking later |
| 1269 |
open( my $HANDLE, "<", "$input_file" ) or die "Error: could not open file '$input_file'\n"; |
| 1270 |
@file_data = <$HANDLE>; |
| 1271 |
close $HANDLE; |
| 1272 |
$loaded_files{$input_file} = "'$loadfile' line $loadline"; |
| 1273 |
} |
| 1274 |
|
| 1275 |
# if the file isn't being loaded from a glob, it should exist. |
| 1276 |
elsif ( $expanded == 0 ) { |
| 1277 |
show_warning("Could not find file '$input_file' sourced at $loadfile:$loadline"); |
| 1278 |
} |
| 1279 |
|
| 1280 |
my $line_in_file = 0; |
| 1281 |
while ( my $line = shift @file_data ) { |
| 1282 |
|
| 1283 |
#handle line continuation. |
| 1284 |
my $continue_line = 0; |
| 1285 |
while ( $line =~ /(.*)\s+\\$/ ) { |
| 1286 |
my $text = $1; |
| 1287 |
|
| 1288 |
# get rid of leading whitespace on all but the first and last lines |
| 1289 |
$text =~ s/^\s*/ / if ($continue_line); |
| 1290 |
|
| 1291 |
$dir_file_data[$line_in_file]{text} .= $text; |
| 1292 |
$line = shift @file_data; |
| 1293 |
$continue_line++; |
| 1294 |
|
| 1295 |
#put the data into the continued lines (other than the first) |
| 1296 |
$line =~ /^\s*(.*)\s*$/; |
| 1297 |
|
| 1298 |
$dir_file_data[ $line_in_file + $continue_line ]{text} = "\t# continued line ( " . $1 . " )\n"; |
| 1299 |
$dir_file_data[ $line_in_file + $continue_line ]{filename} = $input_file; |
| 1300 |
$dir_file_data[ $line_in_file + $continue_line ]{file_line_no} = $line_in_file + $continue_line + 1; |
| 1301 |
|
| 1302 |
#get rid of multiple leading spaces for last line |
| 1303 |
$line = " $1\n"; |
| 1304 |
} |
| 1305 |
|
| 1306 |
$dir_file_data[$line_in_file]{text} .= $line; |
| 1307 |
$dir_file_data[$line_in_file]{filename} = $input_file; |
| 1308 |
$dir_file_data[$line_in_file]{file_line_no} = $line_in_file + 1; |
| 1309 |
|
| 1310 |
$line_in_file++; |
| 1311 |
if ($continue_line) { |
| 1312 |
$line_in_file += $continue_line; |
| 1313 |
} |
| 1314 |
} |
| 1315 |
|
| 1316 |
if ($topfile) { |
| 1317 |
my %file_data; |
| 1318 |
$file_data{text} = "\t### File '$input_file' loaded from '$topfile' line $topline\n"; |
| 1319 |
$file_data{filename} = $topfile; |
| 1320 |
$file_data{file_line_no} = "($topline)"; |
| 1321 |
unshift( @dir_file_data, \%file_data ); |
| 1322 |
} |
| 1323 |
|
| 1324 |
return @dir_file_data; |
| 1325 |
} |
| 1326 |
|
| 1327 |
#------------------------------------------------------------------------------- |
| 1328 |
# print_wholeconfig - prints out the parsed Kconfig file |
| 1329 |
#------------------------------------------------------------------------------- |
| 1330 |
sub print_wholeconfig { |
| 1331 |
|
| 1332 |
return unless $print_full_output; |
| 1333 |
|
| 1334 |
for ( my $i = 0 ; $i <= $#wholeconfig ; $i++ ) { |
| 1335 |
my $line = $wholeconfig[$i]; |
| 1336 |
chop( $line->{text} ); |
| 1337 |
|
| 1338 |
#replace tabs with spaces for consistency |
| 1339 |
$line->{text} =~ s/\t/ /g; |
| 1340 |
printf "%-120s # $line->{filename} line $line->{file_line_no} ($line->{menus})\n", $line->{text}; |
| 1341 |
} |
| 1342 |
} |
| 1343 |
|
| 1344 |
#------------------------------------------------------------------------------- |
| 1345 |
# check_if_file_referenced - checks for kconfig files that are not being parsed |
| 1346 |
#------------------------------------------------------------------------------- |
| 1347 |
sub check_if_file_referenced { |
| 1348 |
my $filename = $File::Find::name; |
| 1349 |
if ( ( $filename =~ /Kconfig/ ) |
| 1350 |
&& ( $filename !~ /\.orig$/ ) |
| 1351 |
&& ( $filename !~ /~$/ ) |
| 1352 |
&& ( !exists $loaded_files{$filename} ) ) |
| 1353 |
{ |
| 1354 |
show_warning("'$filename' is never referenced"); |
| 1355 |
} |
| 1356 |
} |
| 1357 |
|
| 1358 |
#------------------------------------------------------------------------------- |
| 1359 |
# check_arguments parse the command line arguments |
| 1360 |
#------------------------------------------------------------------------------- |
| 1361 |
sub check_arguments { |
| 1362 |
my $show_usage = 0; |
| 1363 |
GetOptions( |
| 1364 |
'help|?' => sub { usage() }, |
| 1365 |
'e|errors_off' => \$suppress_error_output, |
| 1366 |
'n|notes' => \$show_note_output, |
| 1367 |
'o|output=s' => \$output_file, |
| 1368 |
'p|print' => \$print_full_output, |
| 1369 |
'w|warnings_off' => \$suppress_warning_output, |
| 1370 |
'path=s' => \$top_dir, |
| 1371 |
'c|config=s' => \$config_file, |
| 1372 |
'G|no_git_grep' => \$dont_use_git_grep, |
| 1373 |
'S|site_local' => \$include_site_local, |
| 1374 |
); |
| 1375 |
|
| 1376 |
if ($suppress_error_output) { |
| 1377 |
$suppress_warning_output = 1; |
| 1378 |
} |
| 1379 |
if ($suppress_warning_output) { |
| 1380 |
$show_note_output = 0; |
| 1381 |
} |
| 1382 |
} |
| 1383 |
|
| 1384 |
#------------------------------------------------------------------------------- |
| 1385 |
# usage - Print the arguments for the user |
| 1386 |
#------------------------------------------------------------------------------- |
| 1387 |
sub usage { |
| 1388 |
print "kconfig_lint <options>\n"; |
| 1389 |
print " -o|--output=file Set output filename\n"; |
| 1390 |
print " -p|--print Print full output\n"; |
| 1391 |
print " -e|--errors_off Don't print warnings or errors\n"; |
| 1392 |
print " -w|--warnings_off Don't print warnings\n"; |
| 1393 |
print " -n|--notes Show minor notes\n"; |
| 1394 |
print " --path=dir Path to top level kconfig\n"; |
| 1395 |
print " -c|--config=file Filename of config file to load\n"; |
| 1396 |
print " -G|--no_git_grep Use standard grep tools instead of git grep\n"; |
| 1397 |
print " -S|--site_local Include the site-local directory\n"; |
| 1398 |
|
| 1399 |
exit(0); |
| 1400 |
} |
| 1401 |
|
| 1402 |
1; |