checkpatch: fix for flag --no-tree
[openocd.git] / tools / scripts / checkpatch.pl
index edbd464b2622514aed53bb462248a133215454df..9dda61cde010bbfa2512730eae67ba4214839f00 100755 (executable)
@@ -78,7 +78,12 @@ my $codespell = 0;
 my $codespellfile = "/usr/share/codespell/dictionary.txt";
 my $user_codespellfile = "";
 my $conststructsfile = "$D/const_structs.checkpatch";
+if (!$OpenOCD) {
 my $docsfile = "$D/../Documentation/dev-tools/checkpatch.rst";
+} # !$OpenOCD
+# OpenOCD Specific: Begin
+my $docsfile = "$D/../../doc/checkpatch.rst";
+# OpenOCD Specific: End
 my $typedefsfile;
 my $color = "auto";
 my $allow_c99_comments = 1; # Can be overridden by --ignore C99_COMMENT_TOLERANCE
@@ -97,7 +102,7 @@ Version: $V
 Options:
   -q, --quiet                quiet
   -v, --verbose              verbose mode
-  --no-tree                  run without a kernel tree
+  --no-tree                  run without an OpenOCD tree
   --no-signoff               do not check for 'Signed-off-by' line
   --patch                    treat FILE as patchfile (default)
   --emacs                    emacs compile window format
@@ -124,7 +129,7 @@ Options:
                              requires --strict for use with --file
   --min-conf-desc-length=n   set the min description length, if shorter, warn
   --tab-size=n               set the number of spaces for tab (default $tabsize)
-  --root=PATH                PATH to the kernel tree root
+  --root=PATH                PATH to the OpenOCD tree root
   --no-summary               suppress the per-file summary
   --mailback                 only produce a report in case of warnings/errors
   --summary-file             include the filename in summary
@@ -461,14 +466,16 @@ if ($tree) {
        } else {
                if (top_of_kernel_tree('.')) {
                        $root = '.';
-               } elsif ($0 =~ m@(.*)/scripts/[^/]*$@ &&
+               # OpenOCD specific: Begin: replace s"/scripts/"/tools/scripts/"
+               } elsif ($0 =~ m@(.*)/tools/scripts/[^/]*$@ &&
                                                top_of_kernel_tree($1)) {
                        $root = $1;
                }
+               # OpenOCD specific: End
        }
 
        if (!defined $root) {
-               print "Must be run from the top-level dir. of a kernel tree\n";
+               print "Must be run from the top-level dir. of an OpenOCD tree\n";
                exit(2);
        }
 }
