blob: 43a3ca684eeb1db58d8ddf9ff6837bc322d8b3d7 [file] [log] [blame]
Yegor Timoshenkoc2e49412018-10-07 01:58:27 +00001#!/usr/bin/env perl
Martin Rothbcaaad12015-10-18 11:16:25 -06002#
Patrick Georgi7333a112020-05-08 20:48:04 +02003# SPDX-License-Identifier: GPL-2.0-only
4
Martin Roth1b44f7e2016-01-11 14:31:38 -07005# perltidy -l=123
Martin Rothbcaaad12015-10-18 11:16:25 -06006
7package kconfig_lint;
8
9use strict;
10use warnings;
11use English qw( -no_match_vars );
12use File::Find;
13use Getopt::Long;
14use Getopt::Std;
15
Martin Rothabf7d4d2016-02-19 10:24:25 -070016# If taint mode is enabled, Untaint the path - git and grep must be in /bin, /usr/bin or /usr/local/bin
17if ( ${^TAINT} ) {
18 $ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
19 delete @ENV{ 'IFS', 'CDPATH', 'ENV', 'BASH_ENV' };
20}
21
Martin Roth1b44f7e2016-01-11 14:31:38 -070022my $suppress_error_output = 0; # flag to prevent error text
23my $suppress_warning_output = 0; # flag to prevent warning text
24my $show_note_output = 0; # flag to show minor notes text
25my $print_full_output = 0; # flag to print wholeconfig output
26my $output_file = "-"; # filename of output - set stdout by default
Martin Rothd8080172015-11-26 19:12:44 -070027my $dont_use_git_grep = 0;
Martin Rothbcaaad12015-10-18 11:16:25 -060028
Martin Rothabf7d4d2016-02-19 10:24:25 -070029# Globals
Martin Roth1b44f7e2016-01-11 14:31:38 -070030my $top_dir = "."; # Directory where Kconfig is run
31my $root_dir = "src"; # Directory of the top level Kconfig file
32my $errors_found = 0; # count of errors
Martin Rothd8080172015-11-26 19:12:44 -070033my $warnings_found = 0;
Martin Roth63ea4932016-01-25 16:08:27 -070034my $exclude_dirs_and_files =
Martin Rothab273d32016-11-23 17:28:00 -070035 '^build/\|^coreboot-builds/\|^configs/\|^util/\|^\.git/\|^payloads\|^Documentation\|^3rdparty'
Martin Roth63ea4932016-01-25 16:08:27 -070036 . '\|' . # directories to exclude when searching for used symbols
Julius Wernerf0286042019-04-09 15:57:07 -070037 '\.config\|\.txt$\|\.tex$\|\.tags\|/kconfig.h'; #files to exclude when looking for symbols
Martin Rothe69c58d2016-11-15 21:08:42 -070038my $payload_files_to_check='payloads/Makefile.inc payloads/external/Makefile.inc';
Martin Roth08cf90f2016-01-25 19:54:16 -070039my $config_file = ""; # name of config file to load symbol values from.
40my @wholeconfig; # document the entire kconfig structure
41my %loaded_files; # list of each Kconfig file loaded
42my %symbols; # main structure of all symbols declared
43my %referenced_symbols; # list of symbols referenced by expressions or select statements
44my %used_symbols; # structure of symbols used in the tree, and where they're found
45my @collected_symbols; #
46my %selected_symbols; # list of symbols that are enabled by a select statement
Martin Rothbcaaad12015-10-18 11:16:25 -060047
Martin Roth6bfbf1c2016-01-25 16:12:49 -070048my $exclude_unused = '_SPECIFIC_OPTIONS|SOUTH_BRIDGE_OPTIONS';
49
Martin Rothbcaaad12015-10-18 11:16:25 -060050Main();
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#-------------------------------------------------------------------------------
59sub Main {
60
61 check_arguments();
62 open( STDOUT, "> $output_file" ) or die "Can't open $output_file for output: $!\n";
63
Martin Roth1b44f7e2016-01-11 14:31:38 -070064 if ( defined $top_dir ) {
65 chdir $top_dir or die "Error: can't cd to $top_dir\n";
Martin Rothbcaaad12015-10-18 11:16:25 -060066 }
67
Martin Roth1b44f7e2016-01-11 14:31:38 -070068 die "Error: $top_dir/$root_dir does not exist.\n" unless ( -d $root_dir );
Martin Rothbcaaad12015-10-18 11:16:25 -060069
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 Rothbcaaad12015-10-18 11:16:25 -060073 load_config($config_file) if ($config_file);
74
Martin Roth08705f12016-11-09 14:27:00 -070075 check_type();
Martin Rothbcaaad12015-10-18 11:16:25 -060076 check_defaults();
77 check_referenced_symbols();
78
79 collect_used_symbols();
80 check_used_symbols();
81 check_for_ifdef();
82 check_for_def();
Nico Huberec017592019-04-06 16:09:46 +020083 check_config_macro();
Martin Rothb7c39b22016-01-14 09:04:53 -070084 check_selected_symbols();
Martin Rothbcaaad12015-10-18 11:16:25 -060085
Martin Rothabf7d4d2016-02-19 10:24:25 -070086 # 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 Rothbcaaad12015-10-18 11:16:25 -060094 print_wholeconfig();
95
Martin Rothd8080172015-11-26 19:12:44 -070096 if ($errors_found) {
97 print "# $errors_found errors";
Martin Roth1b44f7e2016-01-11 14:31:38 -070098 if ($warnings_found) {
Martin Rothd8080172015-11-26 19:12:44 -070099 print ", $warnings_found warnings";
100 }
Martin Roth1b44f7e2016-01-11 14:31:38 -0700101 print "\n";
Martin Rothd8080172015-11-26 19:12:44 -0700102 }
103
Martin Roth1b44f7e2016-01-11 14:31:38 -0700104 exit( $errors_found + $warnings_found );
Martin Rothd8080172015-11-26 19:12:44 -0700105}
106
107#-------------------------------------------------------------------------------
108# Print and count errors
109#-------------------------------------------------------------------------------
110sub 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#-------------------------------------------------------------------------------
121sub show_warning {
122 my ($warning_msg) = @_;
123 unless ($suppress_warning_output) {
124 print "#!!!!! Warning: $warning_msg\n";
125 $warnings_found++;
126 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600127}
128
129#-------------------------------------------------------------------------------
Martin Rothb7c39b22016-01-14 09:04:53 -0700130# check selected symbols for validity
131# they must be bools
132# they cannot select symbols created in 'choice' blocks
133#-------------------------------------------------------------------------------
134sub 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 Rothbcaaad12015-10-18 11:16:25 -0600172# 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#-------------------------------------------------------------------------------
178sub check_for_ifdef {
179 my @ifdef_symbols = @collected_symbols;
180
181 #look for #ifdef SYMBOL
182 while ( my $line = shift @ifdef_symbols ) {
Julius Werneref7a3262019-03-05 16:57:52 -0800183 if ( $line =~ /^([^:]+):(\d+):\s*#\s*ifn?def\s*\(?\s*CONFIG(?:_|\()(\w+)/ ) {
Martin Roth5b883012017-06-25 20:27:36 -0600184 my $file = $1;
185 my $lineno = $2;
186 my $symbol = $3;
187
188 if ( ( exists $symbols{$symbol} ) && ( $symbols{$symbol}{type} ne "string" ) ) {
Julius Wernere5eb2de2019-03-05 17:10:19 -0800189 show_error( "#ifdef 'CONFIG_$symbol' used at $file:$lineno."
Martin Roth5b883012017-06-25 20:27:36 -0600190 . " Symbols of type '$symbols{$symbol}{type}' are always defined." );
191 }
Julius Wernere5eb2de2019-03-05 17:10:19 -0800192 } elsif ( $line =~ /^([^:]+):(\d+):.+defined\s*\(?\s*CONFIG(?:_|\()(\w+)/ ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -0700193 my $file = $1;
Martin Rothbcaaad12015-10-18 11:16:25 -0600194 my $lineno = $2;
195 my $symbol = $3;
196
Martin Roth1b44f7e2016-01-11 14:31:38 -0700197 if ( ( exists $symbols{$symbol} ) && ( $symbols{$symbol}{type} ne "string" ) ) {
Julius Wernere5eb2de2019-03-05 17:10:19 -0800198 show_error( "defined(CONFIG_$symbol) used at $file:$lineno."
Martin Roth1b44f7e2016-01-11 14:31:38 -0700199 . " Symbols of type '$symbols{$symbol}{type}' are always defined." );
Martin Rothbcaaad12015-10-18 11:16:25 -0600200 }
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#-------------------------------------------------------------------------------
211sub 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 Roth1b44f7e2016-01-11 14:31:38 -0700217 my $file = $1;
Martin Rothbcaaad12015-10-18 11:16:25 -0600218 my $lineno = $2;
219 my $symbol = $3;
220
Martin Roth1b44f7e2016-01-11 14:31:38 -0700221 if ( ( exists $symbols{$symbol} ) ) {
Julius Wernere5eb2de2019-03-05 17:10:19 -0800222 show_error("#define of symbol 'CONFIG_$symbol' used at $file:$lineno.");
Martin Roth1b44f7e2016-01-11 14:31:38 -0700223 }
224 else {
Julius Wernere5eb2de2019-03-05 17:10:19 -0800225 show_error( "#define 'CONFIG_$symbol' used at $file:$lineno."
Martin Roth1b44f7e2016-01-11 14:31:38 -0700226 . " Other #defines should not look like Kconfig symbols." );
227 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600228 }
229 }
230}
231
232#-------------------------------------------------------------------------------
Martin Roth08705f12016-11-09 14:27:00 -0700233# check_type - Make sure that all symbols have a type defined.
234#
235# Conflicting types are found when parsing the Kconfig tree.
236#-------------------------------------------------------------------------------
237sub 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 Huberec017592019-04-06 16:09:46 +0200258# 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 Rothbcaaad12015-10-18 11:16:25 -0600265#-------------------------------------------------------------------------------
Nico Huberec017592019-04-06 16:09:46 +0200266sub check_config_macro {
Martin Rothb6acc302015-11-27 18:51:19 -0700267 my @is_enabled_symbols = @collected_symbols;
Martin Rothbcaaad12015-10-18 11:16:25 -0600268
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 Werneref7a3262019-03-05 16:57:52 -0800271 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 Wernerf0286042019-04-09 15:57:07 -0700287 show_error("CONFIG() used on unknown value ($symbol) at $file:$lineno.");
Julius Werneref7a3262019-03-05 16:57:52 -0800288 }
289 }
290 } elsif ( $line =~ /^([^:]+):(\d+):(.+IS_ENABLED.*)/ ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -0700291 my $file = $1;
Martin Rothbcaaad12015-10-18 11:16:25 -0600292 my $lineno = $2;
Martin Rothb6acc302015-11-27 18:51:19 -0700293 $line = $3;
Martin Roth572a8562016-01-25 16:14:09 -0700294 if ( ( $line !~ /(.*)IS_ENABLED\s*\(\s*CONFIG_(\w+)(.*)/ ) && ( $line !~ /(\/[\*\/])(.*)IS_ENABLED/ ) ) {
Nico Huberec017592019-04-06 16:09:46 +0200295 show_error("# uninterpreted IS_ENABLED at $file:$lineno: $line");
Martin Rothb6acc302015-11-27 18:51:19 -0700296 next;
Martin Rothbcaaad12015-10-18 11:16:25 -0600297 }
Martin Rothb6acc302015-11-27 18:51:19 -0700298 while ( $line =~ /(.*)IS_ENABLED\s*\(\s*CONFIG_(\w+)(.*)/ ) {
299 my $symbol = $2;
Martin Roth1b44f7e2016-01-11 14:31:38 -0700300 $line = $1 . $3;
Nico Huberec017592019-04-06 16:09:46 +0200301 show_error("IS_ENABLED(CONFIG_$symbol) at $file:$lineno is deprecated. Use CONFIG($symbol) instead.");
Martin Rothb6acc302015-11-27 18:51:19 -0700302 }
Martin Roth5b883012017-06-25 20:27:36 -0600303 } 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 Huberec017592019-04-06 16:09:46 +0200307 # If the type is bool, give a warning that CONFIG() should be used
Martin Roth5b883012017-06-25 20:27:36 -0600308 if ( exists $symbols{$symbol} ) {
309 if ( $symbols{$symbol}{type} eq "bool" ) {
310 show_error( "#if CONFIG_$symbol used at $file:$lineno."
Julius Werneref7a3262019-03-05 16:57:52 -0800311 . " CONFIG($symbol) should be used for type 'bool'" );
Martin Roth5b883012017-06-25 20:27:36 -0600312 }
313 }
Julius Werneref7a3262019-03-05 16:57:52 -0800314 } elsif ( $line =~ /^([^:]+):(\d+):\s*#\s*(?:el)?if.*(?:&&|\|\|)\s+!?\s*\(?\s*CONFIG_(\w+)\)?(\s*==\s*1)?$/ ) {
Martin Roth5b883012017-06-25 20:27:36 -0600315 my $file = $1;
316 my $lineno = $2;
317 my $symbol = $3;
Nico Huberec017592019-04-06 16:09:46 +0200318 # If the type is bool, give a warning that CONFIG() should be used
Martin Roth5b883012017-06-25 20:27:36 -0600319 if ( exists $symbols{$symbol} ) {
320 if ( $symbols{$symbol}{type} eq "bool" ) {
321 show_error( "#if CONFIG_$symbol used at $file:$lineno."
Julius Werneref7a3262019-03-05 16:57:52 -0800322 . " CONFIG($symbol) should be used for type 'bool'" );
Martin Roth5b883012017-06-25 20:27:36 -0600323 }
324 }
Julius Wernere5eb2de2019-03-05 17:10:19 -0800325 } 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 Rotha0209032020-07-24 12:42:59 -0600335 show_error( "Naked reference to CONFIG_$symbol used at $file:$lineno."
Julius Wernere5eb2de2019-03-05 17:10:19 -0800336 . " 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 Rothbcaaad12015-10-18 11:16:25 -0600343 }
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#-------------------------------------------------------------------------------
353sub 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 Rothfa956252016-09-30 15:51:32 -0600368 my $filename = $symbols{$sym}{$sym_num}{file};
369 my $line_no = $symbols{$sym}{$sym_num}{default}{$def_num}{default_line_no};
370
Martin Roth08705f12016-11-09 14:27:00 -0700371 # Make sure there's a type set for the symbol
372 next if (!defined $symbols{$sym}{type});
373
Martin Rothfa956252016-09-30 15:51:32 -0600374 # 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 Wernere5eb2de2019-03-05 17:10:19 -0800397 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 Rothfa956252016-09-30 15:51:32 -0600398 } 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 Rothbcaaad12015-10-18 11:16:25 -0600405 #if a default is already set, display an error
406 if ($default_set) {
Julius Wernere5eb2de2019-03-05 17:10:19 -0800407 show_error( "Default for '$sym' referenced at $filename:$line_no will never be set"
Martin Roth1b44f7e2016-01-11 14:31:38 -0700408 . " - overridden by default set at $default_filename:$default_line_no" );
Martin Rothbcaaad12015-10-18 11:16:25 -0600409 }
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#-------------------------------------------------------------------------------
429sub 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 Rothd8080172015-11-26 19:12:44 -0700437 #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 Roth7aa3cea2015-11-27 18:45:45 -0700441 show_error("Undefined Symbol '$key' used at $filename:$line_no.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600442 }
443 }
444}
445
446#-------------------------------------------------------------------------------
447#-------------------------------------------------------------------------------
448sub collect_used_symbols {
449 # find all references to CONFIG_ statements in the tree
450
451 if ($dont_use_git_grep) {
Julius Werneref7a3262019-03-05 16:57:52 -0800452 @collected_symbols = `grep -Irn -- "CONFIG\\(_\\|(\\)" | grep -v '$exclude_dirs_and_files'; grep -In -- "CONFIG\\(_\\|(\\)" $payload_files_to_check`;
Martin Roth1b44f7e2016-01-11 14:31:38 -0700453 }
454 else {
Julius Werneref7a3262019-03-05 16:57:52 -0800455 @collected_symbols = `git grep -In -- "CONFIG\\(_\\|(\\)" | grep -v '$exclude_dirs_and_files'; git grep -In -- "CONFIG\\(_\\|(\\)" $payload_files_to_check`;
Martin Rothbcaaad12015-10-18 11:16:25 -0600456 }
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 Werneref7a3262019-03-05 16:57:52 -0800462 while ( $line =~ /[^A-Za-z0-9_]CONFIG(?:_|\()([A-Za-z0-9_]+)/g ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -0700463 my $symbol = $1;
Martin Rothbcaaad12015-10-18 11:16:25 -0600464 my $filename = "";
Martin Roth1b44f7e2016-01-11 14:31:38 -0700465 if ( $line =~ /^([^:]+):/ ) {
Martin Rothbcaaad12015-10-18 11:16:25 -0600466 $filename = $1;
467 }
468
Martin Roth1b44f7e2016-01-11 14:31:38 -0700469 if ( exists $used_symbols{$symbol}{count} ) {
Martin Rothbcaaad12015-10-18 11:16:25 -0600470 $used_symbols{$symbol}{count}++;
Martin Roth1b44f7e2016-01-11 14:31:38 -0700471 }
472 else {
473 $used_symbols{$symbol}{count} = 0;
Martin Rothbcaaad12015-10-18 11:16:25 -0600474 }
475 $used_symbols{$symbol}{"num_$used_symbols{$symbol}{count}"} = $filename;
Martin Roth1b44f7e2016-01-11 14:31:38 -0700476 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600477 }
478}
479
480#-------------------------------------------------------------------------------
481# check_used_symbols - Checks to see whether or not the created symbols are
482# actually used.
483#-------------------------------------------------------------------------------
484sub 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 Roth6bfbf1c2016-01-25 16:12:49 -0700488 if ( $key =~ /$exclude_unused/ ) {
489 next;
490 }
491
Martin Rothbcaaad12015-10-18 11:16:25 -0600492 #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 Rotha7d00272016-10-03 23:00:04 +0200502 show_warning("Unused symbol '$key' referenced at $filename:$line_no.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600503 }
504 }
505}
506
507#-------------------------------------------------------------------------------
508# build_and_parse_kconfig_tree
509#-------------------------------------------------------------------------------
510#load the initial file and start parsing it
511sub 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 Georgicbc5b992018-11-23 15:55:56 +0100520 my $choice_symbol = "";
Martin Rothbcaaad12015-10-18 11:16:25 -0600521 my $configs_inside_choice;
Martin Roth0e6c0e12016-03-02 12:16:13 -0700522 my %fileinfo;
Martin Rothbcaaad12015-10-18 11:16:25 -0600523
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 Rothbcaaad12015-10-18 11:16:25 -0600527 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 Roth811d93a2017-04-06 11:06:00 -0600533 my $lastline_was_help = $inside_help;
Martin Rothbcaaad12015-10-18 11:16:25 -0600534 $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 Roth811d93a2017-04-06 11:06:00 -0600549 elsif ( $line =~ /^\s*config\s+/ ) {
Martin Rothbcaaad12015-10-18 11:16:25 -0600550 $line =~ /^\s*config\s+([^"\s]+)\s*(?>#.*)?$/;
551 my $symbol = $1;
552 $inside_config = $symbol;
553 if ($inside_choice) {
554 $configs_inside_choice++;
555 }
Martin Rothb7c39b22016-01-14 09:04:53 -0700556 add_symbol( $symbol, \@inside_menu, $filename, $line_no, \@inside_if, $inside_choice );
Martin Rothbcaaad12015-10-18 11:16:25 -0600557 }
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 Georgicbc5b992018-11-23 15:55:56 +0100608 $choice_symbol = $symbol;
Martin Rothbcaaad12015-10-18 11:16:25 -0600609 }
610 $inside_config = "";
611 $inside_choice = "$filename $line_no";
612 $configs_inside_choice = 0;
Martin Roth08cf90f2016-01-25 19:54:16 -0700613
614 # Kconfig verifies that choice blocks have a prompt
Martin Rothbcaaad12015-10-18 11:16:25 -0600615 }
616
617 # endchoice
618 elsif ( $line =~ /^\s*endchoice/ ) {
619 $inside_config = "";
620 if ( !$inside_choice ) {
Martin Roth7aa3cea2015-11-27 18:45:45 -0700621 show_error("'endchoice' keyword not within a choice block at $filename:$line_no.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600622 }
623
624 $inside_choice = "";
Patrick Georgicbc5b992018-11-23 15:55:56 +0100625 if (( $configs_inside_choice == 0 ) &&
626 ( $choice_symbol eq "" )) {
627 show_error("unnamed choice block has no symbols at $filename:$line_no.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600628 }
629 $configs_inside_choice = 0;
Patrick Georgicbc5b992018-11-23 15:55:56 +0100630 $choice_symbol="";
Martin Rothbcaaad12015-10-18 11:16:25 -0600631 }
632
633 # [optional]
634 elsif ( $line =~ /^\s*optional/ ) {
635 if ($inside_config) {
Martin Roth1b44f7e2016-01-11 14:31:38 -0700636 show_error( "Keyword 'optional' appears inside config for '$inside_config'"
637 . " at $filename:$line_no. This is not valid." );
Martin Rothbcaaad12015-10-18 11:16:25 -0600638 }
639 if ( !$inside_choice ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -0700640 show_error( "Keyword 'optional' appears outside of a choice block"
641 . " at $filename:$line_no. This is not valid." );
Martin Rothbcaaad12015-10-18 11:16:25 -0600642 }
643 }
644
645 # mainmenu <prompt>
646 elsif ( $line =~ /^\s*mainmenu/ ) {
647 $inside_config = "";
Martin Roth08cf90f2016-01-25 19:54:16 -0700648
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 Rothbcaaad12015-10-18 11:16:25 -0600652 }
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 Georgifcc29502018-09-16 21:35:46 +0200667 # visible if <expr>
668 elsif ( $line =~ /^\s*visible if.*$/ ) {
Julius Werneref7a3262019-03-05 16:57:52 -0800669 # Must come directly after menu line (and on a separate line)
670 # but kconfig already checks for that.
671 # Ignore it.
Patrick Georgifcc29502018-09-16 21:35:46 +0200672 }
673
Martin Rothbcaaad12015-10-18 11:16:25 -0600674 # 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 Roth0e6c0e12016-03-02 12:16:13 -0700688 $fileinfo{$filename}{iflevel}++;
Martin Rothbcaaad12015-10-18 11:16:25 -0600689 }
690
691 # endif
692 elsif ( $line =~ /^\s*endif/ ) {
693 $inside_config = "";
694 pop(@inside_if);
Martin Roth0e6c0e12016-03-02 12:16:13 -0700695 $fileinfo{$filename}{iflevel}--;
Martin Rothbcaaad12015-10-18 11:16:25 -0600696 }
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 Roth7aa3cea2015-11-27 18:45:45 -0700707 show_error("Keyword 'select' appears outside of config at $filename:$line_no. This is not valid.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600708 }
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 Rothb7c39b22016-01-14 09:04:53 -0700715 add_referenced_symbol( $line, $filename, $line_no, 'select' );
Martin Rothbcaaad12015-10-18 11:16:25 -0600716 }
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 Roth811d93a2017-04-06 11:06:00 -0600734 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 Rothbcaaad12015-10-18 11:16:25 -0600740 }
741
Martin Roth819e6722016-01-25 16:38:05 -0700742 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 Rothbcaaad12015-10-18 11:16:25 -0600757 push @wholeconfig, @parseline;
758 }
Martin Roth0e6c0e12016-03-02 12:16:13 -0700759
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 Rothbcaaad12015-10-18 11:16:25 -0600769}
770
771#-------------------------------------------------------------------------------
772#-------------------------------------------------------------------------------
773sub 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#-------------------------------------------------------------------------------
792sub add_symbol {
Martin Rothb7c39b22016-01-14 09:04:53 -0700793 my ( $symbol, $menu_array_ref, $filename, $line_no, $ifref, $inside_choice ) = @_;
Martin Rothbcaaad12015-10-18 11:16:25 -0600794 my @inside_if = @{$ifref};
795
796 #initialize the symbol or increment the use count.
Martin Roth1b44f7e2016-01-11 14:31:38 -0700797 if ( ( !exists $symbols{$symbol} ) || ( !exists $symbols{$symbol}{count} ) ) {
Martin Rothbcaaad12015-10-18 11:16:25 -0600798 $symbols{$symbol}{count} = 0;
Martin Rothb7c39b22016-01-14 09:04:53 -0700799 if ($inside_choice) {
800 $symbols{$symbol}{choice} = 1;
801 }
802 else {
803 $symbols{$symbol}{choice} = 0;
804 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600805 }
806 else {
807 $symbols{$symbol}{count}++;
Martin Rothb7c39b22016-01-14 09:04:53 -0700808
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 Rothaa206472017-03-24 08:51:51 -0600817 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 Rothbcaaad12015-10-18 11:16:25 -0600821 }
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#-------------------------------------------------------------------------------
847sub 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 Rothd8080172015-11-26 19:12:44 -0700859 show_error("Range entry in $filename line $line_no value 1 ($range1) is greater than value 2 ($range2).");
Martin Rothbcaaad12015-10-18 11:16:25 -0600860 }
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 Rothd8080172015-11-26 19:12:44 -0700865 if ($show_note_output) {
Martin Roth7aa3cea2015-11-27 18:45:45 -0700866 print "#!!!!! Note: Config '$inside_config' range entry $range1 $range2 at $filename:$line_no does";
Martin Roth1b44f7e2016-01-11 14:31:38 -0700867 print " not match the previously defined range $symbols{$inside_config}{range1}"
868 . " $symbols{$inside_config}{range2}";
Martin Roth7aa3cea2015-11-27 18:45:45 -0700869 print " defined at $symbols{$inside_config}{range_file}:$symbols{$inside_config}{range_line_no}.\n";
Martin Rothbcaaad12015-10-18 11:16:25 -0600870 }
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 Roth7aa3cea2015-11-27 18:45:45 -0700881 show_error("Range entry at $filename:$line_no is not inside a config block.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600882 }
883}
884
885#-------------------------------------------------------------------------------
886# handle_default
887#-------------------------------------------------------------------------------
888sub 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 Roth7aa3cea2015-11-27 18:45:45 -0700911 show_error("$name entry at $filename:$line_no is not inside a config or choice block.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600912 }
913}
914
915#-------------------------------------------------------------------------------
916# handle_if_line
917#-------------------------------------------------------------------------------
918sub 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#-------------------------------------------------------------------------------
950# handle_expressions - log which symbols are being used
951#-------------------------------------------------------------------------------
952sub handle_expressions {
953 my ( $exprline, $inside_config, $filename, $line_no ) = @_;
954
955 return unless ($exprline);
956
957 #filter constant symbols first
Martin Roth1b44f7e2016-01-11 14:31:38 -0700958 if ( $exprline =~ /^\s*"?([yn])"?\s*$/ ) { # constant y/n
Martin Rothbcaaad12015-10-18 11:16:25 -0600959 return;
960 }
Martin Roth1b44f7e2016-01-11 14:31:38 -0700961 elsif ( $exprline =~ /^\s*"?((?:-)\d+)"?\s*$/ ) { # int values
Martin Rothbcaaad12015-10-18 11:16:25 -0600962 return;
963 }
964 elsif ( $exprline =~ /^\s*"?((?:-)?(?:0x)?\p{XDigit})+"?\s*$/ ) { # hex values
965 return;
966 }
967 elsif ( $exprline =~ /^\s*("[^"]*")\s*$/ ) { # String values
968 return;
969 }
970 elsif ( $exprline =~ /^\s*([A-Za-z0-9_]+)\s*$/ ) { # <symbol> (1)
Martin Rothb7c39b22016-01-14 09:04:53 -0700971 add_referenced_symbol( $1, $filename, $line_no, 'expression' );
Martin Rothbcaaad12015-10-18 11:16:25 -0600972 }
973 elsif ( $exprline =~ /^\s*!(.+)$/ ) { # '!' <expr> (5)
974
975 handle_expressions( $1, $inside_config, $filename, $line_no );
976 }
977 elsif ( $exprline =~ /^\s*\(([^)]+)\)\s*$/ ) { # '(' <expr> ')' (4)
978 handle_expressions( $1, $inside_config, $filename, $line_no );
979 }
980 elsif ( $exprline =~ /^\s*(.+)\s*!=\s*(.+)\s*$/ ) { # <symbol> '!=' <symbol> (3)
981 handle_expressions( $1, $inside_config, $filename, $line_no );
982 handle_expressions( $2, $inside_config, $filename, $line_no );
983 }
984 elsif ( $exprline =~ /^\s*(.+)\s*=\s*(.+)\s*$/ ) { # <symbol> '=' <symbol> (2)
985 handle_expressions( $1, $inside_config, $filename, $line_no );
986 handle_expressions( $2, $inside_config, $filename, $line_no );
987 }
988 elsif ( $exprline =~ /^\s*([^(]+|\(.+\))\s*&&\s*(.+)\s*$/ ) { # <expr> '&&' <expr> (6)
989 handle_expressions( $1, $inside_config, $filename, $line_no );
990 handle_expressions( $2, $inside_config, $filename, $line_no );
991 }
992 elsif ( $exprline =~ /^\s*([^(]+|\(.+\))\s*\|\|\s*(.+)\s*$/ ) { # <expr> '||' <expr> (7)
993 handle_expressions( $1, $inside_config, $filename, $line_no );
994 handle_expressions( $2, $inside_config, $filename, $line_no );
995 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600996 else {
Martin Rothd8080172015-11-26 19:12:44 -0700997 show_error("Unrecognized expression '$exprline' in $filename line $line_no.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600998 }
999
1000 return;
1001}
1002
1003#-------------------------------------------------------------------------------
1004# add_referenced_symbol
1005#-------------------------------------------------------------------------------
1006sub add_referenced_symbol {
Martin Rothb7c39b22016-01-14 09:04:53 -07001007 my ( $symbol, $filename, $line_no, $reftype ) = @_;
Martin Rothbcaaad12015-10-18 11:16:25 -06001008 if ( exists $referenced_symbols{$symbol} ) {
1009 $referenced_symbols{$symbol}{count}++;
1010 $referenced_symbols{$symbol}{ $referenced_symbols{$symbol}{count} }{filename} = $filename;
1011 $referenced_symbols{$symbol}{ $referenced_symbols{$symbol}{count} }{line_no} = $line_no;
1012 }
1013 else {
1014 $referenced_symbols{$symbol}{count} = 0;
1015 $referenced_symbols{$symbol}{0}{filename} = $filename;
1016 $referenced_symbols{$symbol}{0}{line_no} = $line_no;
1017 }
Martin Rothb7c39b22016-01-14 09:04:53 -07001018
1019 #mark the symbol as being selected, use referenced symbols for location
1020 if ( $reftype eq 'select' ) {
1021 $selected_symbols{$symbol}{ $referenced_symbols{$symbol}{count} } = 1;
1022 }
Martin Rothbcaaad12015-10-18 11:16:25 -06001023}
1024
1025#-------------------------------------------------------------------------------
1026# handle_help
1027#-------------------------------------------------------------------------------
1028{
1029 #create a non-global static variable by enclosing it and the subroutine
1030 my $help_whitespace = ""; #string to show length of the help whitespace
Martin Roth8849f3b2017-05-23 19:43:43 -06001031 my $help_keyword_whitespace = "";
Martin Rothbcaaad12015-10-18 11:16:25 -06001032
1033 sub handle_help {
1034 my ( $line, $inside_help, $inside_config, $inside_choice, $filename, $line_no ) = @_;
1035
1036 if ($inside_help) {
1037
1038 #get the indentation level if it's not already set.
1039 if ( ( !$help_whitespace ) && ( $line !~ /^[\r\n]+/ ) ) {
1040 $line =~ /^(\s+)/; #find the indentation level.
1041 $help_whitespace = $1;
1042 if ( !$help_whitespace ) {
Martin Roth8849f3b2017-05-23 19:43:43 -06001043 show_error("$filename:$line_no - help text starts with no whitespace.");
1044 return $inside_help;
1045 }
1046 elsif ($help_keyword_whitespace eq $help_whitespace) {
1047 show_error("$filename:$line_no - help text needs additional indentation.");
Martin Rothbcaaad12015-10-18 11:16:25 -06001048 return $inside_help;
Martin Rothbcaaad12015-10-18 11:16:25 -06001049 }
1050 }
1051
1052 #help ends at the first line which has a smaller indentation than the first line of the help text.
Martin Roth8849f3b2017-05-23 19:43:43 -06001053 if ( ( $line !~ /^$help_whitespace/ ) && ( $line !~ /^[\r\n]+/ ) ) {
Martin Rothbcaaad12015-10-18 11:16:25 -06001054 $inside_help = 0;
1055 $help_whitespace = "";
Martin Roth8849f3b2017-05-23 19:43:43 -06001056 $help_keyword_whitespace = "";
Martin Rothbcaaad12015-10-18 11:16:25 -06001057 }
1058 else { #if it's not ended, add the line to the helptext array for the symbol's instance
1059 if ($inside_config) {
1060 my $sym_num = $symbols{$inside_config}{count};
1061 if ($help_whitespace) { $line =~ s/^$help_whitespace//; }
1062 push( @{ $symbols{$inside_config}{$sym_num}{helptext} }, $line );
1063 }
Martin Roth8849f3b2017-05-23 19:43:43 -06001064 if ( ($help_keyword_whitespace eq $help_whitespace) && ( $line !~ /^[\r\n]+/ ) ) {
1065 show_error("$filename:$line_no - help text needs additional indentation.");
1066 }
Martin Rothbcaaad12015-10-18 11:16:25 -06001067 }
1068 }
1069 elsif ( ( $line =~ /^(\s*)help/ ) || ( $line =~ /^(\s*)---help---/ ) ) {
1070 $inside_help = $line_no;
Martin Roth8849f3b2017-05-23 19:43:43 -06001071 $line =~ /^(\s+)/;
1072 $help_keyword_whitespace = $1;
Martin Rothbcaaad12015-10-18 11:16:25 -06001073 if ( ( !$inside_config ) && ( !$inside_choice ) ) {
Martin Rothd8080172015-11-26 19:12:44 -07001074 if ($show_note_output) {
Martin Roth7aa3cea2015-11-27 18:45:45 -07001075 print "# Note: $filename:$line_no help is not inside a config or choice block.\n";
Martin Rothbcaaad12015-10-18 11:16:25 -06001076 }
Martin Rothbcaaad12015-10-18 11:16:25 -06001077 }
1078 elsif ($inside_config) {
1079 $help_whitespace = "";
1080 my $sym_num = $symbols{$inside_config}{count};
1081 $symbols{$inside_config}{$sym_num}{help_line_no} = $line_no;
1082 $symbols{$inside_config}{$sym_num}{helptext} = ();
1083 }
1084 }
1085 return $inside_help;
1086 }
1087}
1088
1089#-------------------------------------------------------------------------------
1090# handle_type
1091#-------------------------------------------------------------------------------
1092sub handle_type {
1093 my ( $type, $inside_config, $filename, $line_no ) = @_;
1094
1095 my $expression;
1096 ( $type, $expression ) = handle_if_line( $type, $inside_config, $filename, $line_no );
1097
Martin Roth08ee1cf2016-01-25 16:39:32 -07001098 if ( $type =~ /tristate/ ) {
Julius Wernere5eb2de2019-03-05 17:10:19 -08001099 show_error("$filename:$line_no - tristate types are not used.");
Martin Roth08ee1cf2016-01-25 16:39:32 -07001100 }
1101
Martin Rothbcaaad12015-10-18 11:16:25 -06001102 if ($inside_config) {
1103 if ( exists( $symbols{$inside_config}{type} ) ) {
1104 if ( $symbols{$inside_config}{type} !~ /$type/ ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -07001105 show_error( "Config '$inside_config' type entry $type"
1106 . " at $filename:$line_no does not match $symbols{$inside_config}{type}"
1107 . " defined at $symbols{$inside_config}{type_file}:$symbols{$inside_config}{type_line_no}." );
Martin Rothbcaaad12015-10-18 11:16:25 -06001108 }
1109 }
1110 else {
1111 $symbols{$inside_config}{type} = $type;
1112 $symbols{$inside_config}{type_file} = $filename;
1113 $symbols{$inside_config}{type_line_no} = $line_no;
1114 }
1115 }
1116 else {
Martin Roth7aa3cea2015-11-27 18:45:45 -07001117 show_error("Type entry at $filename:$line_no is not inside a config block.");
Martin Rothbcaaad12015-10-18 11:16:25 -06001118 }
1119}
1120
1121#-------------------------------------------------------------------------------
1122# handle_prompt
1123#-------------------------------------------------------------------------------
1124sub handle_prompt {
1125 my ( $prompt, $name, $menu_array_ref, $inside_config, $inside_choice, $filename, $line_no ) = @_;
1126
1127 my $expression;
1128 ( $prompt, $expression ) = handle_if_line( $prompt, $inside_config, $filename, $line_no );
1129
1130 if ($inside_config) {
1131 if ( $prompt !~ /^\s*$/ ) {
1132 if ( $prompt =~ /^\s*"([^"]*)"\s*$/ ) {
1133 $prompt = $1;
1134 }
1135
Martin Roth08cf90f2016-01-25 19:54:16 -07001136 #display an error if there's a prompt at the top menu level
Martin Rothbcaaad12015-10-18 11:16:25 -06001137 if ( !defined @$menu_array_ref[0] ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -07001138 show_error( "Symbol '$inside_config' with prompt '$prompt' appears outside of a menu"
1139 . " at $filename:$line_no." );
Martin Rothbcaaad12015-10-18 11:16:25 -06001140 }
1141
1142 my $sym_num = $symbols{$inside_config}{count};
Martin Rothb58d3492016-01-25 16:42:13 -07001143 if ( !exists $symbols{$inside_config}{$sym_num}{prompt_max} ) {
Martin Rothbcaaad12015-10-18 11:16:25 -06001144 $symbols{$inside_config}{$sym_num}{prompt_max} = 0;
1145 }
Martin Rothb58d3492016-01-25 16:42:13 -07001146 else {
1147 $symbols{$inside_config}{$sym_num}{prompt_max}++;
1148 }
Martin Rothbcaaad12015-10-18 11:16:25 -06001149 my $prompt_max = $symbols{$inside_config}{$sym_num}{prompt_max};
1150 $symbols{$inside_config}{$sym_num}{prompt}{$prompt_max}{prompt} = $prompt;
1151 $symbols{$inside_config}{$sym_num}{prompt}{$prompt_max}{prompt_line_no} = $line_no;
Martin Rothb58d3492016-01-25 16:42:13 -07001152
1153 $symbols{$inside_config}{$sym_num}{prompt}{$prompt_max}{prompt_menu} = @$menu_array_ref;
Martin Rothbcaaad12015-10-18 11:16:25 -06001154 if ($expression) {
1155 $symbols{$inside_config}{$sym_num}{prompt}{$prompt_max}{prompt_depends_on} = $expression;
1156 }
1157 }
1158 }
1159 elsif ($inside_choice) {
1160
1161 #do nothing
1162 }
1163 else {
Martin Roth7aa3cea2015-11-27 18:45:45 -07001164 show_error("$name entry at $filename:$line_no is not inside a config or choice block.");
Martin Rothbcaaad12015-10-18 11:16:25 -06001165 }
1166}
1167
1168#-------------------------------------------------------------------------------
1169# simple_line_checks - Does some basic checks on the current line, then cleans the line
1170# up for further processing.
1171#-------------------------------------------------------------------------------
1172sub simple_line_checks {
1173 my ( $line, $filename, $line_no ) = @_;
1174
1175 #check for spaces instead of tabs
1176 if ( $line =~ /^ +/ ) {
Martin Roth7aa3cea2015-11-27 18:45:45 -07001177 show_error("$filename:$line_no starts with a space.");
Martin Rothbcaaad12015-10-18 11:16:25 -06001178 }
1179
1180 #verify a linefeed at the end of the line
1181 if ( $line !~ /.*\n/ ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -07001182 show_error( "$filename:$line_no does not end with linefeed."
1183 . " This can cause the line to not be recognized by the Kconfig parser.\n#($line)" );
Martin Rothbcaaad12015-10-18 11:16:25 -06001184 $line =~ s/\s*$//;
1185 }
1186 else {
1187 chop($line);
1188 }
1189
1190 return $line;
1191}
1192
1193#-------------------------------------------------------------------------------
1194# load_kconfig_file - Loads a single Kconfig file or expands * wildcard
1195#-------------------------------------------------------------------------------
1196sub load_kconfig_file {
1197 my ( $input_file, $loadfile, $loadline, $expanded, $topfile, $topline ) = @_;
1198 my @file_data;
1199 my @dir_file_data;
1200
1201 #recursively handle coreboot's new source glob operator
Arthur Heymans55f01322019-11-05 12:06:59 +01001202 if ( $input_file =~ /^(.*?)\/(\w*)\*(\w*)\/(.*)$/ ) {
Martin Rothbcaaad12015-10-18 11:16:25 -06001203 my $dir_prefix = $1;
Arthur Heymans55f01322019-11-05 12:06:59 +01001204 my $dir_glob_prefix = $2;
1205 my $dir_glob_suffix = $3;
1206 my $dir_suffix = $4;
Martin Rothbcaaad12015-10-18 11:16:25 -06001207 if ( -d "$dir_prefix" ) {
1208
1209 opendir( D, "$dir_prefix" ) || die "Can't open directory '$dir_prefix'\n";
1210 my @dirlist = sort { $a cmp $b } readdir(D);
1211 closedir(D);
1212
1213 while ( my $directory = shift @dirlist ) {
1214
1215 #ignore non-directory files
Arthur Heymans55f01322019-11-05 12:06:59 +01001216 if ( ( -d "$dir_prefix/$directory" ) && !( $directory =~ /^\..*/ )
1217 && ( $directory =~ /\Q$dir_glob_prefix\E.*\Q$dir_glob_suffix\E/ ) ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -07001218 push @dir_file_data,
1219 load_kconfig_file( "$dir_prefix/$directory/$dir_suffix",
1220 $input_file, $loadline, 1, $loadfile, $loadline );
Martin Rothbcaaad12015-10-18 11:16:25 -06001221 }
1222 }
1223 }
1224
1225 #the directory should exist when using a glob
1226 else {
Julius Wernere5eb2de2019-03-05 17:10:19 -08001227 show_error("Could not find dir '$dir_prefix'");
Martin Rothbcaaad12015-10-18 11:16:25 -06001228 }
1229 }
1230
1231 #if the file exists, try to load it.
1232 elsif ( -e "$input_file" ) {
1233
Martin Rotha7d00272016-10-03 23:00:04 +02001234 #throw a warning if the file has already been loaded.
Martin Rothbcaaad12015-10-18 11:16:25 -06001235 if ( exists $loaded_files{$input_file} ) {
Martin Rotha7d00272016-10-03 23:00:04 +02001236 show_warning("'$input_file' sourced at $loadfile:$loadline was already loaded by $loaded_files{$input_file}");
Martin Rothbcaaad12015-10-18 11:16:25 -06001237 }
1238
1239 #load the file's contents and mark the file as loaded for checking later
1240 open( my $HANDLE, "<", "$input_file" ) or die "Error: could not open file '$input_file'\n";
1241 @file_data = <$HANDLE>;
1242 close $HANDLE;
1243 $loaded_files{$input_file} = "'$loadfile' line $loadline";
1244 }
1245
1246 # if the file isn't being loaded from a glob, it should exist.
1247 elsif ( $expanded == 0 ) {
Martin Roth7aa3cea2015-11-27 18:45:45 -07001248 show_warning("Could not find file '$input_file' sourced at $loadfile:$loadline");
Martin Rothbcaaad12015-10-18 11:16:25 -06001249 }
1250
1251 my $line_in_file = 0;
1252 while ( my $line = shift @file_data ) {
1253
1254 #handle line continuation.
1255 my $continue_line = 0;
Martin Roth1b44f7e2016-01-11 14:31:38 -07001256 while ( $line =~ /(.*)\s+\\$/ ) {
Martin Rothbcaaad12015-10-18 11:16:25 -06001257 my $text = $1;
1258
1259 # get rid of leading whitespace on all but the first and last lines
1260 $text =~ s/^\s*/ / if ($continue_line);
1261
1262 $dir_file_data[$line_in_file]{text} .= $text;
1263 $line = shift @file_data;
1264 $continue_line++;
1265
1266 #put the data into the continued lines (other than the first)
1267 $line =~ /^\s*(.*)\s*$/;
1268
Martin Roth1b44f7e2016-01-11 14:31:38 -07001269 $dir_file_data[ $line_in_file + $continue_line ]{text} = "\t# continued line ( " . $1 . " )\n";
1270 $dir_file_data[ $line_in_file + $continue_line ]{filename} = $input_file;
1271 $dir_file_data[ $line_in_file + $continue_line ]{file_line_no} = $line_in_file + $continue_line + 1;
Martin Rothbcaaad12015-10-18 11:16:25 -06001272
1273 #get rid of multiple leading spaces for last line
1274 $line = " $1\n";
1275 }
1276
Martin Roth1b44f7e2016-01-11 14:31:38 -07001277 $dir_file_data[$line_in_file]{text} .= $line;
Martin Rothbcaaad12015-10-18 11:16:25 -06001278 $dir_file_data[$line_in_file]{filename} = $input_file;
1279 $dir_file_data[$line_in_file]{file_line_no} = $line_in_file + 1;
1280
1281 $line_in_file++;
1282 if ($continue_line) {
1283 $line_in_file += $continue_line;
1284 }
1285 }
1286
1287 if ($topfile) {
1288 my %file_data;
Martin Roth1b44f7e2016-01-11 14:31:38 -07001289 $file_data{text} = "\t### File '$input_file' loaded from '$topfile' line $topline\n";
Martin Rothbcaaad12015-10-18 11:16:25 -06001290 $file_data{filename} = $topfile;
1291 $file_data{file_line_no} = "($topline)";
Martin Roth1b44f7e2016-01-11 14:31:38 -07001292 unshift( @dir_file_data, \%file_data );
Martin Rothbcaaad12015-10-18 11:16:25 -06001293 }
1294
1295 return @dir_file_data;
1296}
1297
Martin Rothbcaaad12015-10-18 11:16:25 -06001298#-------------------------------------------------------------------------------
1299# print_wholeconfig - prints out the parsed Kconfig file
1300#-------------------------------------------------------------------------------
1301sub print_wholeconfig {
1302
1303 return unless $print_full_output;
1304
1305 for ( my $i = 0 ; $i < $#wholeconfig ; $i++ ) {
1306 my $line = $wholeconfig[$i];
1307 chop( $line->{text} );
1308
1309 #replace tabs with spaces for consistency
1310 $line->{text} =~ s/\t/ /g;
Martin Roth819e6722016-01-25 16:38:05 -07001311 printf "%-120s # $line->{filename} line $line->{file_line_no} ($line->{menus})\n", $line->{text};
Martin Rothbcaaad12015-10-18 11:16:25 -06001312 }
1313}
1314
1315#-------------------------------------------------------------------------------
1316# check_if_file_referenced - checks for kconfig files that are not being parsed
1317#-------------------------------------------------------------------------------
1318sub check_if_file_referenced {
1319 my $filename = $File::Find::name;
Martin Rothab2d7772016-01-25 16:45:14 -07001320 if ( ( $filename =~ /Kconfig/ )
1321 && ( !$filename =~ /\.orig$/ )
1322 && ( !$filename =~ /~$/ )
1323 && ( !exists $loaded_files{$filename} ) )
1324 {
Martin Rothd8080172015-11-26 19:12:44 -07001325 show_warning("'$filename' is never referenced");
Martin Rothbcaaad12015-10-18 11:16:25 -06001326 }
1327}
1328
1329#-------------------------------------------------------------------------------
1330# check_arguments parse the command line arguments
1331#-------------------------------------------------------------------------------
1332sub check_arguments {
1333 my $show_usage = 0;
1334 GetOptions(
1335 'help|?' => sub { usage() },
Martin Rothd8080172015-11-26 19:12:44 -07001336 'e|errors_off' => \$suppress_error_output,
1337 'n|notes' => \$show_note_output,
Martin Rothbcaaad12015-10-18 11:16:25 -06001338 'o|output=s' => \$output_file,
1339 'p|print' => \$print_full_output,
Martin Rothd8080172015-11-26 19:12:44 -07001340 'w|warnings_off' => \$suppress_warning_output,
Martin Rothbcaaad12015-10-18 11:16:25 -06001341 'path=s' => \$top_dir,
1342 'c|config=s' => \$config_file,
1343 'G|no_git_grep' => \$dont_use_git_grep,
1344 );
Martin Rothd8080172015-11-26 19:12:44 -07001345
1346 if ($suppress_error_output) {
1347 $suppress_warning_output = 1;
1348 }
1349 if ($suppress_warning_output) {
Martin Roth1b44f7e2016-01-11 14:31:38 -07001350 $show_note_output = 0;
Martin Rothd8080172015-11-26 19:12:44 -07001351 }
Martin Rothbcaaad12015-10-18 11:16:25 -06001352}
1353
1354#-------------------------------------------------------------------------------
1355# usage - Print the arguments for the user
1356#-------------------------------------------------------------------------------
1357sub usage {
1358 print "kconfig_lint <options>\n";
1359 print " -o|--output=file Set output filename\n";
1360 print " -p|--print Print full output\n";
Martin Rothd8080172015-11-26 19:12:44 -07001361 print " -e|--errors_off Don't print warnings or errors\n";
Martin Rothbcaaad12015-10-18 11:16:25 -06001362 print " -w|--warnings_off Don't print warnings\n";
Martin Rothd8080172015-11-26 19:12:44 -07001363 print " -n|--notes Show minor notes\n";
Martin Rothbcaaad12015-10-18 11:16:25 -06001364 print " --path=dir Path to top level kconfig\n";
1365 print " -c|--config=file Filename of config file to load\n";
1366 print " -G|--no_git_grep Use standard grep tools instead of git grep\n";
1367
1368 exit(0);
1369}
1370
13711;