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