@@ -597,6 +604,7 @@ our $typeTypedefs = qr{(?x:
 
 our $zero_initializer = qr{(?:(?:0[xX])?0+$Int_type?|NULL|false)\b};
 
+if (!$OpenOCD) {
 our $logFunctions = qr{(?x:
        printk(?:_ratelimited|_once|_deferred_once|_deferred|)|
        (?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)|
@@ -606,6 +614,12 @@ our $logFunctions = qr{(?x:
        MODULE_[A-Z_]+|
        seq_vprintf|seq_printf|seq_puts
 )};
+} # !$OpenOCD
+# OpenOCD specific: Begin: list log functions
+our $logFunctions = qr{(?x:
+       LOG_(?:TARGET_|)(?:DEBUG_IO|DEBUG|INFO|WARNING|ERROR|USER|USER_N|OUTPUT)
+)};
+# OpenOCD specific: End
 
 our $allocFunctions = qr{(?x:
        (?:(?:devm_)?
@@ -979,6 +993,34 @@ sub read_words {
        return 0;
 }
 
+# OpenOCD specific: Begin: Load list of allowed CamelCase symbols
+if (show_type("CAMELCASE")) {
+       my $allowed_camelcase_file = "tools/scripts/camelcase.txt";
+       if (!$root) {
+               warn "Ignore list of allowed camelcase symbols.\n";
+       } elsif (open(my $words, '<', "$root/$allowed_camelcase_file")) {
+               while (<$words>) {
+                        my $line = $_;
+
+                       $line =~ s/\s*\n?$//g;
+                       $line =~ s/^\s*//g;
+
+                       next if ($line =~ m/^\s*#/);
+                       next if ($line =~ m/^\s*$/);
+                       if ($line =~ /\s/) {
+                               print("$allowed_camelcase_file: '$line' invalid - ignored\n");
+                               next;
+                       }
+
+                       $camelcase{$line} = 1;
+               }
+               close("$root/$allowed_camelcase_file");
+       } else {
+               warn "Failed opening file '$root/$allowed_camelcase_file': $!\n";
+       }
+}
+# OpenOCD specific: End
+
 my $const_structs;
 if (show_type("CONST_STRUCT")) {
        read_words(\$const_structs, $conststructsfile)
@@ -1095,6 +1137,7 @@ sub seed_camelcase_file {
        my @lines = split('\n', $text);
 
        foreach my $line (@lines) {
+               if (!$OpenOCD) {
                next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/);
                if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) {
                        $camelcase{$1} = 1;
@@ -1103,6 +1146,17 @@ sub seed_camelcase_file {
                } elsif ($line =~ /^\s*(?:union|struct|enum)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[;\{]/) {
                        $camelcase{$1} = 1;
                }
+               } # !$OpenOCD
+               # OpenOCD Specific: Begin: extend to camel[0-9_]*CASE
+               next if ($line !~ /(?:[A-Z][0-9_]*[a-z]|[a-z][0-9_]*[A-Z])/);
+               if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][0-9_]*[a-z]|[a-z][0-9_]*[A-Z])\w*)/) {
+                       $camelcase{$1} = 1;
+               } elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][0-9_]*[a-z]|[a-z][0-9_]*[A-Z])\w*)\s*[\(\[,;]/) {
+                       $camelcase{$1} = 1;
+               } elsif ($line =~ /^\s*(?:union|struct|enum)\s+(\w*(?:[A-Z][0-9_]*[a-z]|[a-z][0-9_]*[A-Z])\w*)\s*[;\{]/) {
+                       $camelcase{$1} = 1;
+               }
+               # OpenOCD Specific: End
        }
 }
 
@@ -1123,10 +1177,12 @@ sub is_maintained_obsolete {
 sub is_SPDX_License_valid {
        my ($license) = @_;
 
-       return 1 if (!$tree || which("python3") eq "" || !(-x "$root/scripts/spdxcheck.py") || !(-e "$gitroot"));
+       # OpenOCD specific: Begin: replace s"scripts"tools/scripts"
+       return 1 if (!$tree || which("python3") eq "" || !(-x "$root/tools/scripts/spdxcheck.py") || !(-e "$gitroot"));
 
        my $root_path = abs_path($root);
-       my $status = `cd "$root_path"; echo "$license" | scripts/spdxcheck.py -`;
+       my $status = `cd "$root_path"; echo "$license" | tools/scripts/spdxcheck.py -`;
+       # OpenOCD specific: End
        return 0 if ($status ne "");
        return 1;
 }
@@ -1335,11 +1391,21 @@ NOTE: perl $^V is not modern enough to detect all possible issues.
 EOM
        }
        if ($exit) {
+               if (!$OpenOCD) {
                print << "EOM"
 
 NOTE: If any of the errors are false positives, please report
       them to the maintainer, see CHECKPATCH in MAINTAINERS.
 EOM
+               } # !$OpenOCD
+               # OpenOCD specific: Begin
+               print << "EOM"
+
+NOTE: If any of the errors are false positives, please report
+      them to the openocd-devel mailing list or prepare a patch
+      and send it to Gerrit for review.
+EOM
+               # OpenOCD specific: End
        }
 }
 
@@ -1348,11 +1414,19 @@ exit($exit);
 sub top_of_kernel_tree {
        my ($root) = @_;
 
+       if (!$OpenOCD) {
        my @tree_check = (
                "COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile",
                "README", "Documentation", "arch", "include", "drivers",
                "fs", "init", "ipc", "kernel", "lib", "scripts",
        );
+       } # !$OpenOCD
+       # OpenOCD specific: Begin
+       my @tree_check = (
+               "AUTHORS", "BUGS", "COPYING", "HACKING", "Makefile.am",
+               "README", "contrib", "doc", "src", "tcl", "testing", "tools",
+       );
+       # OpenOCD specific: End
 
        foreach my $check (@tree_check) {
                if (! -e $root . '/' . $check) {
@@ -1396,6 +1470,10 @@ sub parse_email {
                        $address = "";
                        $comment = "";
                }
+       # OpenOCD specific: Begin: handle jenkins as valid email
+       } elsif ($formatted_email eq "jenkins") {
+                       $address = "jenkins";
+       # OpenOCD specific: End
        }
 
        # Extract comments from names excluding quoted parts
@@ -2978,6 +3056,13 @@ sub process {
                        }
                }
 
+# OpenOCD specific: Begin: Extend list of checkpatch tests to ignore
+               if ($in_commit_log && $line =~ /^\s*Checkpatch-ignore:\s*(.*)/) {
+                       my @array = split(/[\s,]+/, $1);
+                       hash_save_array_words(\%ignore_type, \@array);
+               }
+# OpenOCD specific: End
+
 # Check for patch separator
                if ($line =~ /^---$/) {
                        $has_patch_separator = 1;
@@ -3367,6 +3452,9 @@ sub process {
 
 # Check for various typo / spelling mistakes
                if (defined($misspellings) &&
+                   # OpenOCD specific: Begin: don't check spelling on spelling_file
+                   index($spelling_file, $realfile) + length($realfile) != length($spelling_file) &&
+                   # OpenOCD specific: End
                    ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) {
                        while ($rawline =~ /(?:^|[^\w\-'`])($misspellings)(?:[^\w\-'`]|$)/gi) {
                                my $typo = $1;
@@ -3482,7 +3570,7 @@ sub process {
                        my $msg_level = \&ERROR;
                        $msg_level = \&CHK if ($file);
                        &{$msg_level}("FSF_MAILING_ADDRESS",
-                                     "Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.\n" . $herevet)
+                                     "Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. OpenOCD already includes a copy of the GPL.\n" . $herevet)
                }
 
 # check for Kconfig help text having a real description
@@ -3635,6 +3723,10 @@ sub process {
                                        $comment = '#';
                                } elsif ($realfile =~ /\.rst$/) {
                                        $comment = '..';
+                               # OpenOCD specific: Begin
+                               } elsif ($realfile =~ /\.(am|cfg|tcl)$/) {
+                                       $comment = '#';
+                               # OpenOCD specific: End
                                }
 
 # check SPDX comment style for .[chsS] files
@@ -4198,7 +4290,9 @@ sub process {
 
                        my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0);
 
-                       if ($line =~ /^\+\t{6,}/) {
+                       # OpenOCD specific: Begin: replace s/6/10/
+                       if ($line =~ /^\+\t{10,}/) {
+                       # OpenOCD specific: End
                                WARN("DEEP_INDENTATION",
                                     "Too many leading tabs - consider code refactoring\n" . $herecurr);
                        }
@@ -5723,6 +5817,7 @@ sub process {
                        my $var = $1;
 
 #CamelCase
+                       if (!$OpenOCD) {
                        if ($var !~ /^$Constant$/ &&
                            $var =~ /[A-Z][a-z]|[a-z][A-Z]/ &&
 #Ignore some autogenerated defines and enum values
@@ -5734,9 +5829,24 @@ sub process {
                            $var !~ /^(?:[a-z0-9_]*|[A-Z0-9_]*)?_?[a-z][A-Z](?:_[a-z0-9_]+|_[A-Z0-9_]+)?$/ &&
 #Ignore some three character SI units explicitly, like MiB and KHz
                            $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
+                       }
+                       } # !$OpenOCD
+                       # OpenOCD Specific: Begin: remove Linux exceptions, extend to camel[0-9_]*CASE
+                       if ($var !~ /^$Constant$/ &&
+                           $var =~ /[A-Z][0-9_]*[a-z]|[a-z][0-9_]*[A-Z]/) {
+                       # OpenOCD Specific: End
                                while ($var =~ m{\b($Ident)}g) {
                                        my $word = $1;
+                                       if (!$OpenOCD) {
                                        next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);
+                                       } # !$OpenOCD
+                                       # OpenOCD Specific: Begin: extend to camel[0-9_]*CASE
+                                       next if ($word !~ /[A-Z][0-9_]*[a-z]|[a-z][0-9_]*[A-Z]/);
+                                       # OpenOCD Specific: End
+                                       if (!$OpenOCD) {
+                                       # This will not work for OpenOCD jenkins because it runs
+                                       # checkpatch from a tree already patched. Any new camelcase
+                                       # in include file will be ignored as it was pre-existing.
                                        if ($check) {
                                                seed_camelcase_includes();
                                                if (!$file && !$camelcase_file_seeded) {
@@ -5744,6 +5854,7 @@ sub process {
                                                        $camelcase_file_seeded = 1;
                                                }
                                        }
+                                       } # !$OpenOCD
                                        if (!defined $camelcase{$word}) {
                                                $camelcase{$word} = 1;
                                                CHK("CAMELCASE",

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)