diff options
| author | Rob Herring <robh@kernel.org> | 2018-04-10 19:33:13 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-04-11 13:28:35 -0400 |
| commit | 9f3a89926d6dfc30a4fd1bbcb92cc7b218d3786d (patch) | |
| tree | 8f307e687f09a5729e80bcc15a2ce5b46bc4cd71 /scripts | |
| parent | 85e12066ea09bbee5c99ff2dbde9934291533b0d (diff) | |
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.org
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Philippe 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: 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 | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index b464a4c3f863..0f022b56f117 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -2257,6 +2257,8 @@ sub process { | |||
| 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 { | |||
| 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 { | |||
| 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 hunk | 2941 | # 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 | ||
