linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] checkpatch.pl: Add SPDX license tag check
@ 2017-11-09  1:10 Rob Herring
  2017-11-09  2:10 ` Joe Perches
  0 siblings, 1 reply; 12+ messages in thread
From: Rob Herring @ 2017-11-09  1:10 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andy Whitcroft, Joe Perches, Greg Kroah-Hartman

Add a check warning if SPDX-License-Identifier tags are not used in
newly added files.

Cc: Andy Whitcroft <apw@canonical.com>
Cc: Joe Perches <joe@perches.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Rob Herring <robh@kernel.org>
---
I rewrote my previous version to check more than just dts files. It also 
now looks for a tag in added files rather than trying a fuzzy match on 
freeform license text.

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

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 8b80bac055e4..6665735123e5 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2185,6 +2185,8 @@ sub process {
 	my $commit_log_has_diff = 0;
 	my $reported_maintainer_file = 0;
 	my $non_utf8_charset = 0;
+	my $added_file = 0;
+	my $missing_spdx_license = 0;
 
 	my $last_blank_line = 0;
 	my $last_coalesced_string_linenr = -1;
@@ -2368,6 +2370,16 @@ sub process {
 		$here = "#$linenr: " if (!$file);
 		$here = "#$realline: " if ($file);
 
+		# determine if this is a new file
+		if ($line =~ m@^\-\-\-\s/@) {
+			if ($line =~ m@/dev/null@) {
+				$added_file = 1;
+				$missing_spdx_license++;
+			} else {
+				$added_file = 0;
+			}
+		}
+
 		my $found_file = 0;
 		# extract the filename as it passes
 		if ($line =~ /^diff --git.*?(\S+)$/) {
@@ -2865,6 +2877,14 @@ sub process {
 			}
 		}
 
+# check for using SPDX tag instead of free form license text
+		if ($added_file &&
+		    ($rawline =~ /\bSPDX-License-Identifier/ ||
+		     $realfile =~ /Documentation/)) {
+			$missing_spdx_license--;
+			$added_file = 0;
+		}
+
 # check we are in a valid source file if not then ignore this hunk
 		next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/);
 
@@ -6399,6 +6419,11 @@ sub process {
 		      "Missing Signed-off-by: line(s)\n");
 	}
 
+	if ($missing_spdx_license) {
+		WARN("SPDX_LICENSE_TAG",
+		     "Missing SPDX-License-Identifier tags in added files. Use tags instead of full license text.\n");
+	}
+
 	print report_dump();
 	if ($summary && !($clean == 1 && $quiet == 1)) {
 		print "$filename " if ($summary_file);
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [PATCH] checkpatch.pl: Add SPDX license tag check
@ 2018-02-01 21:14 Rob Herring
  2018-02-01 21:49 ` Joe Perches
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Rob Herring @ 2018-02-01 21:14 UTC (permalink / raw)
  To: linux-kernel, Andrew Morton
  Cc: Andy Whitcroft, Joe Perches, Greg Kroah-Hartman, Thomas Gleixner,
	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>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Rob Herring <robh@kernel.org>
---
I didn't get around to resending once license-rules.rst landed in -next. 
Hopefully, this can be picked up for 4.16 so folks can start using it. 
SPDX tags have already become a frequent review comment.

Rob

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

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index ba03f17ff662..cf1b5a90b20a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2225,6 +2225,8 @@ sub process {
 
 	my $camelcase_file_seeded = 0;
 
+	my $checklicenseline = 1;
+
 	sanitise_line_reset();
 	my $line;
 	foreach my $rawline (@rawlines) {
@@ -2416,6 +2418,7 @@ sub process {
 			} else {
 				$check = $check_orig;
 			}
+			$checklicenseline = 1;
 			next;
 		}
 
@@ -2866,6 +2869,30 @@ sub process {
 			}
 		}
 
+# check for using SPDX license tag at beginning of files
+		if ($realline == $checklicenseline) {
+			if ($realfile =~ /\.(?:sh|pl|py)/ && $rawline =~ /\[ \+]\s*\!\#/) {
+				$checklicenseline = 2;
+			} elsif ($rawline =~ /^\+/) {
+				my $comment = "";
+				if ($realfile =~ /\.(h|s|S)$/) {
+					$comment = '/*';
+				} elsif ($realfile =~ /\.(c|dts|dtsi)$/) {
+					$comment = '//';
+				} elsif ($realfile =~ /\.(sh|pl|py)$/) {
+					$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 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] 12+ messages in thread

end of thread, other threads:[~2018-02-08 14:23 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-09  1:10 [PATCH] checkpatch.pl: Add SPDX license tag check Rob Herring
2017-11-09  2:10 ` Joe Perches
2017-11-09  9:12   ` Greg Kroah-Hartman
2017-11-09 13:55     ` Joe Perches
2017-11-09 13:47   ` Rob Herring
2017-11-09 15:39     ` Joe Perches
2017-11-09 18:12       ` Rob Herring
2017-11-09 18:27         ` Joe Perches
2018-02-01 21:14 Rob Herring
2018-02-01 21:49 ` Joe Perches
2018-02-02  7:56 ` Greg Kroah-Hartman
2018-02-08 14:23 ` Philippe Ombredanne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).