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
2257 2257
2258 my $camelcase_file_seeded = 0;2258 my $camelcase_file_seeded = 0;
2259 2259
2260 my $checklicenseline = 1;
2261
2260 sanitise_line_reset();2262 sanitise_line_reset();
2261 my $line;2263 my $line;
2262 foreach my $rawline (@rawlines) {2264 foreach my $rawline (@rawlines) {
@@ -2448,6 +2450,7 @@ sub process { · 185 unmodified lines
2448 } else {2450 } else {
2449 $check = $check_orig;2451 $check = $check_orig;
2450 }2452 }
2453 $checklicenseline = 1;
2451 next;2454 next;
2452 }2455 }
2453 2456
@@ -2911,6 +2914,30 @@ sub process { · 457 unmodified lines
2911 }2914 }
2912 }2915 }
2913 2916
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
2914# check we are in a valid source file if not then ignore this hunk2941# check we are in a valid source file if not then ignore this hunk
2915 next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/);2942 next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/);
2916 2943