History

checkpatch.pl: add SPDX license tag check

Add SPDX license tag check based on the rules defined in Documentation/process/license-rules.rst. To summarize, SPDX license tags should be on the 1st line (or 2nd line in scripts) using the appropriate comment style for the file type.

Rob Herring committed 8 years ago

Commit 9f3a8991 parent 85e12061 file · +27 −0Browse files

Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all

Unified · Split

scripts/checkpatch.pl+27−0
@@ -2257,6 +2257,8 @@ sub process { · 2256 unmodified lines
22572257
22582258 my $camelcase_file_seeded = 0;
22592259
2260+ my $checklicenseline = 1;
2261+
22602262 sanitise_line_reset();
22612263 my $line;
22622264 foreach my $rawline (@rawlines) {
@@ -2448,6 +2450,7 @@ sub process { · 185 unmodified lines
24482450 } else {
24492451 $check = $check_orig;
24502452 }
2453+ $checklicenseline = 1;
24512454 next;
24522455 }
24532456
@@ -2911,6 +2914,30 @@ sub process { · 457 unmodified lines
29112914 }
29122915 }
29132916
2917+# check for using SPDX license tag at beginning of files
2918+ if ($realline == $checklicenseline) {
2919+ if ($rawline =~ /^[ \+]\s*\#\!\s*\//) {
2920+ $checklicenseline = 2;
2921+ } elsif ($rawline =~ /^\+/) {
2922+ my $comment = "";
2923+ if ($realfile =~ /\.(h|s|S)$/) {
2924+ $comment = '/*';
2925+ } elsif ($realfile =~ /\.(c|dts|dtsi)$/) {
2926+ $comment = '//';
2927+ } elsif (($checklicenseline == 2) || $realfile =~ /\.(sh|pl|py|awk|tc)$/) {
2928+ $comment = '#';
2929+ } elsif ($realfile =~ /\.rst$/) {
2930+ $comment = '..';
2931+ }
2932+
2933+ if ($comment !~ /^$/ &&
2934+ $rawline !~ /^\+\Q$comment\E SPDX-License-Identifier: /) {
2935+ WARN("SPDX_LICENSE_TAG",
2936+ "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
2937+ }
2938+ }
2939+ }
2940+
29142941 # check we are in a valid source file if not then ignore this hunk
29152942 next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/);
29162943