blob: 16188bacc55df65ca82d504e07589e2983604408 [file] [log] [blame]
Yegor Timoshenkoc2e49412018-10-07 01:58:27 +00001#!/usr/bin/env perl
Martin Rothbcaaad12015-10-18 11:16:25 -06002
3#
4# This file is part of the coreboot project.
5#
6# Copyright (C) 2015 Martin L Roth <gaumless@gmail.com>
Martin Roth63ea4932016-01-25 16:08:27 -07007# Copyright (C) 2015-2016 Google, Inc.
Martin Rothbcaaad12015-10-18 11:16:25 -06008#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; version 2 of the License.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
Martin Roth1b44f7e2016-01-11 14:31:38 -070018# perltidy -l=123
Martin Rothbcaaad12015-10-18 11:16:25 -060019
20package kconfig_lint;
21
22use strict;
23use warnings;
24use English qw( -no_match_vars );
25use File::Find;
26use Getopt::Long;
27use Getopt::Std;
28
Martin Rothabf7d4d2016-02-19 10:24:25 -070029# If taint mode is enabled, Untaint the path - git and grep must be in /bin, /usr/bin or /usr/local/bin
30if ( ${^TAINT} ) {
31 $ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
32 delete @ENV{ 'IFS', 'CDPATH', 'ENV', 'BASH_ENV' };
33}
34
Martin Roth1b44f7e2016-01-11 14:31:38 -070035my $suppress_error_output = 0; # flag to prevent error text
36my $suppress_warning_output = 0; # flag to prevent warning text
37my $show_note_output = 0; # flag to show minor notes text
38my $print_full_output = 0; # flag to print wholeconfig output
39my $output_file = "-"; # filename of output - set stdout by default
Martin Rothd8080172015-11-26 19:12:44 -070040my $dont_use_git_grep = 0;
Martin Rothbcaaad12015-10-18 11:16:25 -060041
Martin Rothabf7d4d2016-02-19 10:24:25 -070042# Globals
Martin Roth1b44f7e2016-01-11 14:31:38 -070043my $top_dir = "."; # Directory where Kconfig is run
44my $root_dir = "src"; # Directory of the top level Kconfig file
45my $errors_found = 0; # count of errors
Martin Rothd8080172015-11-26 19:12:44 -070046my $warnings_found = 0;
Martin Roth63ea4932016-01-25 16:08:27 -070047my $exclude_dirs_and_files =
Martin Rothab273d32016-11-23 17:28:00 -070048 '^build/\|^coreboot-builds/\|^configs/\|^util/\|^\.git/\|^payloads\|^Documentation\|^3rdparty'
Martin Roth63ea4932016-01-25 16:08:27 -070049 . '\|' . # directories to exclude when searching for used symbols
Julius Wernerf0286042019-04-09 15:57:07 -070050 '\.config\|\.txt$\|\.tex$\|\.tags\|/kconfig.h'; #files to exclude when looking for symbols
Martin Rothe69c58d2016-11-15 21:08:42 -070051my $payload_files_to_check='payloads/Makefile.inc payloads/external/Makefile.inc';
Martin Roth08cf90f2016-01-25 19:54:16 -070052my $config_file = ""; # name of config file to load symbol values from.
53my @wholeconfig; # document the entire kconfig structure
54my %loaded_files; # list of each Kconfig file loaded
55my %symbols; # main structure of all symbols declared
56my %referenced_symbols; # list of symbols referenced by expressions or select statements
57my %used_symbols; # structure of symbols used in the tree, and where they're found
58my @collected_symbols; #
59my %selected_symbols; # list of symbols that are enabled by a select statement
Martin Rothbcaaad12015-10-18 11:16:25 -060060
Martin Roth6bfbf1c2016-01-25 16:12:49 -070061my $exclude_unused = '_SPECIFIC_OPTIONS|SOUTH_BRIDGE_OPTIONS';
62
Martin Rothbcaaad12015-10-18 11:16:25 -060063Main();
64
65#-------------------------------------------------------------------------------
66# Main
67#
68# Start by loading and parsing the top level Kconfig, this pulls in the other
69# files. Parsing the tree creates several arrays and hashes that can be used
70# to check for errors
71#-------------------------------------------------------------------------------
72sub Main {
73
74 check_arguments();
75 open( STDOUT, "> $output_file" ) or die "Can't open $output_file for output: $!\n";
76
Martin Roth1b44f7e2016-01-11 14:31:38 -070077 if ( defined $top_dir ) {
78 chdir $top_dir or die "Error: can't cd to $top_dir\n";
Martin Rothbcaaad12015-10-18 11:16:25 -060079 }
80
Martin Roth1b44f7e2016-01-11 14:31:38 -070081 die "Error: $top_dir/$root_dir does not exist.\n" unless ( -d $root_dir );
Martin Rothbcaaad12015-10-18 11:16:25 -060082
83 #load the Kconfig tree, checking what we can and building up all the hash tables
84 build_and_parse_kconfig_tree("$root_dir/Kconfig");
85
Martin Rothbcaaad12015-10-18 11:16:25 -060086 load_config($config_file) if ($config_file);
87
Martin Roth08705f12016-11-09 14:27:00 -070088 check_type();
Martin Rothbcaaad12015-10-18 11:16:25 -060089 check_defaults();
90 check_referenced_symbols();
91
92 collect_used_symbols();
93 check_used_symbols();
94 check_for_ifdef();
95 check_for_def();
Nico Huberec017592019-04-06 16:09:46 +020096 check_config_macro();
Martin Rothb7c39b22016-01-14 09:04:53 -070097 check_selected_symbols();
Martin Rothbcaaad12015-10-18 11:16:25 -060098
Martin Rothabf7d4d2016-02-19 10:24:25 -070099 # Run checks based on the data that was found
100 if ( ( !$suppress_warning_output ) && ( ${^TAINT} == 0 ) ) {
101
102 # The find function is tainted - only run it if taint checking
103 # is disabled and warnings are enabled.
104 find( \&check_if_file_referenced, $root_dir );
105 }
106
Martin Rothbcaaad12015-10-18 11:16:25 -0600107 print_wholeconfig();
108
Martin Rothd8080172015-11-26 19:12:44 -0700109 if ($errors_found) {
110 print "# $errors_found errors";
Martin Roth1b44f7e2016-01-11 14:31:38 -0700111 if ($warnings_found) {
Martin Rothd8080172015-11-26 19:12:44 -0700112 print ", $warnings_found warnings";
113 }
Martin Roth1b44f7e2016-01-11 14:31:38 -0700114 print "\n";
Martin Rothd8080172015-11-26 19:12:44 -0700115 }
116
Martin Roth1b44f7e2016-01-11 14:31:38 -0700117 exit( $errors_found + $warnings_found );
Martin Rothd8080172015-11-26 19:12:44 -0700118}
119
120#-------------------------------------------------------------------------------
121# Print and count errors
122#-------------------------------------------------------------------------------
123sub show_error {
124 my ($error_msg) = @_;
125 unless ($suppress_error_output) {
126 print "#!!!!! Error: $error_msg\n";
127 $errors_found++;
128 }
129}
130
131#-------------------------------------------------------------------------------
132# Print and count warnings
133#-------------------------------------------------------------------------------
134sub show_warning {
135 my ($warning_msg) = @_;
136 unless ($suppress_warning_output) {
137 print "#!!!!! Warning: $warning_msg\n";
138 $warnings_found++;
139 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600140}
141
142#-------------------------------------------------------------------------------
Martin Rothb7c39b22016-01-14 09:04:53 -0700143# check selected symbols for validity
144# they must be bools
145# they cannot select symbols created in 'choice' blocks
146#-------------------------------------------------------------------------------
147sub check_selected_symbols {
148
149 #loop through symbols found in expressions and used by 'select' keywords
150 foreach my $symbol ( sort ( keys %selected_symbols ) ) {
151 my $type_failure = 0;
152 my $choice_failure = 0;
153
154 #errors selecting symbols that don't exist are already printed, so we
155 #don't need to print them again here
156
157 #make sure the selected symbols are bools
158 if ( ( exists $symbols{$symbol} ) && ( $symbols{$symbol}{type} ne "bool" ) ) {
159 $type_failure = 1;
160 }
161
162 #make sure we're not selecting choice symbols
163 if ( ( exists $symbols{$symbol} ) && ( $symbols{$symbol}{choice} ) ) {
164 $choice_failure = 1;
165 }
166
167 #loop through each instance of the symbol to print out all of the failures
168 for ( my $i = 0 ; $i <= $referenced_symbols{$symbol}{count} ; $i++ ) {
169 next if ( !exists $selected_symbols{$symbol}{$i} );
170 my $file = $referenced_symbols{$symbol}{$i}{filename};
171 my $lineno = $referenced_symbols{$symbol}{$i}{line_no};
172 if ($type_failure) {
173 show_error(
174 "CONFIG_$symbol' selected at $file:$lineno." . " Selects only work on symbols of type bool." );
175 }
176 if ($choice_failure) {
177 show_error(
178 "'CONFIG_$symbol' selected at $file:$lineno." . " Symbols created in a choice cannot be selected." );
179 }
180 }
181 }
182}
183
184#-------------------------------------------------------------------------------
Martin Rothbcaaad12015-10-18 11:16:25 -0600185# check_for_ifdef - Look for instances of #ifdef CONFIG_[symbol_name] and
186# #if defined(CONFIG_[symbol_name]).
187#
188# #ifdef symbol is valid for strings, but bool, hex, and INT are always defined.
189# #if defined(symbol) && symbol is also a valid construct.
190#-------------------------------------------------------------------------------
191sub check_for_ifdef {
192 my @ifdef_symbols = @collected_symbols;
193
194 #look for #ifdef SYMBOL
195 while ( my $line = shift @ifdef_symbols ) {
Julius Werneref7a3262019-03-05 16:57:52 -0800196 if ( $line =~ /^([^:]+):(\d+):\s*#\s*ifn?def\s*\(?\s*CONFIG(?:_|\()(\w+)/ ) {
Martin Roth5b883012017-06-25 20:27:36 -0600197 my $file = $1;
198 my $lineno = $2;
199 my $symbol = $3;
200
201 if ( ( exists $symbols{$symbol} ) && ( $symbols{$symbol}{type} ne "string" ) ) {
Julius Wernere5eb2de2019-03-05 17:10:19 -0800202 show_error( "#ifdef 'CONFIG_$symbol' used at $file:$lineno."
Martin Roth5b883012017-06-25 20:27:36 -0600203 . " Symbols of type '$symbols{$symbol}{type}' are always defined." );
204 }
Julius Wernere5eb2de2019-03-05 17:10:19 -0800205 } elsif ( $line =~ /^([^:]+):(\d+):.+defined\s*\(?\s*CONFIG(?:_|\()(\w+)/ ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -0700206 my $file = $1;
Martin Rothbcaaad12015-10-18 11:16:25 -0600207 my $lineno = $2;
208 my $symbol = $3;
209
Martin Roth1b44f7e2016-01-11 14:31:38 -0700210 if ( ( exists $symbols{$symbol} ) && ( $symbols{$symbol}{type} ne "string" ) ) {
Julius Wernere5eb2de2019-03-05 17:10:19 -0800211 show_error( "defined(CONFIG_$symbol) used at $file:$lineno."
Martin Roth1b44f7e2016-01-11 14:31:38 -0700212 . " Symbols of type '$symbols{$symbol}{type}' are always defined." );
Martin Rothbcaaad12015-10-18 11:16:25 -0600213 }
214 }
215 }
216}
217
218#-------------------------------------------------------------------------------
219# check_for_def - Look for instances of #define CONFIG_[symbol_name]
220#
221# Symbols should not be redefined outside of Kconfig, and #defines should not
222# look like symbols
223#-------------------------------------------------------------------------------
224sub check_for_def {
225 my @def_symbols = @collected_symbols;
226
227 #look for #ifdef SYMBOL
228 while ( my $line = shift @def_symbols ) {
229 if ( $line =~ /^([^:]+):(\d+):\s*#\s*define\s+CONFIG_(\w+)/ ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -0700230 my $file = $1;
Martin Rothbcaaad12015-10-18 11:16:25 -0600231 my $lineno = $2;
232 my $symbol = $3;
233
Martin Roth1b44f7e2016-01-11 14:31:38 -0700234 if ( ( exists $symbols{$symbol} ) ) {
Julius Wernere5eb2de2019-03-05 17:10:19 -0800235 show_error("#define of symbol 'CONFIG_$symbol' used at $file:$lineno.");
Martin Roth1b44f7e2016-01-11 14:31:38 -0700236 }
237 else {
Julius Wernere5eb2de2019-03-05 17:10:19 -0800238 show_error( "#define 'CONFIG_$symbol' used at $file:$lineno."
Martin Roth1b44f7e2016-01-11 14:31:38 -0700239 . " Other #defines should not look like Kconfig symbols." );
240 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600241 }
242 }
243}
244
245#-------------------------------------------------------------------------------
Martin Roth08705f12016-11-09 14:27:00 -0700246# check_type - Make sure that all symbols have a type defined.
247#
248# Conflicting types are found when parsing the Kconfig tree.
249#-------------------------------------------------------------------------------
250sub check_type {
251
252 # loop through each defined symbol
253 foreach my $sym ( sort ( keys %symbols ) ) {
254
255 # Make sure there's a type set for the symbol
256 if (!defined $symbols{$sym}{type}) {
257
258 #loop through each instance of that symbol
259 for ( my $sym_num = 0 ; $sym_num <= $symbols{$sym}{count} ; $sym_num++ ) {
260
261 my $filename = $symbols{$sym}{$sym_num}{file};
262 my $line_no = $symbols{$sym}{$sym_num}{line_no};
263
264 show_error("No type defined for symbol $sym defined at $filename:$line_no.");
265 }
266 }
267 }
268}
269
270#-------------------------------------------------------------------------------
Nico Huberec017592019-04-06 16:09:46 +0200271# check_config_macro - The CONFIG() macro is only valid for symbols of type
272# bool. It would probably work on type hex or int if the value was 0 or 1,
273# but this seems like a bad plan. Using it on strings is dead out.
274#
275# The IS_ENABLED() macro is forbidden in coreboot now. Though, as long as
276# we keep its definition in libpayload for compatibility, we have to check
277# that it doesn't sneak back in.
Martin Rothbcaaad12015-10-18 11:16:25 -0600278#-------------------------------------------------------------------------------
Nico Huberec017592019-04-06 16:09:46 +0200279sub check_config_macro {
Martin Rothb6acc302015-11-27 18:51:19 -0700280 my @is_enabled_symbols = @collected_symbols;
Martin Rothbcaaad12015-10-18 11:16:25 -0600281
282 #sort through symbols found by grep and store them in a hash for easy access
283 while ( my $line = shift @is_enabled_symbols ) {
Julius Werneref7a3262019-03-05 16:57:52 -0800284 if ( $line =~ /^([^:]+):(\d+):(.+\bCONFIG\(.*)/ ) {
285 my $file = $1;
286 my $lineno = $2;
287 $line = $3;
288 while ( $line =~ /(.*)\bCONFIG\(([^)]*)\)(.*)/ ) {
289 my $symbol = $2;
290 $line = $1 . $3;
291
292 #make sure that the type is bool
293 if ( exists $symbols{$symbol} ) {
294 if ( $symbols{$symbol}{type} ne "bool" ) {
295 show_error( "CONFIG($symbol) used at $file:$lineno."
296 . " CONFIG() is only valid for type 'bool', not '$symbols{$symbol}{type}'." );
297 }
298 }
299 else {
Julius Wernerf0286042019-04-09 15:57:07 -0700300 show_error("CONFIG() used on unknown value ($symbol) at $file:$lineno.");
Julius Werneref7a3262019-03-05 16:57:52 -0800301 }
302 }
303 } elsif ( $line =~ /^([^:]+):(\d+):(.+IS_ENABLED.*)/ ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -0700304 my $file = $1;
Martin Rothbcaaad12015-10-18 11:16:25 -0600305 my $lineno = $2;
Martin Rothb6acc302015-11-27 18:51:19 -0700306 $line = $3;
Martin Roth572a8562016-01-25 16:14:09 -0700307 if ( ( $line !~ /(.*)IS_ENABLED\s*\(\s*CONFIG_(\w+)(.*)/ ) && ( $line !~ /(\/[\*\/])(.*)IS_ENABLED/ ) ) {
Nico Huberec017592019-04-06 16:09:46 +0200308 show_error("# uninterpreted IS_ENABLED at $file:$lineno: $line");
Martin Rothb6acc302015-11-27 18:51:19 -0700309 next;
Martin Rothbcaaad12015-10-18 11:16:25 -0600310 }
Martin Rothb6acc302015-11-27 18:51:19 -0700311 while ( $line =~ /(.*)IS_ENABLED\s*\(\s*CONFIG_(\w+)(.*)/ ) {
312 my $symbol = $2;
Martin Roth1b44f7e2016-01-11 14:31:38 -0700313 $line = $1 . $3;
Nico Huberec017592019-04-06 16:09:46 +0200314 show_error("IS_ENABLED(CONFIG_$symbol) at $file:$lineno is deprecated. Use CONFIG($symbol) instead.");
Martin Rothb6acc302015-11-27 18:51:19 -0700315 }
Martin Roth5b883012017-06-25 20:27:36 -0600316 } elsif ( $line =~ /^([^:]+):(\d+):\s*#\s*(?:el)?if\s+!?\s*\(?\s*CONFIG_(\w+)\)?(\s*==\s*1)?.*?$/ ) {
317 my $file = $1;
318 my $lineno = $2;
319 my $symbol = $3;
Nico Huberec017592019-04-06 16:09:46 +0200320 # If the type is bool, give a warning that CONFIG() should be used
Martin Roth5b883012017-06-25 20:27:36 -0600321 if ( exists $symbols{$symbol} ) {
322 if ( $symbols{$symbol}{type} eq "bool" ) {
323 show_error( "#if CONFIG_$symbol used at $file:$lineno."
Julius Werneref7a3262019-03-05 16:57:52 -0800324 . " CONFIG($symbol) should be used for type 'bool'" );
Martin Roth5b883012017-06-25 20:27:36 -0600325 }
326 }
Julius Werneref7a3262019-03-05 16:57:52 -0800327 } elsif ( $line =~ /^([^:]+):(\d+):\s*#\s*(?:el)?if.*(?:&&|\|\|)\s+!?\s*\(?\s*CONFIG_(\w+)\)?(\s*==\s*1)?$/ ) {
Martin Roth5b883012017-06-25 20:27:36 -0600328 my $file = $1;
329 my $lineno = $2;
330 my $symbol = $3;
Nico Huberec017592019-04-06 16:09:46 +0200331 # If the type is bool, give a warning that CONFIG() should be used
Martin Roth5b883012017-06-25 20:27:36 -0600332 if ( exists $symbols{$symbol} ) {
333 if ( $symbols{$symbol}{type} eq "bool" ) {
334 show_error( "#if CONFIG_$symbol used at $file:$lineno."
Julius Werneref7a3262019-03-05 16:57:52 -0800335 . " CONFIG($symbol) should be used for type 'bool'" );
Martin Roth5b883012017-06-25 20:27:36 -0600336 }
337 }
Julius Wernere5eb2de2019-03-05 17:10:19 -0800338 } elsif ( $line =~ /^([^:]+):(\d+):(.+\bCONFIG_.+)/ ) {
339 my $file = $1;
340 my $lineno = $2;
341 $line = $3;
342 if ( $file =~ /.*\.(c|h|asl|ld)/ ) {
343 while ( $line =~ /(.*)\bCONFIG_(\w+)(.*)/ && $1 !~ /\/\/|\/\*/ ) {
344 my $symbol = $2;
345 $line = $1 . $3;
346 if ( exists $symbols{$symbol} ) {
347 if ( $symbols{$symbol}{type} eq "bool" ) {
348 show_warning( "Naked reference to CONFIG_$symbol used at $file:$lineno."
349 . " A 'bool' Kconfig should always be accessed through CONFIG($symbol)." );
350 }
351 } else {
352 show_warning( "Unknown config option CONFIG_$symbol used at $file:$lineno." );
353 }
354 }
355 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600356 }
357 }
358}
359
360#-------------------------------------------------------------------------------
361# check_defaults - Look for defaults that come after a default with no
362# dependencies.
363#
364# TODO - check for defaults with the same dependencies
365#-------------------------------------------------------------------------------
366sub check_defaults {
367
368 # loop through each defined symbol
369 foreach my $sym ( sort ( keys %symbols ) ) {
370 my $default_set = 0;
371 my $default_filename = "";
372 my $default_line_no = "";
373
374 #loop through each instance of that symbol
375 for ( my $sym_num = 0 ; $sym_num <= $symbols{$sym}{count} ; $sym_num++ ) {
376
377 #loop through any defaults for that instance of that symbol, if there are any
378 next unless ( exists $symbols{$sym}{$sym_num}{default_max} );
379 for ( my $def_num = 0 ; $def_num <= $symbols{$sym}{$sym_num}{default_max} ; $def_num++ ) {
380
Martin Rothfa956252016-09-30 15:51:32 -0600381 my $filename = $symbols{$sym}{$sym_num}{file};
382 my $line_no = $symbols{$sym}{$sym_num}{default}{$def_num}{default_line_no};
383
Martin Roth08705f12016-11-09 14:27:00 -0700384 # Make sure there's a type set for the symbol
385 next if (!defined $symbols{$sym}{type});
386
Martin Rothfa956252016-09-30 15:51:32 -0600387 # skip good defaults
388 if (! ((($symbols{$sym}{type} eq "hex") && ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /^0x/)) ||
389 (($symbols{$sym}{type} eq "int") && ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /^[-0-9]+$/)) ||
390 (($symbols{$sym}{type} eq "string") && ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /^".*"$/)) ||
391 (($symbols{$sym}{type} eq "bool") && ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /^[yn]$/)))
392 ) {
393
394 my ($checksym) = $symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /(\w+)/;
395
396 if (! exists $symbols{$checksym}) {
397
398 # verify the symbol type against the default value
399 if ($symbols{$sym}{type} eq "hex") {
400 show_error("non hex default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) used for hex symbol $sym at $filename:$line_no.");
401 } elsif ($symbols{$sym}{type} eq "int") {
402 show_error("non int default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) used for int symbol $sym at $filename:$line_no.");
403 } elsif ($symbols{$sym}{type} eq "string") {
404 # TODO: Remove special MAINBOARD_DIR check
405 if ($sym ne "MAINBOARD_DIR") {
406 show_error("no quotes around default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) used for string symbol $sym at $filename:$line_no.");
407 }
408 } elsif ($symbols{$sym}{type} eq "bool") {
409 if ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /[01YN]/) {
Julius Wernere5eb2de2019-03-05 17:10:19 -0800410 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 -0600411 } else {
412 show_error("non bool default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) used for bool symbol $sym at $filename:$line_no.");
413 }
414 }
415 }
416 }
417
Martin Rothbcaaad12015-10-18 11:16:25 -0600418 #if a default is already set, display an error
419 if ($default_set) {
Julius Wernere5eb2de2019-03-05 17:10:19 -0800420 show_error( "Default for '$sym' referenced at $filename:$line_no will never be set"
Martin Roth1b44f7e2016-01-11 14:31:38 -0700421 . " - overridden by default set at $default_filename:$default_line_no" );
Martin Rothbcaaad12015-10-18 11:16:25 -0600422 }
423 else {
424 #if no default is set, see if this is a default with no dependencies
425 unless ( ( exists $symbols{$sym}{$sym_num}{default}{$def_num}{default_depends_on} )
426 || ( exists $symbols{$sym}{$sym_num}{max_dependency} ) )
427 {
428 $default_set = 1;
429 $default_filename = $symbols{$sym}{$sym_num}{file};
430 $default_line_no = $symbols{$sym}{$sym_num}{default}{$def_num}{default_line_no};
431 }
432 }
433 }
434 }
435 }
436}
437
438#-------------------------------------------------------------------------------
439# check_referenced_symbols - Make sure the symbols referenced by expressions and
440# select statements are actually valid symbols.
441#-------------------------------------------------------------------------------
442sub check_referenced_symbols {
443
444 #loop through symbols found in expressions and used by 'select' keywords
445 foreach my $key ( sort ( keys %referenced_symbols ) ) {
446
447 #make sure the symbol was defined by a 'config' or 'choice' keyword
448 next if ( exists $symbols{$key} );
449
Martin Rothd8080172015-11-26 19:12:44 -0700450 #loop through each instance of the symbol to print out all of the invalid references
451 for ( my $i = 0 ; $i <= $referenced_symbols{$key}{count} ; $i++ ) {
452 my $filename = $referenced_symbols{$key}{$i}{filename};
453 my $line_no = $referenced_symbols{$key}{$i}{line_no};
Martin Roth7aa3cea2015-11-27 18:45:45 -0700454 show_error("Undefined Symbol '$key' used at $filename:$line_no.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600455 }
456 }
457}
458
459#-------------------------------------------------------------------------------
460#-------------------------------------------------------------------------------
461sub collect_used_symbols {
462 # find all references to CONFIG_ statements in the tree
463
464 if ($dont_use_git_grep) {
Julius Werneref7a3262019-03-05 16:57:52 -0800465 @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 -0700466 }
467 else {
Julius Werneref7a3262019-03-05 16:57:52 -0800468 @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 -0600469 }
470
471 my @used_symbols = @collected_symbols;
472
473 #sort through symbols found by grep and store them in a hash for easy access
474 while ( my $line = shift @used_symbols ) {
Julius Werneref7a3262019-03-05 16:57:52 -0800475 while ( $line =~ /[^A-Za-z0-9_]CONFIG(?:_|\()([A-Za-z0-9_]+)/g ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -0700476 my $symbol = $1;
Martin Rothbcaaad12015-10-18 11:16:25 -0600477 my $filename = "";
Martin Roth1b44f7e2016-01-11 14:31:38 -0700478 if ( $line =~ /^([^:]+):/ ) {
Martin Rothbcaaad12015-10-18 11:16:25 -0600479 $filename = $1;
480 }
481
Martin Roth1b44f7e2016-01-11 14:31:38 -0700482 if ( exists $used_symbols{$symbol}{count} ) {
Martin Rothbcaaad12015-10-18 11:16:25 -0600483 $used_symbols{$symbol}{count}++;
Martin Roth1b44f7e2016-01-11 14:31:38 -0700484 }
485 else {
486 $used_symbols{$symbol}{count} = 0;
Martin Rothbcaaad12015-10-18 11:16:25 -0600487 }
488 $used_symbols{$symbol}{"num_$used_symbols{$symbol}{count}"} = $filename;
Martin Roth1b44f7e2016-01-11 14:31:38 -0700489 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600490 }
491}
492
493#-------------------------------------------------------------------------------
494# check_used_symbols - Checks to see whether or not the created symbols are
495# actually used.
496#-------------------------------------------------------------------------------
497sub check_used_symbols {
498 # loop through all defined symbols and see if they're used anywhere
499 foreach my $key ( sort ( keys %symbols ) ) {
500
Martin Roth6bfbf1c2016-01-25 16:12:49 -0700501 if ( $key =~ /$exclude_unused/ ) {
502 next;
503 }
504
Martin Rothbcaaad12015-10-18 11:16:25 -0600505 #see if they're used internal to Kconfig
506 next if ( exists $referenced_symbols{$key} );
507
508 #see if they're used externally
509 next if exists $used_symbols{$key};
510
511 #loop through the definitions to print out all the places the symbol is defined.
512 for ( my $i = 0 ; $i <= $symbols{$key}{count} ; $i++ ) {
513 my $filename = $symbols{$key}{$i}{file};
514 my $line_no = $symbols{$key}{$i}{line_no};
Martin Rotha7d00272016-10-03 23:00:04 +0200515 show_warning("Unused symbol '$key' referenced at $filename:$line_no.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600516 }
517 }
518}
519
520#-------------------------------------------------------------------------------
521# build_and_parse_kconfig_tree
522#-------------------------------------------------------------------------------
523#load the initial file and start parsing it
524sub build_and_parse_kconfig_tree {
525 my ($top_level_kconfig) = @_;
526 my @config_to_parse;
527 my @parseline;
528 my $inside_help = 0; # set to line number of 'help' keyword if this line is inside a help block
529 my @inside_if = (); # stack of if dependencies
530 my $inside_config = ""; # set to symbol name of the config section
531 my @inside_menu = (); # stack of menu names
532 my $inside_choice = "";
Patrick Georgicbc5b992018-11-23 15:55:56 +0100533 my $choice_symbol = "";
Martin Rothbcaaad12015-10-18 11:16:25 -0600534 my $configs_inside_choice;
Martin Roth0e6c0e12016-03-02 12:16:13 -0700535 my %fileinfo;
Martin Rothbcaaad12015-10-18 11:16:25 -0600536
537 #start the tree off by loading the top level kconfig
538 @config_to_parse = load_kconfig_file( $top_level_kconfig, "", 0, 0, "", 0 );
539
Martin Rothbcaaad12015-10-18 11:16:25 -0600540 while ( ( @parseline = shift(@config_to_parse) ) && ( exists $parseline[0]{text} ) ) {
541 my $line = $parseline[0]{text};
542 my $filename = $parseline[0]{filename};
543 my $line_no = $parseline[0]{file_line_no};
544
545 #handle help - help text: "help" or "---help---"
Martin Roth811d93a2017-04-06 11:06:00 -0600546 my $lastline_was_help = $inside_help;
Martin Rothbcaaad12015-10-18 11:16:25 -0600547 $inside_help = handle_help( $line, $inside_help, $inside_config, $inside_choice, $filename, $line_no );
548 $parseline[0]{inside_help} = $inside_help;
549
550 #look for basic issues in the line, strip crlf
551 $line = simple_line_checks( $line, $filename, $line_no );
552
553 #strip comments
554 $line =~ s/\s*#.*$//;
555
556 #don't parse any more if we're inside a help block
557 if ($inside_help) {
558 #do nothing
559 }
560
561 #handle config
Martin Roth811d93a2017-04-06 11:06:00 -0600562 elsif ( $line =~ /^\s*config\s+/ ) {
Martin Rothbcaaad12015-10-18 11:16:25 -0600563 $line =~ /^\s*config\s+([^"\s]+)\s*(?>#.*)?$/;
564 my $symbol = $1;
565 $inside_config = $symbol;
566 if ($inside_choice) {
567 $configs_inside_choice++;
568 }
Martin Rothb7c39b22016-01-14 09:04:53 -0700569 add_symbol( $symbol, \@inside_menu, $filename, $line_no, \@inside_if, $inside_choice );
Martin Rothbcaaad12015-10-18 11:16:25 -0600570 }
571
572 #bool|hex|int|string|tristate <expr> [if <expr>]
573 elsif ( $line =~ /^\s*(bool|string|hex|int|tristate)/ ) {
574 $line =~ /^\s*(bool|string|hex|int|tristate)\s*(.*)/;
575 my ( $type, $prompt ) = ( $1, $2 );
576 handle_type( $type, $inside_config, $filename, $line_no );
577 handle_prompt( $prompt, $type, \@inside_menu, $inside_config, $inside_choice, $filename, $line_no );
578 }
579
580 # def_bool|def_tristate <expr> [if <expr>]
581 elsif ( $line =~ /^\s*(def_bool|def_tristate)/ ) {
582 $line =~ /^\s*(def_bool|def_tristate)\s+(.*)/;
583 my ( $orgtype, $default ) = ( $1, $2 );
584 ( my $type = $orgtype ) =~ s/def_//;
585 handle_type( $type, $inside_config, $filename, $line_no );
586 handle_default( $default, $orgtype, $inside_config, $inside_choice, $filename, $line_no );
587 }
588
589 #prompt <prompt> [if <expr>]
590 elsif ( $line =~ /^\s*prompt/ ) {
591 $line =~ /^\s*prompt\s+(.+)/;
592 handle_prompt( $1, "prompt", \@inside_menu, $inside_config, $inside_choice, $filename, $line_no );
593 }
594
595 # default <expr> [if <expr>]
596 elsif ( $line =~ /^\s*default/ ) {
597 $line =~ /^\s*default\s+(.*)/;
598 my $default = $1;
599 handle_default( $default, "default", $inside_config, $inside_choice, $filename, $line_no );
600 }
601
602 # depends on <expr>
603 elsif ( $line =~ /^\s*depends\s+on/ ) {
604 $line =~ /^\s*depends\s+on\s+(.*)$/;
605 my $expr = $1;
606 handle_depends( $expr, $inside_config, $inside_choice, $filename, $line_no );
607 handle_expressions( $expr, $inside_config, $filename, $line_no );
608 }
609
610 # comment <prompt>
611 elsif ( $line =~ /^\s*comment/ ) {
612 $inside_config = "";
613 }
614
615 # choice [symbol]
616 elsif ( $line =~ /^\s*choice/ ) {
617 if ( $line =~ /^\s*choice\s*([A-Za-z0-9_]+)$/ ) {
618 my $symbol = $1;
619 add_symbol( $symbol, \@inside_menu, $filename, $line_no, \@inside_if );
620 handle_type( "bool", $symbol, $filename, $line_no );
Patrick Georgicbc5b992018-11-23 15:55:56 +0100621 $choice_symbol = $symbol;
Martin Rothbcaaad12015-10-18 11:16:25 -0600622 }
623 $inside_config = "";
624 $inside_choice = "$filename $line_no";
625 $configs_inside_choice = 0;
Martin Roth08cf90f2016-01-25 19:54:16 -0700626
627 # Kconfig verifies that choice blocks have a prompt
Martin Rothbcaaad12015-10-18 11:16:25 -0600628 }
629
630 # endchoice
631 elsif ( $line =~ /^\s*endchoice/ ) {
632 $inside_config = "";
633 if ( !$inside_choice ) {
Martin Roth7aa3cea2015-11-27 18:45:45 -0700634 show_error("'endchoice' keyword not within a choice block at $filename:$line_no.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600635 }
636
637 $inside_choice = "";
Patrick Georgicbc5b992018-11-23 15:55:56 +0100638 if (( $configs_inside_choice == 0 ) &&
639 ( $choice_symbol eq "" )) {
640 show_error("unnamed choice block has no symbols at $filename:$line_no.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600641 }
642 $configs_inside_choice = 0;
Patrick Georgicbc5b992018-11-23 15:55:56 +0100643 $choice_symbol="";
Martin Rothbcaaad12015-10-18 11:16:25 -0600644 }
645
646 # [optional]
647 elsif ( $line =~ /^\s*optional/ ) {
648 if ($inside_config) {
Martin Roth1b44f7e2016-01-11 14:31:38 -0700649 show_error( "Keyword 'optional' appears inside config for '$inside_config'"
650 . " at $filename:$line_no. This is not valid." );
Martin Rothbcaaad12015-10-18 11:16:25 -0600651 }
652 if ( !$inside_choice ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -0700653 show_error( "Keyword 'optional' appears outside of a choice block"
654 . " at $filename:$line_no. This is not valid." );
Martin Rothbcaaad12015-10-18 11:16:25 -0600655 }
656 }
657
658 # mainmenu <prompt>
659 elsif ( $line =~ /^\s*mainmenu/ ) {
660 $inside_config = "";
Martin Roth08cf90f2016-01-25 19:54:16 -0700661
662 # Kconfig alread checks for multiple 'mainmenu' entries and mainmenu entries with no prompt
663 # Possible check: look for 'mainmenu ""'
664 # Possible check: verify that a mainmenu has been specified
Martin Rothbcaaad12015-10-18 11:16:25 -0600665 }
666
667 # menu <prompt>
668 elsif ( $line =~ /^\s*menu/ ) {
669 $line =~ /^\s*menu\s+(.*)/;
670 my $menu = $1;
671 if ( $menu =~ /^\s*"([^"]*)"\s*$/ ) {
672 $menu = $1;
673 }
674
675 $inside_config = "";
676 $inside_choice = "";
677 push( @inside_menu, $menu );
678 }
679
Patrick Georgifcc29502018-09-16 21:35:46 +0200680 # visible if <expr>
681 elsif ( $line =~ /^\s*visible if.*$/ ) {
Julius Werneref7a3262019-03-05 16:57:52 -0800682 # Must come directly after menu line (and on a separate line)
683 # but kconfig already checks for that.
684 # Ignore it.
Patrick Georgifcc29502018-09-16 21:35:46 +0200685 }
686
Martin Rothbcaaad12015-10-18 11:16:25 -0600687 # endmenu
688 elsif ( $line =~ /^\s*endmenu/ ) {
689 $inside_config = "";
690 $inside_choice = "";
691 pop @inside_menu;
692 }
693
694 # "if" <expr>
695 elsif ( $line =~ /^\s*if/ ) {
696 $inside_config = "";
697 $line =~ /^\s*if\s+(.*)$/;
698 my $expr = $1;
699 push( @inside_if, $expr );
700 handle_expressions( $expr, $inside_config, $filename, $line_no );
Martin Roth0e6c0e12016-03-02 12:16:13 -0700701 $fileinfo{$filename}{iflevel}++;
Martin Rothbcaaad12015-10-18 11:16:25 -0600702 }
703
704 # endif
705 elsif ( $line =~ /^\s*endif/ ) {
706 $inside_config = "";
707 pop(@inside_if);
Martin Roth0e6c0e12016-03-02 12:16:13 -0700708 $fileinfo{$filename}{iflevel}--;
Martin Rothbcaaad12015-10-18 11:16:25 -0600709 }
710
711 #range <symbol> <symbol> [if <expr>]
712 elsif ( $line =~ /^\s*range/ ) {
713 $line =~ /^\s*range\s+(\S+)\s+(.*)$/;
714 handle_range( $1, $2, $inside_config, $filename, $line_no );
715 }
716
717 # select <symbol> [if <expr>]
718 elsif ( $line =~ /^\s*select/ ) {
719 unless ($inside_config) {
Martin Roth7aa3cea2015-11-27 18:45:45 -0700720 show_error("Keyword 'select' appears outside of config at $filename:$line_no. This is not valid.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600721 }
722
723 if ( $line =~ /^\s*select\s+(.*)$/ ) {
724 $line = $1;
725 my $expression;
726 ( $line, $expression ) = handle_if_line( $line, $inside_config, $filename, $line_no );
727 if ($line) {
Martin Rothb7c39b22016-01-14 09:04:53 -0700728 add_referenced_symbol( $line, $filename, $line_no, 'select' );
Martin Rothbcaaad12015-10-18 11:16:25 -0600729 }
730 }
731 }
732
733 # source <prompt>
734 elsif ( $line =~ /^\s*source\s+"?([^"\s]+)"?\s*(?>#.*)?$/ ) {
735 my @newfile = load_kconfig_file( $1, $filename, $line_no, 0, $filename, $line_no );
736 unshift( @config_to_parse, @newfile );
737 $parseline[0]{text} = "# '$line'\n";
738 }
739 elsif (
740 ( $line =~ /^\s*#/ ) || #comments
741 ( $line =~ /^\s*$/ ) #blank lines
742 )
743 {
744 # do nothing
745 }
746 else {
Martin Roth811d93a2017-04-06 11:06:00 -0600747 if ($lastline_was_help) {
748 show_error("The line \"$line\" ($filename:$line_no) wasn't recognized - supposed to be inside help?");
749 }
750 else {
751 show_error("The line \"$line\" ($filename:$line_no) wasn't recognized");
752 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600753 }
754
Martin Roth819e6722016-01-25 16:38:05 -0700755 if ( defined $inside_menu[0] ) {
756 $parseline[0]{menus} = "";
757 }
758 else {
759 $parseline[0]{menus} = "top";
760 }
761
762 my $i = 0;
763 while ( defined $inside_menu[$i] ) {
764 $parseline[0]{menus} .= "$inside_menu[$i]";
765 $i++;
766 if ( defined $inside_menu[$i] ) {
767 $parseline[0]{menus} .= "->";
768 }
769 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600770 push @wholeconfig, @parseline;
771 }
Martin Roth0e6c0e12016-03-02 12:16:13 -0700772
773 foreach my $file ( keys %fileinfo ) {
774 if ( $fileinfo{$file}{iflevel} > 0 ) {
775 show_error("$file has $fileinfo{$file}{iflevel} more 'if' statement(s) than 'endif' statements.");
776 }
777 elsif ( $fileinfo{$file}{iflevel} < 0 ) {
778 show_error(
779 "$file has " . ( $fileinfo{$file}{iflevel} * -1 ) . " more 'endif' statement(s) than 'if' statements." );
780 }
781 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600782}
783
784#-------------------------------------------------------------------------------
785#-------------------------------------------------------------------------------
786sub handle_depends {
787 my ( $expr, $inside_config, $inside_choice, $filename, $line_no ) = @_;
788
789 if ($inside_config) {
790 my $sym_num = $symbols{$inside_config}{count};
791 if ( exists $symbols{$inside_config}{$sym_num}{max_dependency} ) {
792 $symbols{$inside_config}{$sym_num}{max_dependency}++;
793 }
794 else {
795 $symbols{$inside_config}{$sym_num}{max_dependency} = 0;
796 }
797
798 my $dep_num = $symbols{$inside_config}{$sym_num}{max_dependency};
799 $symbols{$inside_config}{$sym_num}{dependency}{$dep_num} = $expr;
800 }
801}
802
803#-------------------------------------------------------------------------------
804#-------------------------------------------------------------------------------
805sub add_symbol {
Martin Rothb7c39b22016-01-14 09:04:53 -0700806 my ( $symbol, $menu_array_ref, $filename, $line_no, $ifref, $inside_choice ) = @_;
Martin Rothbcaaad12015-10-18 11:16:25 -0600807 my @inside_if = @{$ifref};
808
809 #initialize the symbol or increment the use count.
Martin Roth1b44f7e2016-01-11 14:31:38 -0700810 if ( ( !exists $symbols{$symbol} ) || ( !exists $symbols{$symbol}{count} ) ) {
Martin Rothbcaaad12015-10-18 11:16:25 -0600811 $symbols{$symbol}{count} = 0;
Martin Rothb7c39b22016-01-14 09:04:53 -0700812 if ($inside_choice) {
813 $symbols{$symbol}{choice} = 1;
814 }
815 else {
816 $symbols{$symbol}{choice} = 0;
817 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600818 }
819 else {
820 $symbols{$symbol}{count}++;
Martin Rothb7c39b22016-01-14 09:04:53 -0700821
822 if ( $inside_choice && !$symbols{$symbol}{choice} ) {
823 show_error( "$symbol entry at $filename:$line_no has already been created inside a choice block "
824 . "at $symbols{$symbol}{0}{file}:$symbols{$symbol}{0}{line_no}." );
825 }
826 elsif ( !$inside_choice && $symbols{$symbol}{choice} ) {
827 show_error( "$symbol entry at $filename:$line_no has already been created outside a choice block "
828 . "at $symbols{$symbol}{0}{file}:$symbols{$symbol}{0}{line_no}." );
829 }
Martin Rothaa206472017-03-24 08:51:51 -0600830 elsif ( $inside_choice && $symbols{$symbol}{choice} ) {
831 show_error( "$symbol entry at $filename:$line_no has already been created inside another choice block "
832 . "at $symbols{$symbol}{0}{file}:$symbols{$symbol}{0}{line_no}." );
833 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600834 }
835
836 # add the location of this instance
837 my $symcount = $symbols{$symbol}{count};
838 $symbols{$symbol}{$symcount}{file} = $filename;
839 $symbols{$symbol}{$symcount}{line_no} = $line_no;
840
841 #Add the menu structure
842 if ( defined @$menu_array_ref[0] ) {
843 $symbols{$symbol}{$symcount}{menu} = $menu_array_ref;
844 }
845
846 #Add any 'if' statements that the symbol is inside as dependencies
847 if (@inside_if) {
848 my $dep_num = 0;
849 for my $dependency (@inside_if) {
850 $symbols{$symbol}{$symcount}{dependency}{$dep_num} = $dependency;
851 $symbols{$symbol}{$symcount}{max_dependency} = $dep_num;
852 $dep_num++;
853 }
854 }
855}
856
857#-------------------------------------------------------------------------------
858# handle range
859#-------------------------------------------------------------------------------
860sub handle_range {
861 my ( $range1, $range2, $inside_config, $filename, $line_no ) = @_;
862
863 my $expression;
864 ( $range2, $expression ) = handle_if_line( $range2, $inside_config, $filename, $line_no );
865
866 $range1 =~ /^\s*(?:0x)?([A-Fa-f0-9]+)\s*$/;
867 my $checkrange1 = $1;
868 $range2 =~ /^\s*(?:0x)?([A-Fa-f0-9]+)\s*$/;
869 my $checkrange2 = $1;
870
871 if ( $checkrange1 && $checkrange2 && ( hex($checkrange1) > hex($checkrange2) ) ) {
Martin Rothd8080172015-11-26 19:12:44 -0700872 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 -0600873 }
874
875 if ($inside_config) {
876 if ( exists( $symbols{$inside_config}{range1} ) ) {
877 if ( ( $symbols{$inside_config}{range1} != $range1 ) || ( $symbols{$inside_config}{range2} != $range2 ) ) {
Martin Rothd8080172015-11-26 19:12:44 -0700878 if ($show_note_output) {
Martin Roth7aa3cea2015-11-27 18:45:45 -0700879 print "#!!!!! Note: Config '$inside_config' range entry $range1 $range2 at $filename:$line_no does";
Martin Roth1b44f7e2016-01-11 14:31:38 -0700880 print " not match the previously defined range $symbols{$inside_config}{range1}"
881 . " $symbols{$inside_config}{range2}";
Martin Roth7aa3cea2015-11-27 18:45:45 -0700882 print " defined at $symbols{$inside_config}{range_file}:$symbols{$inside_config}{range_line_no}.\n";
Martin Rothbcaaad12015-10-18 11:16:25 -0600883 }
884 }
885 }
886 else {
887 $symbols{$inside_config}{range1} = $range1;
888 $symbols{$inside_config}{range2} = $range2;
889 $symbols{$inside_config}{range_file} = $filename;
890 $symbols{$inside_config}{range_line_no} = $line_no;
891 }
892 }
893 else {
Martin Roth7aa3cea2015-11-27 18:45:45 -0700894 show_error("Range entry at $filename:$line_no is not inside a config block.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600895 }
896}
897
898#-------------------------------------------------------------------------------
899# handle_default
900#-------------------------------------------------------------------------------
901sub handle_default {
902 my ( $default, $name, $inside_config, $inside_choice, $filename, $line_no ) = @_;
903 my $expression;
904 ( $default, $expression ) = handle_if_line( $default, $inside_config, $filename, $line_no );
905
906 if ($inside_config) {
907 handle_expressions( $default, $inside_config, $filename, $line_no );
908 my $sym_num = $symbols{$inside_config}{count};
909
910 unless ( exists $symbols{$inside_config}{$sym_num}{default_max} ) {
911 $symbols{$inside_config}{$sym_num}{default_max} = 0;
912 }
913 my $default_max = $symbols{$inside_config}{$sym_num}{default_max};
914 $symbols{$inside_config}{$sym_num}{default}{$default_max}{default} = $default;
915 $symbols{$inside_config}{$sym_num}{default}{$default_max}{default_line_no} = $line_no;
916 if ($expression) {
917 $symbols{$inside_config}{$sym_num}{default}{$default_max}{default_depends_on} = $expression;
918 }
919 }
920 elsif ($inside_choice) {
921 handle_expressions( $default, $inside_config, $filename, $line_no );
922 }
923 else {
Martin Roth7aa3cea2015-11-27 18:45:45 -0700924 show_error("$name entry at $filename:$line_no is not inside a config or choice block.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600925 }
926}
927
928#-------------------------------------------------------------------------------
929# handle_if_line
930#-------------------------------------------------------------------------------
931sub handle_if_line {
932 my ( $exprline, $inside_config, $filename, $line_no ) = @_;
933
934 if ( $exprline !~ /if/ ) {
935 return ( $exprline, "" );
936 }
937
938 #remove any quotes that might have an 'if' in them
939 my $savequote;
940 if ( $exprline =~ /^\s*("[^"]+")/ ) {
941 $savequote = $1;
942 $exprline =~ s/^\s*("[^"]+")//;
943 }
944
945 my $expr = "";
946 if ( $exprline =~ /\s*if\s+(.*)$/ ) {
947 $expr = $1;
948 $exprline =~ s/\s*if\s+.*$//;
949
950 if ($expr) {
951 handle_expressions( $expr, $inside_config, $filename, $line_no );
952 }
953 }
954
955 if ($savequote) {
956 $exprline = $savequote;
957 }
958
959 return ( $exprline, $expr );
960}
961
962#-------------------------------------------------------------------------------
963# handle_expressions - log which symbols are being used
964#-------------------------------------------------------------------------------
965sub handle_expressions {
966 my ( $exprline, $inside_config, $filename, $line_no ) = @_;
967
968 return unless ($exprline);
969
970 #filter constant symbols first
Martin Roth1b44f7e2016-01-11 14:31:38 -0700971 if ( $exprline =~ /^\s*"?([yn])"?\s*$/ ) { # constant y/n
Martin Rothbcaaad12015-10-18 11:16:25 -0600972 return;
973 }
Martin Roth1b44f7e2016-01-11 14:31:38 -0700974 elsif ( $exprline =~ /^\s*"?((?:-)\d+)"?\s*$/ ) { # int values
Martin Rothbcaaad12015-10-18 11:16:25 -0600975 return;
976 }
977 elsif ( $exprline =~ /^\s*"?((?:-)?(?:0x)?\p{XDigit})+"?\s*$/ ) { # hex values
978 return;
979 }
980 elsif ( $exprline =~ /^\s*("[^"]*")\s*$/ ) { # String values
981 return;
982 }
983 elsif ( $exprline =~ /^\s*([A-Za-z0-9_]+)\s*$/ ) { # <symbol> (1)
Martin Rothb7c39b22016-01-14 09:04:53 -0700984 add_referenced_symbol( $1, $filename, $line_no, 'expression' );
Martin Rothbcaaad12015-10-18 11:16:25 -0600985 }
986 elsif ( $exprline =~ /^\s*!(.+)$/ ) { # '!' <expr> (5)
987
988 handle_expressions( $1, $inside_config, $filename, $line_no );
989 }
990 elsif ( $exprline =~ /^\s*\(([^)]+)\)\s*$/ ) { # '(' <expr> ')' (4)
991 handle_expressions( $1, $inside_config, $filename, $line_no );
992 }
993 elsif ( $exprline =~ /^\s*(.+)\s*!=\s*(.+)\s*$/ ) { # <symbol> '!=' <symbol> (3)
994 handle_expressions( $1, $inside_config, $filename, $line_no );
995 handle_expressions( $2, $inside_config, $filename, $line_no );
996 }
997 elsif ( $exprline =~ /^\s*(.+)\s*=\s*(.+)\s*$/ ) { # <symbol> '=' <symbol> (2)
998 handle_expressions( $1, $inside_config, $filename, $line_no );
999 handle_expressions( $2, $inside_config, $filename, $line_no );
1000 }
1001 elsif ( $exprline =~ /^\s*([^(]+|\(.+\))\s*&&\s*(.+)\s*$/ ) { # <expr> '&&' <expr> (6)
1002 handle_expressions( $1, $inside_config, $filename, $line_no );
1003 handle_expressions( $2, $inside_config, $filename, $line_no );
1004 }
1005 elsif ( $exprline =~ /^\s*([^(]+|\(.+\))\s*\|\|\s*(.+)\s*$/ ) { # <expr> '||' <expr> (7)
1006 handle_expressions( $1, $inside_config, $filename, $line_no );
1007 handle_expressions( $2, $inside_config, $filename, $line_no );
1008 }
1009
1010 # work around kconfig spec violation for now - paths not in quotes
1011 elsif ( $exprline =~ /^\s*([A-Za-z0-9_\-\/]+)\s*$/ ) { # <symbol> (1)
1012 return;
1013 }
1014 else {
Martin Rothd8080172015-11-26 19:12:44 -07001015 show_error("Unrecognized expression '$exprline' in $filename line $line_no.");
Martin Rothbcaaad12015-10-18 11:16:25 -06001016 }
1017
1018 return;
1019}
1020
1021#-------------------------------------------------------------------------------
1022# add_referenced_symbol
1023#-------------------------------------------------------------------------------
1024sub add_referenced_symbol {
Martin Rothb7c39b22016-01-14 09:04:53 -07001025 my ( $symbol, $filename, $line_no, $reftype ) = @_;
Martin Rothbcaaad12015-10-18 11:16:25 -06001026 if ( exists $referenced_symbols{$symbol} ) {
1027 $referenced_symbols{$symbol}{count}++;
1028 $referenced_symbols{$symbol}{ $referenced_symbols{$symbol}{count} }{filename} = $filename;
1029 $referenced_symbols{$symbol}{ $referenced_symbols{$symbol}{count} }{line_no} = $line_no;
1030 }
1031 else {
1032 $referenced_symbols{$symbol}{count} = 0;
1033 $referenced_symbols{$symbol}{0}{filename} = $filename;
1034 $referenced_symbols{$symbol}{0}{line_no} = $line_no;
1035 }
Martin Rothb7c39b22016-01-14 09:04:53 -07001036
1037 #mark the symbol as being selected, use referenced symbols for location
1038 if ( $reftype eq 'select' ) {
1039 $selected_symbols{$symbol}{ $referenced_symbols{$symbol}{count} } = 1;
1040 }
Martin Rothbcaaad12015-10-18 11:16:25 -06001041}
1042
1043#-------------------------------------------------------------------------------
1044# handle_help
1045#-------------------------------------------------------------------------------
1046{
1047 #create a non-global static variable by enclosing it and the subroutine
1048 my $help_whitespace = ""; #string to show length of the help whitespace
Martin Roth8849f3b2017-05-23 19:43:43 -06001049 my $help_keyword_whitespace = "";
Martin Rothbcaaad12015-10-18 11:16:25 -06001050
1051 sub handle_help {
1052 my ( $line, $inside_help, $inside_config, $inside_choice, $filename, $line_no ) = @_;
1053
1054 if ($inside_help) {
1055
1056 #get the indentation level if it's not already set.
1057 if ( ( !$help_whitespace ) && ( $line !~ /^[\r\n]+/ ) ) {
1058 $line =~ /^(\s+)/; #find the indentation level.
1059 $help_whitespace = $1;
1060 if ( !$help_whitespace ) {
Martin Roth8849f3b2017-05-23 19:43:43 -06001061 show_error("$filename:$line_no - help text starts with no whitespace.");
1062 return $inside_help;
1063 }
1064 elsif ($help_keyword_whitespace eq $help_whitespace) {
1065 show_error("$filename:$line_no - help text needs additional indentation.");
Martin Rothbcaaad12015-10-18 11:16:25 -06001066 return $inside_help;
Martin Rothbcaaad12015-10-18 11:16:25 -06001067 }
1068 }
1069
1070 #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 -06001071 if ( ( $line !~ /^$help_whitespace/ ) && ( $line !~ /^[\r\n]+/ ) ) {
Martin Rothbcaaad12015-10-18 11:16:25 -06001072 $inside_help = 0;
1073 $help_whitespace = "";
Martin Roth8849f3b2017-05-23 19:43:43 -06001074 $help_keyword_whitespace = "";
Martin Rothbcaaad12015-10-18 11:16:25 -06001075 }
1076 else { #if it's not ended, add the line to the helptext array for the symbol's instance
1077 if ($inside_config) {
1078 my $sym_num = $symbols{$inside_config}{count};
1079 if ($help_whitespace) { $line =~ s/^$help_whitespace//; }
1080 push( @{ $symbols{$inside_config}{$sym_num}{helptext} }, $line );
1081 }
Martin Roth8849f3b2017-05-23 19:43:43 -06001082 if ( ($help_keyword_whitespace eq $help_whitespace) && ( $line !~ /^[\r\n]+/ ) ) {
1083 show_error("$filename:$line_no - help text needs additional indentation.");
1084 }
Martin Rothbcaaad12015-10-18 11:16:25 -06001085 }
1086 }
1087 elsif ( ( $line =~ /^(\s*)help/ ) || ( $line =~ /^(\s*)---help---/ ) ) {
1088 $inside_help = $line_no;
Martin Roth8849f3b2017-05-23 19:43:43 -06001089 $line =~ /^(\s+)/;
1090 $help_keyword_whitespace = $1;
Martin Rothbcaaad12015-10-18 11:16:25 -06001091 if ( ( !$inside_config ) && ( !$inside_choice ) ) {
Martin Rothd8080172015-11-26 19:12:44 -07001092 if ($show_note_output) {
Martin Roth7aa3cea2015-11-27 18:45:45 -07001093 print "# Note: $filename:$line_no help is not inside a config or choice block.\n";
Martin Rothbcaaad12015-10-18 11:16:25 -06001094 }
Martin Rothbcaaad12015-10-18 11:16:25 -06001095 }
1096 elsif ($inside_config) {
1097 $help_whitespace = "";
1098 my $sym_num = $symbols{$inside_config}{count};
1099 $symbols{$inside_config}{$sym_num}{help_line_no} = $line_no;
1100 $symbols{$inside_config}{$sym_num}{helptext} = ();
1101 }
1102 }
1103 return $inside_help;
1104 }
1105}
1106
1107#-------------------------------------------------------------------------------
1108# handle_type
1109#-------------------------------------------------------------------------------
1110sub handle_type {
1111 my ( $type, $inside_config, $filename, $line_no ) = @_;
1112
1113 my $expression;
1114 ( $type, $expression ) = handle_if_line( $type, $inside_config, $filename, $line_no );
1115
Martin Roth08ee1cf2016-01-25 16:39:32 -07001116 if ( $type =~ /tristate/ ) {
Julius Wernere5eb2de2019-03-05 17:10:19 -08001117 show_error("$filename:$line_no - tristate types are not used.");
Martin Roth08ee1cf2016-01-25 16:39:32 -07001118 }
1119
Martin Rothbcaaad12015-10-18 11:16:25 -06001120 if ($inside_config) {
1121 if ( exists( $symbols{$inside_config}{type} ) ) {
1122 if ( $symbols{$inside_config}{type} !~ /$type/ ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -07001123 show_error( "Config '$inside_config' type entry $type"
1124 . " at $filename:$line_no does not match $symbols{$inside_config}{type}"
1125 . " defined at $symbols{$inside_config}{type_file}:$symbols{$inside_config}{type_line_no}." );
Martin Rothbcaaad12015-10-18 11:16:25 -06001126 }
1127 }
1128 else {
1129 $symbols{$inside_config}{type} = $type;
1130 $symbols{$inside_config}{type_file} = $filename;
1131 $symbols{$inside_config}{type_line_no} = $line_no;
1132 }
1133 }
1134 else {
Martin Roth7aa3cea2015-11-27 18:45:45 -07001135 show_error("Type entry at $filename:$line_no is not inside a config block.");
Martin Rothbcaaad12015-10-18 11:16:25 -06001136 }
1137}
1138
1139#-------------------------------------------------------------------------------
1140# handle_prompt
1141#-------------------------------------------------------------------------------
1142sub handle_prompt {
1143 my ( $prompt, $name, $menu_array_ref, $inside_config, $inside_choice, $filename, $line_no ) = @_;
1144
1145 my $expression;
1146 ( $prompt, $expression ) = handle_if_line( $prompt, $inside_config, $filename, $line_no );
1147
1148 if ($inside_config) {
1149 if ( $prompt !~ /^\s*$/ ) {
1150 if ( $prompt =~ /^\s*"([^"]*)"\s*$/ ) {
1151 $prompt = $1;
1152 }
1153
Martin Roth08cf90f2016-01-25 19:54:16 -07001154 #display an error if there's a prompt at the top menu level
Martin Rothbcaaad12015-10-18 11:16:25 -06001155 if ( !defined @$menu_array_ref[0] ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -07001156 show_error( "Symbol '$inside_config' with prompt '$prompt' appears outside of a menu"
1157 . " at $filename:$line_no." );
Martin Rothbcaaad12015-10-18 11:16:25 -06001158 }
1159
1160 my $sym_num = $symbols{$inside_config}{count};
Martin Rothb58d3492016-01-25 16:42:13 -07001161 if ( !exists $symbols{$inside_config}{$sym_num}{prompt_max} ) {
Martin Rothbcaaad12015-10-18 11:16:25 -06001162 $symbols{$inside_config}{$sym_num}{prompt_max} = 0;
1163 }
Martin Rothb58d3492016-01-25 16:42:13 -07001164 else {
1165 $symbols{$inside_config}{$sym_num}{prompt_max}++;
1166 }
Martin Rothbcaaad12015-10-18 11:16:25 -06001167 my $prompt_max = $symbols{$inside_config}{$sym_num}{prompt_max};
1168 $symbols{$inside_config}{$sym_num}{prompt}{$prompt_max}{prompt} = $prompt;
1169 $symbols{$inside_config}{$sym_num}{prompt}{$prompt_max}{prompt_line_no} = $line_no;
Martin Rothb58d3492016-01-25 16:42:13 -07001170
1171 $symbols{$inside_config}{$sym_num}{prompt}{$prompt_max}{prompt_menu} = @$menu_array_ref;
Martin Rothbcaaad12015-10-18 11:16:25 -06001172 if ($expression) {
1173 $symbols{$inside_config}{$sym_num}{prompt}{$prompt_max}{prompt_depends_on} = $expression;
1174 }
1175 }
1176 }
1177 elsif ($inside_choice) {
1178
1179 #do nothing
1180 }
1181 else {
Martin Roth7aa3cea2015-11-27 18:45:45 -07001182 show_error("$name entry at $filename:$line_no is not inside a config or choice block.");
Martin Rothbcaaad12015-10-18 11:16:25 -06001183 }
1184}
1185
1186#-------------------------------------------------------------------------------
1187# simple_line_checks - Does some basic checks on the current line, then cleans the line
1188# up for further processing.
1189#-------------------------------------------------------------------------------
1190sub simple_line_checks {
1191 my ( $line, $filename, $line_no ) = @_;
1192
1193 #check for spaces instead of tabs
1194 if ( $line =~ /^ +/ ) {
Martin Roth7aa3cea2015-11-27 18:45:45 -07001195 show_error("$filename:$line_no starts with a space.");
Martin Rothbcaaad12015-10-18 11:16:25 -06001196 }
1197
1198 #verify a linefeed at the end of the line
1199 if ( $line !~ /.*\n/ ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -07001200 show_error( "$filename:$line_no does not end with linefeed."
1201 . " This can cause the line to not be recognized by the Kconfig parser.\n#($line)" );
Martin Rothbcaaad12015-10-18 11:16:25 -06001202 $line =~ s/\s*$//;
1203 }
1204 else {
1205 chop($line);
1206 }
1207
1208 return $line;
1209}
1210
1211#-------------------------------------------------------------------------------
1212# load_kconfig_file - Loads a single Kconfig file or expands * wildcard
1213#-------------------------------------------------------------------------------
1214sub load_kconfig_file {
1215 my ( $input_file, $loadfile, $loadline, $expanded, $topfile, $topline ) = @_;
1216 my @file_data;
1217 my @dir_file_data;
1218
1219 #recursively handle coreboot's new source glob operator
Arthur Heymans55f01322019-11-05 12:06:59 +01001220 if ( $input_file =~ /^(.*?)\/(\w*)\*(\w*)\/(.*)$/ ) {
Martin Rothbcaaad12015-10-18 11:16:25 -06001221 my $dir_prefix = $1;
Arthur Heymans55f01322019-11-05 12:06:59 +01001222 my $dir_glob_prefix = $2;
1223 my $dir_glob_suffix = $3;
1224 my $dir_suffix = $4;
Martin Rothbcaaad12015-10-18 11:16:25 -06001225 if ( -d "$dir_prefix" ) {
1226
1227 opendir( D, "$dir_prefix" ) || die "Can't open directory '$dir_prefix'\n";
1228 my @dirlist = sort { $a cmp $b } readdir(D);
1229 closedir(D);
1230
1231 while ( my $directory = shift @dirlist ) {
1232
1233 #ignore non-directory files
Arthur Heymans55f01322019-11-05 12:06:59 +01001234 if ( ( -d "$dir_prefix/$directory" ) && !( $directory =~ /^\..*/ )
1235 && ( $directory =~ /\Q$dir_glob_prefix\E.*\Q$dir_glob_suffix\E/ ) ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -07001236 push @dir_file_data,
1237 load_kconfig_file( "$dir_prefix/$directory/$dir_suffix",
1238 $input_file, $loadline, 1, $loadfile, $loadline );
Martin Rothbcaaad12015-10-18 11:16:25 -06001239 }
1240 }
1241 }
1242
1243 #the directory should exist when using a glob
1244 else {
Julius Wernere5eb2de2019-03-05 17:10:19 -08001245 show_error("Could not find dir '$dir_prefix'");
Martin Rothbcaaad12015-10-18 11:16:25 -06001246 }
1247 }
1248
1249 #if the file exists, try to load it.
1250 elsif ( -e "$input_file" ) {
1251
Martin Rotha7d00272016-10-03 23:00:04 +02001252 #throw a warning if the file has already been loaded.
Martin Rothbcaaad12015-10-18 11:16:25 -06001253 if ( exists $loaded_files{$input_file} ) {
Martin Rotha7d00272016-10-03 23:00:04 +02001254 show_warning("'$input_file' sourced at $loadfile:$loadline was already loaded by $loaded_files{$input_file}");
Martin Rothbcaaad12015-10-18 11:16:25 -06001255 }
1256
1257 #load the file's contents and mark the file as loaded for checking later
1258 open( my $HANDLE, "<", "$input_file" ) or die "Error: could not open file '$input_file'\n";
1259 @file_data = <$HANDLE>;
1260 close $HANDLE;
1261 $loaded_files{$input_file} = "'$loadfile' line $loadline";
1262 }
1263
1264 # if the file isn't being loaded from a glob, it should exist.
1265 elsif ( $expanded == 0 ) {
Martin Roth7aa3cea2015-11-27 18:45:45 -07001266 show_warning("Could not find file '$input_file' sourced at $loadfile:$loadline");
Martin Rothbcaaad12015-10-18 11:16:25 -06001267 }
1268
1269 my $line_in_file = 0;
1270 while ( my $line = shift @file_data ) {
1271
1272 #handle line continuation.
1273 my $continue_line = 0;
Martin Roth1b44f7e2016-01-11 14:31:38 -07001274 while ( $line =~ /(.*)\s+\\$/ ) {
Martin Rothbcaaad12015-10-18 11:16:25 -06001275 my $text = $1;
1276
1277 # get rid of leading whitespace on all but the first and last lines
1278 $text =~ s/^\s*/ / if ($continue_line);
1279
1280 $dir_file_data[$line_in_file]{text} .= $text;
1281 $line = shift @file_data;
1282 $continue_line++;
1283
1284 #put the data into the continued lines (other than the first)
1285 $line =~ /^\s*(.*)\s*$/;
1286
Martin Roth1b44f7e2016-01-11 14:31:38 -07001287 $dir_file_data[ $line_in_file + $continue_line ]{text} = "\t# continued line ( " . $1 . " )\n";
1288 $dir_file_data[ $line_in_file + $continue_line ]{filename} = $input_file;
1289 $dir_file_data[ $line_in_file + $continue_line ]{file_line_no} = $line_in_file + $continue_line + 1;
Martin Rothbcaaad12015-10-18 11:16:25 -06001290
1291 #get rid of multiple leading spaces for last line
1292 $line = " $1\n";
1293 }
1294
Martin Roth1b44f7e2016-01-11 14:31:38 -07001295 $dir_file_data[$line_in_file]{text} .= $line;
Martin Rothbcaaad12015-10-18 11:16:25 -06001296 $dir_file_data[$line_in_file]{filename} = $input_file;
1297 $dir_file_data[$line_in_file]{file_line_no} = $line_in_file + 1;
1298
1299 $line_in_file++;
1300 if ($continue_line) {
1301 $line_in_file += $continue_line;
1302 }
1303 }
1304
1305 if ($topfile) {
1306 my %file_data;
Martin Roth1b44f7e2016-01-11 14:31:38 -07001307 $file_data{text} = "\t### File '$input_file' loaded from '$topfile' line $topline\n";
Martin Rothbcaaad12015-10-18 11:16:25 -06001308 $file_data{filename} = $topfile;
1309 $file_data{file_line_no} = "($topline)";
Martin Roth1b44f7e2016-01-11 14:31:38 -07001310 unshift( @dir_file_data, \%file_data );
Martin Rothbcaaad12015-10-18 11:16:25 -06001311 }
1312
1313 return @dir_file_data;
1314}
1315
Martin Rothbcaaad12015-10-18 11:16:25 -06001316#-------------------------------------------------------------------------------
1317# print_wholeconfig - prints out the parsed Kconfig file
1318#-------------------------------------------------------------------------------
1319sub print_wholeconfig {
1320
1321 return unless $print_full_output;
1322
1323 for ( my $i = 0 ; $i < $#wholeconfig ; $i++ ) {
1324 my $line = $wholeconfig[$i];
1325 chop( $line->{text} );
1326
1327 #replace tabs with spaces for consistency
1328 $line->{text} =~ s/\t/ /g;
Martin Roth819e6722016-01-25 16:38:05 -07001329 printf "%-120s # $line->{filename} line $line->{file_line_no} ($line->{menus})\n", $line->{text};
Martin Rothbcaaad12015-10-18 11:16:25 -06001330 }
1331}
1332
1333#-------------------------------------------------------------------------------
1334# check_if_file_referenced - checks for kconfig files that are not being parsed
1335#-------------------------------------------------------------------------------
1336sub check_if_file_referenced {
1337 my $filename = $File::Find::name;
Martin Rothab2d7772016-01-25 16:45:14 -07001338 if ( ( $filename =~ /Kconfig/ )
1339 && ( !$filename =~ /\.orig$/ )
1340 && ( !$filename =~ /~$/ )
1341 && ( !exists $loaded_files{$filename} ) )
1342 {
Martin Rothd8080172015-11-26 19:12:44 -07001343 show_warning("'$filename' is never referenced");
Martin Rothbcaaad12015-10-18 11:16:25 -06001344 }
1345}
1346
1347#-------------------------------------------------------------------------------
1348# check_arguments parse the command line arguments
1349#-------------------------------------------------------------------------------
1350sub check_arguments {
1351 my $show_usage = 0;
1352 GetOptions(
1353 'help|?' => sub { usage() },
Martin Rothd8080172015-11-26 19:12:44 -07001354 'e|errors_off' => \$suppress_error_output,
1355 'n|notes' => \$show_note_output,
Martin Rothbcaaad12015-10-18 11:16:25 -06001356 'o|output=s' => \$output_file,
1357 'p|print' => \$print_full_output,
Martin Rothd8080172015-11-26 19:12:44 -07001358 'w|warnings_off' => \$suppress_warning_output,
Martin Rothbcaaad12015-10-18 11:16:25 -06001359 'path=s' => \$top_dir,
1360 'c|config=s' => \$config_file,
1361 'G|no_git_grep' => \$dont_use_git_grep,
1362 );
Martin Rothd8080172015-11-26 19:12:44 -07001363
1364 if ($suppress_error_output) {
1365 $suppress_warning_output = 1;
1366 }
1367 if ($suppress_warning_output) {
Martin Roth1b44f7e2016-01-11 14:31:38 -07001368 $show_note_output = 0;
Martin Rothd8080172015-11-26 19:12:44 -07001369 }
Martin Rothbcaaad12015-10-18 11:16:25 -06001370}
1371
1372#-------------------------------------------------------------------------------
1373# usage - Print the arguments for the user
1374#-------------------------------------------------------------------------------
1375sub usage {
1376 print "kconfig_lint <options>\n";
1377 print " -o|--output=file Set output filename\n";
1378 print " -p|--print Print full output\n";
Martin Rothd8080172015-11-26 19:12:44 -07001379 print " -e|--errors_off Don't print warnings or errors\n";
Martin Rothbcaaad12015-10-18 11:16:25 -06001380 print " -w|--warnings_off Don't print warnings\n";
Martin Rothd8080172015-11-26 19:12:44 -07001381 print " -n|--notes Show minor notes\n";
Martin Rothbcaaad12015-10-18 11:16:25 -06001382 print " --path=dir Path to top level kconfig\n";
1383 print " -c|--config=file Filename of config file to load\n";
1384 print " -G|--no_git_grep Use standard grep tools instead of git grep\n";
1385
1386 exit(0);
1387}
1388
13891;