public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] checkpatch.pl: Add SPDX license tag check
@ 2017-12-20 23:46 Rob Herring
  2017-12-21  6:28 ` Joe Perches
  2017-12-21  7:15 ` Philippe Ombredanne
  0 siblings, 2 replies; 5+ messages in thread
From: Rob Herring @ 2017-12-20 23:46 UTC (permalink / raw)
  To: linux-kernel, Thomas Gleixner, Joe Perches
  Cc: Andy Whitcroft, Greg Kroah-Hartman, Philippe Ombredanne

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.

Cc: Andy Whitcroft <apw@canonical.com>
Cc: Joe Perches <joe@perches.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Rob Herring <robh@kernel.org>
---
Thomas, if you are inclined and Joe is happy with this, can you add this 
on top of your series adding license-rules.rst.

v4:
- Reference license-rules.rst
- Add comment style checks based on file types
- Check .rst files

v3:
- Since we specify that the tag goes on the 1st or 2nd line, the logic
  can be greatly simplified compared to v2 because we can just use the
  line number. And now the check is improved too.

 scripts/checkpatch.pl | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 31031f10fe56..0324f845011d 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2866,6 +2866,31 @@ sub process {
 			}
 		}
 
+# check for using SPDX license tag at beginning of files
+		if ($rawline =~ /^\+/ && !($realline == 1 && $rawline =~ /^[\s\+]#!/)) {
+			my $ln = 1;
+			my $comment = "";
+
+			if ($realfile =~ /\.(h|s|S)$/) {
+				$comment = '/\*';
+			} elsif ($realfile =~ /\.(c|dts|dtsi)$/) {
+				$comment = '//';
+			} elsif ($realfile =~ /\.(sh|pl|py)$/) {
+				if ($prevrawline =~ /^[\s\+]#!/) {
+					$ln = 2;
+				}
+				$comment = '#';
+			} elsif ($realfile =~ /\.rst$/) {
+				$comment = '..';
+			}
+
+			if ($comment !~ /^$/ &&
+			    ($realline == $ln xor $rawline =~ m@^\+$comment SPDX-License-Identifier: @)) {
+				WARN("SPDX_LICENSE_TAG",
+				     "Missing or malformed SPDX-License-Identifier tag in 1st (or 2nd for scripts) line\n" . $herecurr);
+			}
+		}
+
 # check we are in a valid source file if not then ignore this hunk
 		next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/);
 
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-12-21 17:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-20 23:46 [PATCH v4] checkpatch.pl: Add SPDX license tag check Rob Herring
2017-12-21  6:28 ` Joe Perches
2017-12-21 17:04   ` Rob Herring
2017-12-21 17:22     ` Joe Perches
2017-12-21  7:15 ` Philippe Ombredanne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox