blob: eddd8de6ee6dd98229a36cffff709050e40c6518 [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
Martin Rothab273d32016-11-23 17:28:00 -070050 '\.config\|\.txt$\|\.tex$\|\.tags'; #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();
96 check_is_enabled();
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 ) {
Martin Roth5b883012017-06-25 20:27:36 -0600196 if ( $line =~ /^([^:]+):(\d+):\s*#\s*ifn?def\s*\(?\s*CONFIG_(\w+)/ ) {
197 my $file = $1;
198 my $lineno = $2;
199 my $symbol = $3;
200
201 if ( ( exists $symbols{$symbol} ) && ( $symbols{$symbol}{type} ne "string" ) ) {
202 show_warning( "#ifdef 'CONFIG_$symbol' used at $file:$lineno."
203 . " Symbols of type '$symbols{$symbol}{type}' are always defined." );
204 }
205 } elsif ( $line =~ /^([^:]+):(\d+):\s*#\s*if\s+!?\s*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" ) ) {
Martin Rotha7d00272016-10-03 23:00:04 +0200211 show_warning( "#ifdef '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 # look for (#if) defined SYMBOL
218 @ifdef_symbols = @collected_symbols;
219 while ( my $line = shift @ifdef_symbols ) {
220 if ( $line =~ /^([^:]+):(\d+):.+defined\s*\(\s*CONFIG_(\w+)/ ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -0700221 my $file = $1;
Martin Rothbcaaad12015-10-18 11:16:25 -0600222 my $lineno = $2;
223 my $symbol = $3;
224
225 #ignore '#if defined(symbol) && symbol' type statements
Martin Roth1b44f7e2016-01-11 14:31:38 -0700226 next
227 if ( $line =~ /^([^:]+):(\d+):.+defined\s*\(\s*CONFIG_$symbol.*(&&|\|\|)\s*!?\s*\(?\s*CONFIG_$symbol/ );
Martin Rothbcaaad12015-10-18 11:16:25 -0600228
Martin Roth1b44f7e2016-01-11 14:31:38 -0700229 if ( ( exists $symbols{$symbol} ) && ( $symbols{$symbol}{type} ne "string" ) ) {
Martin Roth15f4d8c2016-01-31 10:44:33 -0700230 show_warning( "defined 'CONFIG_$symbol' used at $file:$lineno."
Martin Roth1b44f7e2016-01-11 14:31:38 -0700231 . " Symbols of type '$symbols{$symbol}{type}' are always defined." );
Martin Rothbcaaad12015-10-18 11:16:25 -0600232 }
233 }
234 }
Martin Roth66223762016-01-31 10:34:13 -0700235
236 my @collected_is_enabled;
237 if ($dont_use_git_grep) {
238 @collected_is_enabled =
239 `grep -Irn -- "[[:space:]]IS_ENABLED[[:space:]]*(.*)" | grep -v '$exclude_dirs_and_files' | grep -v "kconfig.h"`;
240 }
241 else {
242 @collected_is_enabled =
243 `git grep -In -- "[[:space:]]IS_ENABLED[[:space:]]*(.*)" | grep -v '$exclude_dirs_and_files' | grep -v "kconfig.h"`;
244 }
245
246 while ( my $line = shift @collected_is_enabled ) {
247 if ($line !~ /CONFIG_/ && $line =~ /^([^:]+):(\d+):.+IS_ENABLED\s*\(\s*(\w+)/ ) {
248 my $file = $1;
249 my $lineno = $2;
250 my $symbol = $3;
251 if ( ( exists $symbols{$symbol} ) ) {
252 show_error("IS_ENABLED missing CONFIG_ prefix on symbol '$symbol' at $file:$lineno.");
253 }
254 }
255 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600256}
257
258#-------------------------------------------------------------------------------
259# check_for_def - Look for instances of #define CONFIG_[symbol_name]
260#
261# Symbols should not be redefined outside of Kconfig, and #defines should not
262# look like symbols
263#-------------------------------------------------------------------------------
264sub check_for_def {
265 my @def_symbols = @collected_symbols;
266
267 #look for #ifdef SYMBOL
268 while ( my $line = shift @def_symbols ) {
269 if ( $line =~ /^([^:]+):(\d+):\s*#\s*define\s+CONFIG_(\w+)/ ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -0700270 my $file = $1;
Martin Rothbcaaad12015-10-18 11:16:25 -0600271 my $lineno = $2;
272 my $symbol = $3;
273
Martin Roth1b44f7e2016-01-11 14:31:38 -0700274 if ( ( exists $symbols{$symbol} ) ) {
Martin Rotha7d00272016-10-03 23:00:04 +0200275 show_warning("#define of symbol 'CONFIG_$symbol' used at $file:$lineno.");
Martin Roth1b44f7e2016-01-11 14:31:38 -0700276 }
277 else {
278 show_warning( "#define 'CONFIG_$symbol' used at $file:$lineno."
279 . " Other #defines should not look like Kconfig symbols." );
280 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600281 }
282 }
283}
284
285#-------------------------------------------------------------------------------
Martin Roth08705f12016-11-09 14:27:00 -0700286# check_type - Make sure that all symbols have a type defined.
287#
288# Conflicting types are found when parsing the Kconfig tree.
289#-------------------------------------------------------------------------------
290sub check_type {
291
292 # loop through each defined symbol
293 foreach my $sym ( sort ( keys %symbols ) ) {
294
295 # Make sure there's a type set for the symbol
296 if (!defined $symbols{$sym}{type}) {
297
298 #loop through each instance of that symbol
299 for ( my $sym_num = 0 ; $sym_num <= $symbols{$sym}{count} ; $sym_num++ ) {
300
301 my $filename = $symbols{$sym}{$sym_num}{file};
302 my $line_no = $symbols{$sym}{$sym_num}{line_no};
303
304 show_error("No type defined for symbol $sym defined at $filename:$line_no.");
305 }
306 }
307 }
308}
309
310#-------------------------------------------------------------------------------
Martin Rothbcaaad12015-10-18 11:16:25 -0600311# check_is_enabled - The IS_ENABLED() macro is only valid for symbols of type
312# bool. It would probably work on type hex or int if the value was 0 or 1, but
313# this seems like a bad plan. Using it on strings is dead out.
314#-------------------------------------------------------------------------------
315sub check_is_enabled {
Martin Rothb6acc302015-11-27 18:51:19 -0700316 my @is_enabled_symbols = @collected_symbols;
Martin Rothbcaaad12015-10-18 11:16:25 -0600317
318 #sort through symbols found by grep and store them in a hash for easy access
319 while ( my $line = shift @is_enabled_symbols ) {
Martin Rothb6acc302015-11-27 18:51:19 -0700320 if ( $line =~ /^([^:]+):(\d+):(.+IS_ENABLED.*)/ ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -0700321 my $file = $1;
Martin Rothbcaaad12015-10-18 11:16:25 -0600322 my $lineno = $2;
Martin Rothb6acc302015-11-27 18:51:19 -0700323 $line = $3;
Martin Roth572a8562016-01-25 16:14:09 -0700324 if ( ( $line !~ /(.*)IS_ENABLED\s*\(\s*CONFIG_(\w+)(.*)/ ) && ( $line !~ /(\/[\*\/])(.*)IS_ENABLED/ ) ) {
Martin Rothb6acc302015-11-27 18:51:19 -0700325 show_warning("# uninterpreted IS_ENABLED at $file:$lineno: $line");
326 next;
Martin Rothbcaaad12015-10-18 11:16:25 -0600327 }
Martin Rothb6acc302015-11-27 18:51:19 -0700328 while ( $line =~ /(.*)IS_ENABLED\s*\(\s*CONFIG_(\w+)(.*)/ ) {
329 my $symbol = $2;
Martin Roth1b44f7e2016-01-11 14:31:38 -0700330 $line = $1 . $3;
Martin Rothb6acc302015-11-27 18:51:19 -0700331
Martin Roth5b883012017-06-25 20:27:36 -0600332 #make sure that the type is bool
Martin Roth1b44f7e2016-01-11 14:31:38 -0700333 if ( exists $symbols{$symbol} ) {
334 if ( $symbols{$symbol}{type} ne "bool" ) {
335 show_error( "IS_ENABLED(CONFIG_$symbol) used at $file:$lineno."
336 . " IS_ENABLED is only valid for type 'bool', not '$symbols{$symbol}{type}'." );
Martin Rothb6acc302015-11-27 18:51:19 -0700337 }
Martin Roth1b44f7e2016-01-11 14:31:38 -0700338 }
339 else {
Martin Rothb6acc302015-11-27 18:51:19 -0700340 show_error("IS_ENABLED() used on unknown value CONFIG_$symbol at $file:$lineno.");
341 }
342 }
Martin Roth5b883012017-06-25 20:27:36 -0600343 } elsif ( $line =~ /^([^:]+):(\d+):\s*#\s*(?:el)?if\s+!?\s*\(?\s*CONFIG_(\w+)\)?(\s*==\s*1)?.*?$/ ) {
344 my $file = $1;
345 my $lineno = $2;
346 my $symbol = $3;
347 # If the type is bool, give a warning that IS_ENABLED should be used
348 if ( exists $symbols{$symbol} ) {
349 if ( $symbols{$symbol}{type} eq "bool" ) {
350 show_error( "#if CONFIG_$symbol used at $file:$lineno."
351 . " IS_ENABLED should be used for type 'bool'" );
352 }
353 }
354 } elsif ( $line =~ /^([^:]+):(\d+):\s*#\s*(?:el)?if.*(?:&&|\|\|)\s+!?\s*\(?\s*CONFIG_(\w+)\)?(\s*==\s*1)?$/ ) {
355 my $file = $1;
356 my $lineno = $2;
357 my $symbol = $3;
358 # If the type is bool, give a warning that IS_ENABLED should be used
359 if ( exists $symbols{$symbol} ) {
360 if ( $symbols{$symbol}{type} eq "bool" ) {
361 show_error( "#if CONFIG_$symbol used at $file:$lineno."
362 . " IS_ENABLED should be used for type 'bool'" );
363 }
364 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600365 }
366 }
367}
368
369#-------------------------------------------------------------------------------
370# check_defaults - Look for defaults that come after a default with no
371# dependencies.
372#
373# TODO - check for defaults with the same dependencies
374#-------------------------------------------------------------------------------
375sub check_defaults {
376
377 # loop through each defined symbol
378 foreach my $sym ( sort ( keys %symbols ) ) {
379 my $default_set = 0;
380 my $default_filename = "";
381 my $default_line_no = "";
382
383 #loop through each instance of that symbol
384 for ( my $sym_num = 0 ; $sym_num <= $symbols{$sym}{count} ; $sym_num++ ) {
385
386 #loop through any defaults for that instance of that symbol, if there are any
387 next unless ( exists $symbols{$sym}{$sym_num}{default_max} );
388 for ( my $def_num = 0 ; $def_num <= $symbols{$sym}{$sym_num}{default_max} ; $def_num++ ) {
389
Martin Rothfa956252016-09-30 15:51:32 -0600390 my $filename = $symbols{$sym}{$sym_num}{file};
391 my $line_no = $symbols{$sym}{$sym_num}{default}{$def_num}{default_line_no};
392
Martin Roth08705f12016-11-09 14:27:00 -0700393 # Make sure there's a type set for the symbol
394 next if (!defined $symbols{$sym}{type});
395
Martin Rothfa956252016-09-30 15:51:32 -0600396 # skip good defaults
397 if (! ((($symbols{$sym}{type} eq "hex") && ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /^0x/)) ||
398 (($symbols{$sym}{type} eq "int") && ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /^[-0-9]+$/)) ||
399 (($symbols{$sym}{type} eq "string") && ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /^".*"$/)) ||
400 (($symbols{$sym}{type} eq "bool") && ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /^[yn]$/)))
401 ) {
402
403 my ($checksym) = $symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /(\w+)/;
404
405 if (! exists $symbols{$checksym}) {
406
407 # verify the symbol type against the default value
408 if ($symbols{$sym}{type} eq "hex") {
409 show_error("non hex default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) used for hex symbol $sym at $filename:$line_no.");
410 } elsif ($symbols{$sym}{type} eq "int") {
411 show_error("non int default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) used for int symbol $sym at $filename:$line_no.");
412 } elsif ($symbols{$sym}{type} eq "string") {
413 # TODO: Remove special MAINBOARD_DIR check
414 if ($sym ne "MAINBOARD_DIR") {
415 show_error("no quotes around default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) used for string symbol $sym at $filename:$line_no.");
416 }
417 } elsif ($symbols{$sym}{type} eq "bool") {
418 if ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /[01YN]/) {
419 show_warning("default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) for bool symbol $sym uses value other than y/n at $filename:$line_no.");
420 } else {
421 show_error("non bool default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) used for bool symbol $sym at $filename:$line_no.");
422 }
423 }
424 }
425 }
426
Martin Rothbcaaad12015-10-18 11:16:25 -0600427 #if a default is already set, display an error
428 if ($default_set) {
Martin Roth1b44f7e2016-01-11 14:31:38 -0700429 show_warning( "Default for '$sym' referenced at $filename:$line_no will never be set"
430 . " - overridden by default set at $default_filename:$default_line_no" );
Martin Rothbcaaad12015-10-18 11:16:25 -0600431 }
432 else {
433 #if no default is set, see if this is a default with no dependencies
434 unless ( ( exists $symbols{$sym}{$sym_num}{default}{$def_num}{default_depends_on} )
435 || ( exists $symbols{$sym}{$sym_num}{max_dependency} ) )
436 {
437 $default_set = 1;
438 $default_filename = $symbols{$sym}{$sym_num}{file};
439 $default_line_no = $symbols{$sym}{$sym_num}{default}{$def_num}{default_line_no};
440 }
441 }
442 }
443 }
444 }
445}
446
447#-------------------------------------------------------------------------------
448# check_referenced_symbols - Make sure the symbols referenced by expressions and
449# select statements are actually valid symbols.
450#-------------------------------------------------------------------------------
451sub check_referenced_symbols {
452
453 #loop through symbols found in expressions and used by 'select' keywords
454 foreach my $key ( sort ( keys %referenced_symbols ) ) {
455
456 #make sure the symbol was defined by a 'config' or 'choice' keyword
457 next if ( exists $symbols{$key} );
458
Martin Rothd8080172015-11-26 19:12:44 -0700459 #loop through each instance of the symbol to print out all of the invalid references
460 for ( my $i = 0 ; $i <= $referenced_symbols{$key}{count} ; $i++ ) {
461 my $filename = $referenced_symbols{$key}{$i}{filename};
462 my $line_no = $referenced_symbols{$key}{$i}{line_no};
Martin Roth7aa3cea2015-11-27 18:45:45 -0700463 show_error("Undefined Symbol '$key' used at $filename:$line_no.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600464 }
465 }
466}
467
468#-------------------------------------------------------------------------------
469#-------------------------------------------------------------------------------
470sub collect_used_symbols {
471 # find all references to CONFIG_ statements in the tree
472
473 if ($dont_use_git_grep) {
Martin Rothe69c58d2016-11-15 21:08:42 -0700474 @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 -0700475 }
476 else {
Martin Rothe69c58d2016-11-15 21:08:42 -0700477 @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 -0600478 }
479
480 my @used_symbols = @collected_symbols;
481
482 #sort through symbols found by grep and store them in a hash for easy access
483 while ( my $line = shift @used_symbols ) {
484 while ( $line =~ /[^A-Za-z0-9_]CONFIG_([A-Za-z0-9_]+)/g ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -0700485 my $symbol = $1;
Martin Rothbcaaad12015-10-18 11:16:25 -0600486 my $filename = "";
Martin Roth1b44f7e2016-01-11 14:31:38 -0700487 if ( $line =~ /^([^:]+):/ ) {
Martin Rothbcaaad12015-10-18 11:16:25 -0600488 $filename = $1;
489 }
490
Martin Roth1b44f7e2016-01-11 14:31:38 -0700491 if ( exists $used_symbols{$symbol}{count} ) {
Martin Rothbcaaad12015-10-18 11:16:25 -0600492 $used_symbols{$symbol}{count}++;
Martin Roth1b44f7e2016-01-11 14:31:38 -0700493 }
494 else {
495 $used_symbols{$symbol}{count} = 0;
Martin Rothbcaaad12015-10-18 11:16:25 -0600496 }
497 $used_symbols{$symbol}{"num_$used_symbols{$symbol}{count}"} = $filename;
Martin Roth1b44f7e2016-01-11 14:31:38 -0700498 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600499 }
500}
501
502#-------------------------------------------------------------------------------
503# check_used_symbols - Checks to see whether or not the created symbols are
504# actually used.
505#-------------------------------------------------------------------------------
506sub check_used_symbols {
507 # loop through all defined symbols and see if they're used anywhere
508 foreach my $key ( sort ( keys %symbols ) ) {
509
Martin Roth6bfbf1c2016-01-25 16:12:49 -0700510 if ( $key =~ /$exclude_unused/ ) {
511 next;
512 }
513
Martin Rothbcaaad12015-10-18 11:16:25 -0600514 #see if they're used internal to Kconfig
515 next if ( exists $referenced_symbols{$key} );
516
517 #see if they're used externally
518 next if exists $used_symbols{$key};
519
520 #loop through the definitions to print out all the places the symbol is defined.
521 for ( my $i = 0 ; $i <= $symbols{$key}{count} ; $i++ ) {
522 my $filename = $symbols{$key}{$i}{file};
523 my $line_no = $symbols{$key}{$i}{line_no};
Martin Rotha7d00272016-10-03 23:00:04 +0200524 show_warning("Unused symbol '$key' referenced at $filename:$line_no.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600525 }
526 }
527}
528
529#-------------------------------------------------------------------------------
530# build_and_parse_kconfig_tree
531#-------------------------------------------------------------------------------
532#load the initial file and start parsing it
533sub build_and_parse_kconfig_tree {
534 my ($top_level_kconfig) = @_;
535 my @config_to_parse;
536 my @parseline;
537 my $inside_help = 0; # set to line number of 'help' keyword if this line is inside a help block
538 my @inside_if = (); # stack of if dependencies
539 my $inside_config = ""; # set to symbol name of the config section
540 my @inside_menu = (); # stack of menu names
541 my $inside_choice = "";
542 my $configs_inside_choice;
Martin Roth0e6c0e12016-03-02 12:16:13 -0700543 my %fileinfo;
Martin Rothbcaaad12015-10-18 11:16:25 -0600544
545 #start the tree off by loading the top level kconfig
546 @config_to_parse = load_kconfig_file( $top_level_kconfig, "", 0, 0, "", 0 );
547
Martin Rothbcaaad12015-10-18 11:16:25 -0600548 while ( ( @parseline = shift(@config_to_parse) ) && ( exists $parseline[0]{text} ) ) {
549 my $line = $parseline[0]{text};
550 my $filename = $parseline[0]{filename};
551 my $line_no = $parseline[0]{file_line_no};
552
553 #handle help - help text: "help" or "---help---"
Martin Roth811d93a2017-04-06 11:06:00 -0600554 my $lastline_was_help = $inside_help;
Martin Rothbcaaad12015-10-18 11:16:25 -0600555 $inside_help = handle_help( $line, $inside_help, $inside_config, $inside_choice, $filename, $line_no );
556 $parseline[0]{inside_help} = $inside_help;
557
558 #look for basic issues in the line, strip crlf
559 $line = simple_line_checks( $line, $filename, $line_no );
560
561 #strip comments
562 $line =~ s/\s*#.*$//;
563
564 #don't parse any more if we're inside a help block
565 if ($inside_help) {
566 #do nothing
567 }
568
569 #handle config
Martin Roth811d93a2017-04-06 11:06:00 -0600570 elsif ( $line =~ /^\s*config\s+/ ) {
Martin Rothbcaaad12015-10-18 11:16:25 -0600571 $line =~ /^\s*config\s+([^"\s]+)\s*(?>#.*)?$/;
572 my $symbol = $1;
573 $inside_config = $symbol;
574 if ($inside_choice) {
575 $configs_inside_choice++;
576 }
Martin Rothb7c39b22016-01-14 09:04:53 -0700577 add_symbol( $symbol, \@inside_menu, $filename, $line_no, \@inside_if, $inside_choice );
Martin Rothbcaaad12015-10-18 11:16:25 -0600578 }
579
580 #bool|hex|int|string|tristate <expr> [if <expr>]
581 elsif ( $line =~ /^\s*(bool|string|hex|int|tristate)/ ) {
582 $line =~ /^\s*(bool|string|hex|int|tristate)\s*(.*)/;
583 my ( $type, $prompt ) = ( $1, $2 );
584 handle_type( $type, $inside_config, $filename, $line_no );
585 handle_prompt( $prompt, $type, \@inside_menu, $inside_config, $inside_choice, $filename, $line_no );
586 }
587
588 # def_bool|def_tristate <expr> [if <expr>]
589 elsif ( $line =~ /^\s*(def_bool|def_tristate)/ ) {
590 $line =~ /^\s*(def_bool|def_tristate)\s+(.*)/;
591 my ( $orgtype, $default ) = ( $1, $2 );
592 ( my $type = $orgtype ) =~ s/def_//;
593 handle_type( $type, $inside_config, $filename, $line_no );
594 handle_default( $default, $orgtype, $inside_config, $inside_choice, $filename, $line_no );
595 }
596
597 #prompt <prompt> [if <expr>]
598 elsif ( $line =~ /^\s*prompt/ ) {
599 $line =~ /^\s*prompt\s+(.+)/;
600 handle_prompt( $1, "prompt", \@inside_menu, $inside_config, $inside_choice, $filename, $line_no );
601 }
602
603 # default <expr> [if <expr>]
604 elsif ( $line =~ /^\s*default/ ) {
605 $line =~ /^\s*default\s+(.*)/;
606 my $default = $1;
607 handle_default( $default, "default", $inside_config, $inside_choice, $filename, $line_no );
608 }
609
610 # depends on <expr>
611 elsif ( $line =~ /^\s*depends\s+on/ ) {
612 $line =~ /^\s*depends\s+on\s+(.*)$/;
613 my $expr = $1;
614 handle_depends( $expr, $inside_config, $inside_choice, $filename, $line_no );
615 handle_expressions( $expr, $inside_config, $filename, $line_no );
616 }
617
618 # comment <prompt>
619 elsif ( $line =~ /^\s*comment/ ) {
620 $inside_config = "";
621 }
622
623 # choice [symbol]
624 elsif ( $line =~ /^\s*choice/ ) {
625 if ( $line =~ /^\s*choice\s*([A-Za-z0-9_]+)$/ ) {
626 my $symbol = $1;
627 add_symbol( $symbol, \@inside_menu, $filename, $line_no, \@inside_if );
628 handle_type( "bool", $symbol, $filename, $line_no );
629 }
630 $inside_config = "";
631 $inside_choice = "$filename $line_no";
632 $configs_inside_choice = 0;
Martin Roth08cf90f2016-01-25 19:54:16 -0700633
634 # Kconfig verifies that choice blocks have a prompt
Martin Rothbcaaad12015-10-18 11:16:25 -0600635 }
636
637 # endchoice
638 elsif ( $line =~ /^\s*endchoice/ ) {
639 $inside_config = "";
640 if ( !$inside_choice ) {
Martin Roth7aa3cea2015-11-27 18:45:45 -0700641 show_error("'endchoice' keyword not within a choice block at $filename:$line_no.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600642 }
643
644 $inside_choice = "";
645 if ( $configs_inside_choice == 0 ) {
Martin Roth7aa3cea2015-11-27 18:45:45 -0700646 show_error("choice block has no symbols at $filename:$line_no.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600647 }
648 $configs_inside_choice = 0;
649 }
650
651 # [optional]
652 elsif ( $line =~ /^\s*optional/ ) {
653 if ($inside_config) {
Martin Roth1b44f7e2016-01-11 14:31:38 -0700654 show_error( "Keyword 'optional' appears inside config for '$inside_config'"
655 . " at $filename:$line_no. This is not valid." );
Martin Rothbcaaad12015-10-18 11:16:25 -0600656 }
657 if ( !$inside_choice ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -0700658 show_error( "Keyword 'optional' appears outside of a choice block"
659 . " at $filename:$line_no. This is not valid." );
Martin Rothbcaaad12015-10-18 11:16:25 -0600660 }
661 }
662
663 # mainmenu <prompt>
664 elsif ( $line =~ /^\s*mainmenu/ ) {
665 $inside_config = "";
Martin Roth08cf90f2016-01-25 19:54:16 -0700666
667 # Kconfig alread checks for multiple 'mainmenu' entries and mainmenu entries with no prompt
668 # Possible check: look for 'mainmenu ""'
669 # Possible check: verify that a mainmenu has been specified
Martin Rothbcaaad12015-10-18 11:16:25 -0600670 }
671
672 # menu <prompt>
673 elsif ( $line =~ /^\s*menu/ ) {
674 $line =~ /^\s*menu\s+(.*)/;
675 my $menu = $1;
676 if ( $menu =~ /^\s*"([^"]*)"\s*$/ ) {
677 $menu = $1;
678 }
679
680 $inside_config = "";
681 $inside_choice = "";
682 push( @inside_menu, $menu );
683 }
684
Patrick Georgifcc29502018-09-16 21:35:46 +0200685 # visible if <expr>
686 elsif ( $line =~ /^\s*visible if.*$/ ) {
687 # Must come directly after menu line (and on a separate line)
688 # but kconfig already checks for that.
689 # Ignore it.
690 }
691
Martin Rothbcaaad12015-10-18 11:16:25 -0600692 # endmenu
693 elsif ( $line =~ /^\s*endmenu/ ) {
694 $inside_config = "";
695 $inside_choice = "";
696 pop @inside_menu;
697 }
698
699 # "if" <expr>
700 elsif ( $line =~ /^\s*if/ ) {
701 $inside_config = "";
702 $line =~ /^\s*if\s+(.*)$/;
703 my $expr = $1;
704 push( @inside_if, $expr );
705 handle_expressions( $expr, $inside_config, $filename, $line_no );
Martin Roth0e6c0e12016-03-02 12:16:13 -0700706 $fileinfo{$filename}{iflevel}++;
Martin Rothbcaaad12015-10-18 11:16:25 -0600707 }
708
709 # endif
710 elsif ( $line =~ /^\s*endif/ ) {
711 $inside_config = "";
712 pop(@inside_if);
Martin Roth0e6c0e12016-03-02 12:16:13 -0700713 $fileinfo{$filename}{iflevel}--;
Martin Rothbcaaad12015-10-18 11:16:25 -0600714 }
715
716 #range <symbol> <symbol> [if <expr>]
717 elsif ( $line =~ /^\s*range/ ) {
718 $line =~ /^\s*range\s+(\S+)\s+(.*)$/;
719 handle_range( $1, $2, $inside_config, $filename, $line_no );
720 }
721
722 # select <symbol> [if <expr>]
723 elsif ( $line =~ /^\s*select/ ) {
724 unless ($inside_config) {
Martin Roth7aa3cea2015-11-27 18:45:45 -0700725 show_error("Keyword 'select' appears outside of config at $filename:$line_no. This is not valid.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600726 }
727
728 if ( $line =~ /^\s*select\s+(.*)$/ ) {
729 $line = $1;
730 my $expression;
731 ( $line, $expression ) = handle_if_line( $line, $inside_config, $filename, $line_no );
732 if ($line) {
Martin Rothb7c39b22016-01-14 09:04:53 -0700733 add_referenced_symbol( $line, $filename, $line_no, 'select' );
Martin Rothbcaaad12015-10-18 11:16:25 -0600734 }
735 }
736 }
737
738 # source <prompt>
739 elsif ( $line =~ /^\s*source\s+"?([^"\s]+)"?\s*(?>#.*)?$/ ) {
740 my @newfile = load_kconfig_file( $1, $filename, $line_no, 0, $filename, $line_no );
741 unshift( @config_to_parse, @newfile );
742 $parseline[0]{text} = "# '$line'\n";
743 }
744 elsif (
745 ( $line =~ /^\s*#/ ) || #comments
746 ( $line =~ /^\s*$/ ) #blank lines
747 )
748 {
749 # do nothing
750 }
751 else {
Martin Roth811d93a2017-04-06 11:06:00 -0600752 if ($lastline_was_help) {
753 show_error("The line \"$line\" ($filename:$line_no) wasn't recognized - supposed to be inside help?");
754 }
755 else {
756 show_error("The line \"$line\" ($filename:$line_no) wasn't recognized");
757 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600758 }
759
Martin Roth819e6722016-01-25 16:38:05 -0700760 if ( defined $inside_menu[0] ) {
761 $parseline[0]{menus} = "";
762 }
763 else {
764 $parseline[0]{menus} = "top";
765 }
766
767 my $i = 0;
768 while ( defined $inside_menu[$i] ) {
769 $parseline[0]{menus} .= "$inside_menu[$i]";
770 $i++;
771 if ( defined $inside_menu[$i] ) {
772 $parseline[0]{menus} .= "->";
773 }
774 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600775 push @wholeconfig, @parseline;
776 }
Martin Roth0e6c0e12016-03-02 12:16:13 -0700777
778 foreach my $file ( keys %fileinfo ) {
779 if ( $fileinfo{$file}{iflevel} > 0 ) {
780 show_error("$file has $fileinfo{$file}{iflevel} more 'if' statement(s) than 'endif' statements.");
781 }
782 elsif ( $fileinfo{$file}{iflevel} < 0 ) {
783 show_error(
784 "$file has " . ( $fileinfo{$file}{iflevel} * -1 ) . " more 'endif' statement(s) than 'if' statements." );
785 }
786 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600787}
788
789#-------------------------------------------------------------------------------
790#-------------------------------------------------------------------------------
791sub handle_depends {
792 my ( $expr, $inside_config, $inside_choice, $filename, $line_no ) = @_;
793
794 if ($inside_config) {
795 my $sym_num = $symbols{$inside_config}{count};
796 if ( exists $symbols{$inside_config}{$sym_num}{max_dependency} ) {
797 $symbols{$inside_config}{$sym_num}{max_dependency}++;
798 }
799 else {
800 $symbols{$inside_config}{$sym_num}{max_dependency} = 0;
801 }
802
803 my $dep_num = $symbols{$inside_config}{$sym_num}{max_dependency};
804 $symbols{$inside_config}{$sym_num}{dependency}{$dep_num} = $expr;
805 }
806}
807
808#-------------------------------------------------------------------------------
809#-------------------------------------------------------------------------------
810sub add_symbol {
Martin Rothb7c39b22016-01-14 09:04:53 -0700811 my ( $symbol, $menu_array_ref, $filename, $line_no, $ifref, $inside_choice ) = @_;
Martin Rothbcaaad12015-10-18 11:16:25 -0600812 my @inside_if = @{$ifref};
813
814 #initialize the symbol or increment the use count.
Martin Roth1b44f7e2016-01-11 14:31:38 -0700815 if ( ( !exists $symbols{$symbol} ) || ( !exists $symbols{$symbol}{count} ) ) {
Martin Rothbcaaad12015-10-18 11:16:25 -0600816 $symbols{$symbol}{count} = 0;
Martin Rothb7c39b22016-01-14 09:04:53 -0700817 if ($inside_choice) {
818 $symbols{$symbol}{choice} = 1;
819 }
820 else {
821 $symbols{$symbol}{choice} = 0;
822 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600823 }
824 else {
825 $symbols{$symbol}{count}++;
Martin Rothb7c39b22016-01-14 09:04:53 -0700826
827 if ( $inside_choice && !$symbols{$symbol}{choice} ) {
828 show_error( "$symbol entry at $filename:$line_no has already been created inside a choice block "
829 . "at $symbols{$symbol}{0}{file}:$symbols{$symbol}{0}{line_no}." );
830 }
831 elsif ( !$inside_choice && $symbols{$symbol}{choice} ) {
832 show_error( "$symbol entry at $filename:$line_no has already been created outside a choice block "
833 . "at $symbols{$symbol}{0}{file}:$symbols{$symbol}{0}{line_no}." );
834 }
Martin Rothaa206472017-03-24 08:51:51 -0600835 elsif ( $inside_choice && $symbols{$symbol}{choice} ) {
836 show_error( "$symbol entry at $filename:$line_no has already been created inside another choice block "
837 . "at $symbols{$symbol}{0}{file}:$symbols{$symbol}{0}{line_no}." );
838 }
Martin Rothbcaaad12015-10-18 11:16:25 -0600839 }
840
841 # add the location of this instance
842 my $symcount = $symbols{$symbol}{count};
843 $symbols{$symbol}{$symcount}{file} = $filename;
844 $symbols{$symbol}{$symcount}{line_no} = $line_no;
845
846 #Add the menu structure
847 if ( defined @$menu_array_ref[0] ) {
848 $symbols{$symbol}{$symcount}{menu} = $menu_array_ref;
849 }
850
851 #Add any 'if' statements that the symbol is inside as dependencies
852 if (@inside_if) {
853 my $dep_num = 0;
854 for my $dependency (@inside_if) {
855 $symbols{$symbol}{$symcount}{dependency}{$dep_num} = $dependency;
856 $symbols{$symbol}{$symcount}{max_dependency} = $dep_num;
857 $dep_num++;
858 }
859 }
860}
861
862#-------------------------------------------------------------------------------
863# handle range
864#-------------------------------------------------------------------------------
865sub handle_range {
866 my ( $range1, $range2, $inside_config, $filename, $line_no ) = @_;
867
868 my $expression;
869 ( $range2, $expression ) = handle_if_line( $range2, $inside_config, $filename, $line_no );
870
871 $range1 =~ /^\s*(?:0x)?([A-Fa-f0-9]+)\s*$/;
872 my $checkrange1 = $1;
873 $range2 =~ /^\s*(?:0x)?([A-Fa-f0-9]+)\s*$/;
874 my $checkrange2 = $1;
875
876 if ( $checkrange1 && $checkrange2 && ( hex($checkrange1) > hex($checkrange2) ) ) {
Martin Rothd8080172015-11-26 19:12:44 -0700877 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 -0600878 }
879
880 if ($inside_config) {
881 if ( exists( $symbols{$inside_config}{range1} ) ) {
882 if ( ( $symbols{$inside_config}{range1} != $range1 ) || ( $symbols{$inside_config}{range2} != $range2 ) ) {
Martin Rothd8080172015-11-26 19:12:44 -0700883 if ($show_note_output) {
Martin Roth7aa3cea2015-11-27 18:45:45 -0700884 print "#!!!!! Note: Config '$inside_config' range entry $range1 $range2 at $filename:$line_no does";
Martin Roth1b44f7e2016-01-11 14:31:38 -0700885 print " not match the previously defined range $symbols{$inside_config}{range1}"
886 . " $symbols{$inside_config}{range2}";
Martin Roth7aa3cea2015-11-27 18:45:45 -0700887 print " defined at $symbols{$inside_config}{range_file}:$symbols{$inside_config}{range_line_no}.\n";
Martin Rothbcaaad12015-10-18 11:16:25 -0600888 }
889 }
890 }
891 else {
892 $symbols{$inside_config}{range1} = $range1;
893 $symbols{$inside_config}{range2} = $range2;
894 $symbols{$inside_config}{range_file} = $filename;
895 $symbols{$inside_config}{range_line_no} = $line_no;
896 }
897 }
898 else {
Martin Roth7aa3cea2015-11-27 18:45:45 -0700899 show_error("Range entry at $filename:$line_no is not inside a config block.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600900 }
901}
902
903#-------------------------------------------------------------------------------
904# handle_default
905#-------------------------------------------------------------------------------
906sub handle_default {
907 my ( $default, $name, $inside_config, $inside_choice, $filename, $line_no ) = @_;
908 my $expression;
909 ( $default, $expression ) = handle_if_line( $default, $inside_config, $filename, $line_no );
910
911 if ($inside_config) {
912 handle_expressions( $default, $inside_config, $filename, $line_no );
913 my $sym_num = $symbols{$inside_config}{count};
914
915 unless ( exists $symbols{$inside_config}{$sym_num}{default_max} ) {
916 $symbols{$inside_config}{$sym_num}{default_max} = 0;
917 }
918 my $default_max = $symbols{$inside_config}{$sym_num}{default_max};
919 $symbols{$inside_config}{$sym_num}{default}{$default_max}{default} = $default;
920 $symbols{$inside_config}{$sym_num}{default}{$default_max}{default_line_no} = $line_no;
921 if ($expression) {
922 $symbols{$inside_config}{$sym_num}{default}{$default_max}{default_depends_on} = $expression;
923 }
924 }
925 elsif ($inside_choice) {
926 handle_expressions( $default, $inside_config, $filename, $line_no );
927 }
928 else {
Martin Roth7aa3cea2015-11-27 18:45:45 -0700929 show_error("$name entry at $filename:$line_no is not inside a config or choice block.");
Martin Rothbcaaad12015-10-18 11:16:25 -0600930 }
931}
932
933#-------------------------------------------------------------------------------
934# handle_if_line
935#-------------------------------------------------------------------------------
936sub handle_if_line {
937 my ( $exprline, $inside_config, $filename, $line_no ) = @_;
938
939 if ( $exprline !~ /if/ ) {
940 return ( $exprline, "" );
941 }
942
943 #remove any quotes that might have an 'if' in them
944 my $savequote;
945 if ( $exprline =~ /^\s*("[^"]+")/ ) {
946 $savequote = $1;
947 $exprline =~ s/^\s*("[^"]+")//;
948 }
949
950 my $expr = "";
951 if ( $exprline =~ /\s*if\s+(.*)$/ ) {
952 $expr = $1;
953 $exprline =~ s/\s*if\s+.*$//;
954
955 if ($expr) {
956 handle_expressions( $expr, $inside_config, $filename, $line_no );
957 }
958 }
959
960 if ($savequote) {
961 $exprline = $savequote;
962 }
963
964 return ( $exprline, $expr );
965}
966
967#-------------------------------------------------------------------------------
968# handle_expressions - log which symbols are being used
969#-------------------------------------------------------------------------------
970sub handle_expressions {
971 my ( $exprline, $inside_config, $filename, $line_no ) = @_;
972
973 return unless ($exprline);
974
975 #filter constant symbols first
Martin Roth1b44f7e2016-01-11 14:31:38 -0700976 if ( $exprline =~ /^\s*"?([yn])"?\s*$/ ) { # constant y/n
Martin Rothbcaaad12015-10-18 11:16:25 -0600977 return;
978 }
Martin Roth1b44f7e2016-01-11 14:31:38 -0700979 elsif ( $exprline =~ /^\s*"?((?:-)\d+)"?\s*$/ ) { # int values
Martin Rothbcaaad12015-10-18 11:16:25 -0600980 return;
981 }
982 elsif ( $exprline =~ /^\s*"?((?:-)?(?:0x)?\p{XDigit})+"?\s*$/ ) { # hex values
983 return;
984 }
985 elsif ( $exprline =~ /^\s*("[^"]*")\s*$/ ) { # String values
986 return;
987 }
988 elsif ( $exprline =~ /^\s*([A-Za-z0-9_]+)\s*$/ ) { # <symbol> (1)
Martin Rothb7c39b22016-01-14 09:04:53 -0700989 add_referenced_symbol( $1, $filename, $line_no, 'expression' );
Martin Rothbcaaad12015-10-18 11:16:25 -0600990 }
991 elsif ( $exprline =~ /^\s*!(.+)$/ ) { # '!' <expr> (5)
992
993 handle_expressions( $1, $inside_config, $filename, $line_no );
994 }
995 elsif ( $exprline =~ /^\s*\(([^)]+)\)\s*$/ ) { # '(' <expr> ')' (4)
996 handle_expressions( $1, $inside_config, $filename, $line_no );
997 }
998 elsif ( $exprline =~ /^\s*(.+)\s*!=\s*(.+)\s*$/ ) { # <symbol> '!=' <symbol> (3)
999 handle_expressions( $1, $inside_config, $filename, $line_no );
1000 handle_expressions( $2, $inside_config, $filename, $line_no );
1001 }
1002 elsif ( $exprline =~ /^\s*(.+)\s*=\s*(.+)\s*$/ ) { # <symbol> '=' <symbol> (2)
1003 handle_expressions( $1, $inside_config, $filename, $line_no );
1004 handle_expressions( $2, $inside_config, $filename, $line_no );
1005 }
1006 elsif ( $exprline =~ /^\s*([^(]+|\(.+\))\s*&&\s*(.+)\s*$/ ) { # <expr> '&&' <expr> (6)
1007 handle_expressions( $1, $inside_config, $filename, $line_no );
1008 handle_expressions( $2, $inside_config, $filename, $line_no );
1009 }
1010 elsif ( $exprline =~ /^\s*([^(]+|\(.+\))\s*\|\|\s*(.+)\s*$/ ) { # <expr> '||' <expr> (7)
1011 handle_expressions( $1, $inside_config, $filename, $line_no );
1012 handle_expressions( $2, $inside_config, $filename, $line_no );
1013 }
1014
1015 # work around kconfig spec violation for now - paths not in quotes
1016 elsif ( $exprline =~ /^\s*([A-Za-z0-9_\-\/]+)\s*$/ ) { # <symbol> (1)
1017 return;
1018 }
1019 else {
Martin Rothd8080172015-11-26 19:12:44 -07001020 show_error("Unrecognized expression '$exprline' in $filename line $line_no.");
Martin Rothbcaaad12015-10-18 11:16:25 -06001021 }
1022
1023 return;
1024}
1025
1026#-------------------------------------------------------------------------------
1027# add_referenced_symbol
1028#-------------------------------------------------------------------------------
1029sub add_referenced_symbol {
Martin Rothb7c39b22016-01-14 09:04:53 -07001030 my ( $symbol, $filename, $line_no, $reftype ) = @_;
Martin Rothbcaaad12015-10-18 11:16:25 -06001031 if ( exists $referenced_symbols{$symbol} ) {
1032 $referenced_symbols{$symbol}{count}++;
1033 $referenced_symbols{$symbol}{ $referenced_symbols{$symbol}{count} }{filename} = $filename;
1034 $referenced_symbols{$symbol}{ $referenced_symbols{$symbol}{count} }{line_no} = $line_no;
1035 }
1036 else {
1037 $referenced_symbols{$symbol}{count} = 0;
1038 $referenced_symbols{$symbol}{0}{filename} = $filename;
1039 $referenced_symbols{$symbol}{0}{line_no} = $line_no;
1040 }
Martin Rothb7c39b22016-01-14 09:04:53 -07001041
1042 #mark the symbol as being selected, use referenced symbols for location
1043 if ( $reftype eq 'select' ) {
1044 $selected_symbols{$symbol}{ $referenced_symbols{$symbol}{count} } = 1;
1045 }
Martin Rothbcaaad12015-10-18 11:16:25 -06001046}
1047
1048#-------------------------------------------------------------------------------
1049# handle_help
1050#-------------------------------------------------------------------------------
1051{
1052 #create a non-global static variable by enclosing it and the subroutine
1053 my $help_whitespace = ""; #string to show length of the help whitespace
Martin Roth8849f3b2017-05-23 19:43:43 -06001054 my $help_keyword_whitespace = "";
Martin Rothbcaaad12015-10-18 11:16:25 -06001055
1056 sub handle_help {
1057 my ( $line, $inside_help, $inside_config, $inside_choice, $filename, $line_no ) = @_;
1058
1059 if ($inside_help) {
1060
1061 #get the indentation level if it's not already set.
1062 if ( ( !$help_whitespace ) && ( $line !~ /^[\r\n]+/ ) ) {
1063 $line =~ /^(\s+)/; #find the indentation level.
1064 $help_whitespace = $1;
1065 if ( !$help_whitespace ) {
Martin Roth8849f3b2017-05-23 19:43:43 -06001066 show_error("$filename:$line_no - help text starts with no whitespace.");
1067 return $inside_help;
1068 }
1069 elsif ($help_keyword_whitespace eq $help_whitespace) {
1070 show_error("$filename:$line_no - help text needs additional indentation.");
Martin Rothbcaaad12015-10-18 11:16:25 -06001071 return $inside_help;
Martin Rothbcaaad12015-10-18 11:16:25 -06001072 }
1073 }
1074
1075 #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 -06001076 if ( ( $line !~ /^$help_whitespace/ ) && ( $line !~ /^[\r\n]+/ ) ) {
Martin Rothbcaaad12015-10-18 11:16:25 -06001077 $inside_help = 0;
1078 $help_whitespace = "";
Martin Roth8849f3b2017-05-23 19:43:43 -06001079 $help_keyword_whitespace = "";
Martin Rothbcaaad12015-10-18 11:16:25 -06001080 }
1081 else { #if it's not ended, add the line to the helptext array for the symbol's instance
1082 if ($inside_config) {
1083 my $sym_num = $symbols{$inside_config}{count};
1084 if ($help_whitespace) { $line =~ s/^$help_whitespace//; }
1085 push( @{ $symbols{$inside_config}{$sym_num}{helptext} }, $line );
1086 }
Martin Roth8849f3b2017-05-23 19:43:43 -06001087 if ( ($help_keyword_whitespace eq $help_whitespace) && ( $line !~ /^[\r\n]+/ ) ) {
1088 show_error("$filename:$line_no - help text needs additional indentation.");
1089 }
Martin Rothbcaaad12015-10-18 11:16:25 -06001090 }
1091 }
1092 elsif ( ( $line =~ /^(\s*)help/ ) || ( $line =~ /^(\s*)---help---/ ) ) {
1093 $inside_help = $line_no;
Martin Roth8849f3b2017-05-23 19:43:43 -06001094 $line =~ /^(\s+)/;
1095 $help_keyword_whitespace = $1;
Martin Rothbcaaad12015-10-18 11:16:25 -06001096 if ( ( !$inside_config ) && ( !$inside_choice ) ) {
Martin Rothd8080172015-11-26 19:12:44 -07001097 if ($show_note_output) {
Martin Roth7aa3cea2015-11-27 18:45:45 -07001098 print "# Note: $filename:$line_no help is not inside a config or choice block.\n";
Martin Rothbcaaad12015-10-18 11:16:25 -06001099 }
Martin Rothbcaaad12015-10-18 11:16:25 -06001100 }
1101 elsif ($inside_config) {
1102 $help_whitespace = "";
1103 my $sym_num = $symbols{$inside_config}{count};
1104 $symbols{$inside_config}{$sym_num}{help_line_no} = $line_no;
1105 $symbols{$inside_config}{$sym_num}{helptext} = ();
1106 }
1107 }
1108 return $inside_help;
1109 }
1110}
1111
1112#-------------------------------------------------------------------------------
1113# handle_type
1114#-------------------------------------------------------------------------------
1115sub handle_type {
1116 my ( $type, $inside_config, $filename, $line_no ) = @_;
1117
1118 my $expression;
1119 ( $type, $expression ) = handle_if_line( $type, $inside_config, $filename, $line_no );
1120
Martin Roth08ee1cf2016-01-25 16:39:32 -07001121 if ( $type =~ /tristate/ ) {
1122 show_warning("$filename:$line_no - tristate types are not used.");
1123 }
1124
Martin Rothbcaaad12015-10-18 11:16:25 -06001125 if ($inside_config) {
1126 if ( exists( $symbols{$inside_config}{type} ) ) {
1127 if ( $symbols{$inside_config}{type} !~ /$type/ ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -07001128 show_error( "Config '$inside_config' type entry $type"
1129 . " at $filename:$line_no does not match $symbols{$inside_config}{type}"
1130 . " defined at $symbols{$inside_config}{type_file}:$symbols{$inside_config}{type_line_no}." );
Martin Rothbcaaad12015-10-18 11:16:25 -06001131 }
1132 }
1133 else {
1134 $symbols{$inside_config}{type} = $type;
1135 $symbols{$inside_config}{type_file} = $filename;
1136 $symbols{$inside_config}{type_line_no} = $line_no;
1137 }
1138 }
1139 else {
Martin Roth7aa3cea2015-11-27 18:45:45 -07001140 show_error("Type entry at $filename:$line_no is not inside a config block.");
Martin Rothbcaaad12015-10-18 11:16:25 -06001141 }
1142}
1143
1144#-------------------------------------------------------------------------------
1145# handle_prompt
1146#-------------------------------------------------------------------------------
1147sub handle_prompt {
1148 my ( $prompt, $name, $menu_array_ref, $inside_config, $inside_choice, $filename, $line_no ) = @_;
1149
1150 my $expression;
1151 ( $prompt, $expression ) = handle_if_line( $prompt, $inside_config, $filename, $line_no );
1152
1153 if ($inside_config) {
1154 if ( $prompt !~ /^\s*$/ ) {
1155 if ( $prompt =~ /^\s*"([^"]*)"\s*$/ ) {
1156 $prompt = $1;
1157 }
1158
Martin Roth08cf90f2016-01-25 19:54:16 -07001159 #display an error if there's a prompt at the top menu level
Martin Rothbcaaad12015-10-18 11:16:25 -06001160 if ( !defined @$menu_array_ref[0] ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -07001161 show_error( "Symbol '$inside_config' with prompt '$prompt' appears outside of a menu"
1162 . " at $filename:$line_no." );
Martin Rothbcaaad12015-10-18 11:16:25 -06001163 }
1164
1165 my $sym_num = $symbols{$inside_config}{count};
Martin Rothb58d3492016-01-25 16:42:13 -07001166 if ( !exists $symbols{$inside_config}{$sym_num}{prompt_max} ) {
Martin Rothbcaaad12015-10-18 11:16:25 -06001167 $symbols{$inside_config}{$sym_num}{prompt_max} = 0;
1168 }
Martin Rothb58d3492016-01-25 16:42:13 -07001169 else {
1170 $symbols{$inside_config}{$sym_num}{prompt_max}++;
1171 }
Martin Rothbcaaad12015-10-18 11:16:25 -06001172 my $prompt_max = $symbols{$inside_config}{$sym_num}{prompt_max};
1173 $symbols{$inside_config}{$sym_num}{prompt}{$prompt_max}{prompt} = $prompt;
1174 $symbols{$inside_config}{$sym_num}{prompt}{$prompt_max}{prompt_line_no} = $line_no;
Martin Rothb58d3492016-01-25 16:42:13 -07001175
1176 $symbols{$inside_config}{$sym_num}{prompt}{$prompt_max}{prompt_menu} = @$menu_array_ref;
Martin Rothbcaaad12015-10-18 11:16:25 -06001177 if ($expression) {
1178 $symbols{$inside_config}{$sym_num}{prompt}{$prompt_max}{prompt_depends_on} = $expression;
1179 }
1180 }
1181 }
1182 elsif ($inside_choice) {
1183
1184 #do nothing
1185 }
1186 else {
Martin Roth7aa3cea2015-11-27 18:45:45 -07001187 show_error("$name entry at $filename:$line_no is not inside a config or choice block.");
Martin Rothbcaaad12015-10-18 11:16:25 -06001188 }
1189}
1190
1191#-------------------------------------------------------------------------------
1192# simple_line_checks - Does some basic checks on the current line, then cleans the line
1193# up for further processing.
1194#-------------------------------------------------------------------------------
1195sub simple_line_checks {
1196 my ( $line, $filename, $line_no ) = @_;
1197
1198 #check for spaces instead of tabs
1199 if ( $line =~ /^ +/ ) {
Martin Roth7aa3cea2015-11-27 18:45:45 -07001200 show_error("$filename:$line_no starts with a space.");
Martin Rothbcaaad12015-10-18 11:16:25 -06001201 }
1202
1203 #verify a linefeed at the end of the line
1204 if ( $line !~ /.*\n/ ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -07001205 show_error( "$filename:$line_no does not end with linefeed."
1206 . " This can cause the line to not be recognized by the Kconfig parser.\n#($line)" );
Martin Rothbcaaad12015-10-18 11:16:25 -06001207 $line =~ s/\s*$//;
1208 }
1209 else {
1210 chop($line);
1211 }
1212
1213 return $line;
1214}
1215
1216#-------------------------------------------------------------------------------
1217# load_kconfig_file - Loads a single Kconfig file or expands * wildcard
1218#-------------------------------------------------------------------------------
1219sub load_kconfig_file {
1220 my ( $input_file, $loadfile, $loadline, $expanded, $topfile, $topline ) = @_;
1221 my @file_data;
1222 my @dir_file_data;
1223
1224 #recursively handle coreboot's new source glob operator
1225 if ( $input_file =~ /^(.*?)\/\*\/(.*)$/ ) {
1226 my $dir_prefix = $1;
1227 my $dir_suffix = $2;
1228 if ( -d "$dir_prefix" ) {
1229
1230 opendir( D, "$dir_prefix" ) || die "Can't open directory '$dir_prefix'\n";
1231 my @dirlist = sort { $a cmp $b } readdir(D);
1232 closedir(D);
1233
1234 while ( my $directory = shift @dirlist ) {
1235
1236 #ignore non-directory files
1237 if ( ( -d "$dir_prefix/$directory" ) && !( $directory =~ /^\..*/ ) ) {
Martin Roth1b44f7e2016-01-11 14:31:38 -07001238 push @dir_file_data,
1239 load_kconfig_file( "$dir_prefix/$directory/$dir_suffix",
1240 $input_file, $loadline, 1, $loadfile, $loadline );
Martin Rothbcaaad12015-10-18 11:16:25 -06001241 }
1242 }
1243 }
1244
1245 #the directory should exist when using a glob
1246 else {
Martin Rothd8080172015-11-26 19:12:44 -07001247 show_warning("Could not find dir '$dir_prefix'");
Martin Rothbcaaad12015-10-18 11:16:25 -06001248 }
1249 }
1250
1251 #if the file exists, try to load it.
1252 elsif ( -e "$input_file" ) {
1253
Martin Rotha7d00272016-10-03 23:00:04 +02001254 #throw a warning if the file has already been loaded.
Martin Rothbcaaad12015-10-18 11:16:25 -06001255 if ( exists $loaded_files{$input_file} ) {
Martin Rotha7d00272016-10-03 23:00:04 +02001256 show_warning("'$input_file' sourced at $loadfile:$loadline was already loaded by $loaded_files{$input_file}");
Martin Rothbcaaad12015-10-18 11:16:25 -06001257 }
1258
1259 #load the file's contents and mark the file as loaded for checking later
1260 open( my $HANDLE, "<", "$input_file" ) or die "Error: could not open file '$input_file'\n";
1261 @file_data = <$HANDLE>;
1262 close $HANDLE;
1263 $loaded_files{$input_file} = "'$loadfile' line $loadline";
1264 }
1265
1266 # if the file isn't being loaded from a glob, it should exist.
1267 elsif ( $expanded == 0 ) {
Martin Roth7aa3cea2015-11-27 18:45:45 -07001268 show_warning("Could not find file '$input_file' sourced at $loadfile:$loadline");
Martin Rothbcaaad12015-10-18 11:16:25 -06001269 }
1270
1271 my $line_in_file = 0;
1272 while ( my $line = shift @file_data ) {
1273
1274 #handle line continuation.
1275 my $continue_line = 0;
Martin Roth1b44f7e2016-01-11 14:31:38 -07001276 while ( $line =~ /(.*)\s+\\$/ ) {
Martin Rothbcaaad12015-10-18 11:16:25 -06001277 my $text = $1;
1278
1279 # get rid of leading whitespace on all but the first and last lines
1280 $text =~ s/^\s*/ / if ($continue_line);
1281
1282 $dir_file_data[$line_in_file]{text} .= $text;
1283 $line = shift @file_data;
1284 $continue_line++;
1285
1286 #put the data into the continued lines (other than the first)
1287 $line =~ /^\s*(.*)\s*$/;
1288
Martin Roth1b44f7e2016-01-11 14:31:38 -07001289 $dir_file_data[ $line_in_file + $continue_line ]{text} = "\t# continued line ( " . $1 . " )\n";
1290 $dir_file_data[ $line_in_file + $continue_line ]{filename} = $input_file;
1291 $dir_file_data[ $line_in_file + $continue_line ]{file_line_no} = $line_in_file + $continue_line + 1;
Martin Rothbcaaad12015-10-18 11:16:25 -06001292
1293 #get rid of multiple leading spaces for last line
1294 $line = " $1\n";
1295 }
1296
Martin Roth1b44f7e2016-01-11 14:31:38 -07001297 $dir_file_data[$line_in_file]{text} .= $line;
Martin Rothbcaaad12015-10-18 11:16:25 -06001298 $dir_file_data[$line_in_file]{filename} = $input_file;
1299 $dir_file_data[$line_in_file]{file_line_no} = $line_in_file + 1;
1300
1301 $line_in_file++;
1302 if ($continue_line) {
1303 $line_in_file += $continue_line;
1304 }
1305 }
1306
1307 if ($topfile) {
1308 my %file_data;
Martin Roth1b44f7e2016-01-11 14:31:38 -07001309 $file_data{text} = "\t### File '$input_file' loaded from '$topfile' line $topline\n";
Martin Rothbcaaad12015-10-18 11:16:25 -06001310 $file_data{filename} = $topfile;
1311 $file_data{file_line_no} = "($topline)";
Martin Roth1b44f7e2016-01-11 14:31:38 -07001312 unshift( @dir_file_data, \%file_data );
Martin Rothbcaaad12015-10-18 11:16:25 -06001313 }
1314
1315 return @dir_file_data;
1316}
1317
Martin Rothbcaaad12015-10-18 11:16:25 -06001318#-------------------------------------------------------------------------------
1319# print_wholeconfig - prints out the parsed Kconfig file
1320#-------------------------------------------------------------------------------
1321sub print_wholeconfig {
1322
1323 return unless $print_full_output;
1324
1325 for ( my $i = 0 ; $i < $#wholeconfig ; $i++ ) {
1326 my $line = $wholeconfig[$i];
1327 chop( $line->{text} );
1328
1329 #replace tabs with spaces for consistency
1330 $line->{text} =~ s/\t/ /g;
Martin Roth819e6722016-01-25 16:38:05 -07001331 printf "%-120s # $line->{filename} line $line->{file_line_no} ($line->{menus})\n", $line->{text};
Martin Rothbcaaad12015-10-18 11:16:25 -06001332 }
1333}
1334
1335#-------------------------------------------------------------------------------
1336# check_if_file_referenced - checks for kconfig files that are not being parsed
1337#-------------------------------------------------------------------------------
1338sub check_if_file_referenced {
1339 my $filename = $File::Find::name;
Martin Rothab2d7772016-01-25 16:45:14 -07001340 if ( ( $filename =~ /Kconfig/ )
1341 && ( !$filename =~ /\.orig$/ )
1342 && ( !$filename =~ /~$/ )
1343 && ( !exists $loaded_files{$filename} ) )
1344 {
Martin Rothd8080172015-11-26 19:12:44 -07001345 show_warning("'$filename' is never referenced");
Martin Rothbcaaad12015-10-18 11:16:25 -06001346 }
1347}
1348
1349#-------------------------------------------------------------------------------
1350# check_arguments parse the command line arguments
1351#-------------------------------------------------------------------------------
1352sub check_arguments {
1353 my $show_usage = 0;
1354 GetOptions(
1355 'help|?' => sub { usage() },
Martin Rothd8080172015-11-26 19:12:44 -07001356 'e|errors_off' => \$suppress_error_output,
1357 'n|notes' => \$show_note_output,
Martin Rothbcaaad12015-10-18 11:16:25 -06001358 'o|output=s' => \$output_file,
1359 'p|print' => \$print_full_output,
Martin Rothd8080172015-11-26 19:12:44 -07001360 'w|warnings_off' => \$suppress_warning_output,
Martin Rothbcaaad12015-10-18 11:16:25 -06001361 'path=s' => \$top_dir,
1362 'c|config=s' => \$config_file,
1363 'G|no_git_grep' => \$dont_use_git_grep,
1364 );
Martin Rothd8080172015-11-26 19:12:44 -07001365
1366 if ($suppress_error_output) {
1367 $suppress_warning_output = 1;
1368 }
1369 if ($suppress_warning_output) {
Martin Roth1b44f7e2016-01-11 14:31:38 -07001370 $show_note_output = 0;
Martin Rothd8080172015-11-26 19:12:44 -07001371 }
Martin Rothbcaaad12015-10-18 11:16:25 -06001372}
1373
1374#-------------------------------------------------------------------------------
1375# usage - Print the arguments for the user
1376#-------------------------------------------------------------------------------
1377sub usage {
1378 print "kconfig_lint <options>\n";
1379 print " -o|--output=file Set output filename\n";
1380 print " -p|--print Print full output\n";
Martin Rothd8080172015-11-26 19:12:44 -07001381 print " -e|--errors_off Don't print warnings or errors\n";
Martin Rothbcaaad12015-10-18 11:16:25 -06001382 print " -w|--warnings_off Don't print warnings\n";
Martin Rothd8080172015-11-26 19:12:44 -07001383 print " -n|--notes Show minor notes\n";
Martin Rothbcaaad12015-10-18 11:16:25 -06001384 print " --path=dir Path to top level kconfig\n";
1385 print " -c|--config=file Filename of config file to load\n";
1386 print " -G|--no_git_grep Use standard grep tools instead of git grep\n";
1387
1388 exit(0);
1389}
1390
13911;