Commit 9f3a8992 authored by Rob Herring's avatar Rob Herring Committed by Linus Torvalds

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.

Link: http://lkml.kernel.org/r/20180202154026.15298-1-robh@kernel.orgSigned-off-by: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: default avatarPhilippe Ombredanne <pombredanne@nexb.com>
Cc: Andy Whitcroft <apw@canonical.com>
Cc: Joe Perches <joe@perches.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Igor Stoppa <igor.stoppa@huawei.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 85e12066
...@@ -2257,6 +2257,8 @@ sub process { ...@@ -2257,6 +2257,8 @@ sub process {
my $camelcase_file_seeded = 0; my $camelcase_file_seeded = 0;
my $checklicenseline = 1;
sanitise_line_reset(); sanitise_line_reset();
my $line; my $line;
foreach my $rawline (@rawlines) { foreach my $rawline (@rawlines) {
...@@ -2448,6 +2450,7 @@ sub process { ...@@ -2448,6 +2450,7 @@ sub process {
} else { } else {
$check = $check_orig; $check = $check_orig;
} }
$checklicenseline = 1;
next; next;
} }
...@@ -2911,6 +2914,30 @@ sub process { ...@@ -2911,6 +2914,30 @@ sub process {
} }
} }
# check for using SPDX license tag at beginning of files
if ($realline == $checklicenseline) {
if ($rawline =~ /^[ \+]\s*\#\!\s*\//) {
$checklicenseline = 2;
} elsif ($rawline =~ /^\+/) {
my $comment = "";
if ($realfile =~ /\.(h|s|S)$/) {
$comment = '/*';
} elsif ($realfile =~ /\.(c|dts|dtsi)$/) {
$comment = '//';
} elsif (($checklicenseline == 2) || $realfile =~ /\.(sh|pl|py|awk|tc)$/) {
$comment = '#';
} elsif ($realfile =~ /\.rst$/) {
$comment = '..';
}
if ($comment !~ /^$/ &&
$rawline !~ /^\+\Q$comment\E SPDX-License-Identifier: /) {
WARN("SPDX_LICENSE_TAG",
"Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
}
}
}
# check we are in a valid source file if not then ignore this hunk # check we are in a valid source file if not then ignore this hunk
next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/); next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment