diff options
| author | Joe Perches <joe@perches.com> | 2013-07-03 18:05:34 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-07-03 19:07:45 -0400 |
| commit | 3445686af721534ac1086a9c6d48b3470dfb6946 (patch) | |
| tree | d3b3ece795d3a83e19c8f9e788d3433d275b0bda /scripts | |
| parent | 22735ce857a2d9f4e6eec37c36be3fcf9d21d154 (diff) | |
checkpatch: ignore existing CamelCase uses from include/...
When using --strict, CamelCase uses are described with CHECK: messages.
These CamelCase uses may be acceptable and should not generate these
messages when the variable is already defined in a file from the
include/... path.
So, change checkpatch to read all the .h files in include/... and look
for preexisting CamelCase #defines, typedefs and function prototypes.
Add these to the existing camelcase hash so that any uses in the patch or
file can be ignored.
There are currently ~3500 files in include/. It takes about 10 cpu
seconds on my little netbook to grep for and preseed these existing uses.
That's about 4x the time for a similar git grep.
This preseeding is only done once when using --strict and only when there
is a CamelCase use found.
If a .git directory is found, it uses 'git ls-files include' If not, it
uses 'find $root/include -name "*.h"
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/checkpatch.pl | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 7e8aa1bb0721..70e7f7cdb452 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -31,6 +31,7 @@ my $fix = 0; | |||
| 31 | my $root; | 31 | my $root; |
| 32 | my %debug; | 32 | my %debug; |
| 33 | my %ignore_type = (); | 33 | my %ignore_type = (); |
| 34 | my %camelcase = (); | ||
| 34 | my @ignore = (); | 35 | my @ignore = (); |
| 35 | my $help = 0; | 36 | my $help = 0; |
| 36 | my $configuration_file = ".checkpatch.conf"; | 37 | my $configuration_file = ".checkpatch.conf"; |
| @@ -349,7 +350,6 @@ sub build_types { | |||
| 349 | } | 350 | } |
| 350 | build_types(); | 351 | build_types(); |
| 351 | 352 | ||
| 352 | |||
| 353 | our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*}; | 353 | our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*}; |
| 354 | 354 | ||
| 355 | # Using $balanced_parens, $LvalOrFunc, or $FuncArg | 355 | # Using $balanced_parens, $LvalOrFunc, or $FuncArg |
| @@ -369,6 +369,48 @@ sub deparenthesize { | |||
| 369 | return $string; | 369 | return $string; |
| 370 | } | 370 | } |
| 371 | 371 | ||
| 372 | sub seed_camelcase_file { | ||
| 373 | my ($file) = @_; | ||
| 374 | |||
| 375 | return if (!(-f $file)); | ||
| 376 | |||
| 377 | local $/; | ||
| 378 | |||
| 379 | open(my $include_file, '<', "$file") | ||
| 380 | or warn "$P: Can't read '$file' $!\n"; | ||
| 381 | my $text = <$include_file>; | ||
| 382 | close($include_file); | ||
| 383 | |||
| 384 | my @lines = split('\n', $text); | ||
| 385 | |||
| 386 | foreach my $line (@lines) { | ||
| 387 | next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/); | ||
| 388 | if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) { | ||
| 389 | $camelcase{$1} = 1; | ||
| 390 | } | ||
| 391 | elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*\(/) { | ||
| 392 | $camelcase{$1} = 1; | ||
| 393 | } | ||
| 394 | } | ||
| 395 | } | ||
| 396 | |||
| 397 | my $camelcase_seeded = 0; | ||
| 398 | sub seed_camelcase_includes { | ||
| 399 | return if ($camelcase_seeded); | ||
| 400 | |||
| 401 | my $files; | ||
| 402 | if (-d ".git") { | ||
| 403 | $files = `git ls-files include`; | ||
| 404 | } else { | ||
| 405 | $files = `find $root/include -name "*.h"`; | ||
| 406 | } | ||
| 407 | my @include_files = split('\n', $files); | ||
| 408 | foreach my $file (@include_files) { | ||
| 409 | seed_camelcase_file($file); | ||
| 410 | } | ||
| 411 | $camelcase_seeded = 1; | ||
| 412 | } | ||
| 413 | |||
| 372 | $chk_signoff = 0 if ($file); | 414 | $chk_signoff = 0 if ($file); |
| 373 | 415 | ||
| 374 | my @rawlines = (); | 416 | my @rawlines = (); |
| @@ -1448,7 +1490,6 @@ sub process { | |||
| 1448 | my %suppress_export; | 1490 | my %suppress_export; |
| 1449 | my $suppress_statement = 0; | 1491 | my $suppress_statement = 0; |
| 1450 | 1492 | ||
| 1451 | my %camelcase = (); | ||
| 1452 | 1493 | ||
| 1453 | # Pre-scan the patch sanitizing the lines. | 1494 | # Pre-scan the patch sanitizing the lines. |
| 1454 | # Pre-scan the patch looking for any __setup documentation. | 1495 | # Pre-scan the patch looking for any __setup documentation. |
| @@ -3198,11 +3239,13 @@ sub process { | |||
| 3198 | #Ignore Page<foo> variants | 3239 | #Ignore Page<foo> variants |
| 3199 | $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ && | 3240 | $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ && |
| 3200 | #Ignore SI style variants like nS, mV and dB (ie: max_uV, regulator_min_uA_show) | 3241 | #Ignore SI style variants like nS, mV and dB (ie: max_uV, regulator_min_uA_show) |
| 3201 | $var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/ && | 3242 | $var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/) { |
| 3202 | !defined $camelcase{$var}) { | 3243 | seed_camelcase_includes() if ($check); |
| 3203 | $camelcase{$var} = 1; | 3244 | if (!defined $camelcase{$var}) { |
| 3204 | CHK("CAMELCASE", | 3245 | $camelcase{$var} = 1; |
| 3205 | "Avoid CamelCase: <$var>\n" . $herecurr); | 3246 | CHK("CAMELCASE", |
| 3247 | "Avoid CamelCase: <$var>\n" . $herecurr); | ||
| 3248 | } | ||
| 3206 | } | 3249 | } |
| 3207 | } | 3250 | } |
| 3208 | 3251 | ||
