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

SPDX license tags are a thing now in the kernel[1]. It has also been
decided to make them the first line in files. As Linus put it:

"The real reason _I_ personally would like to see at least all the new
SPDX lines to go at the very top of the file is that every time when
we have some kind of ambiguity about placement, we end up with
multiple cases, and then people don't notice when merging, and you end
up having two - or you just end up having unnecessary merge conflicts
because two different people picked two different choices)."

Add a warning if SPDX-License-Identifier tag is not present in the first
line (or 2nd for #! scripts) of files.

[1] https://lwn.net/Articles/738235/

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>
---
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.

I tested this on a variety of files and Greg's patches adding the tags. 
I did find one error in Greg's patches. The tags were placed on the 
2nd line even for scripts without a "#!" line. Want to know which ones? 
Well, you'll have to run checkpatch. :)

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

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 8b80bac055e4..50633d44b49b 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2865,6 +2865,20 @@ sub process {
 			}
 		}
 
+# check for using SPDX license tag at beginning of files
+		if ($realfile !~ /Documentation/ && $rawline =~ /^\+/ &&
+		    !($realline == 1 && $rawline =~ /^[\s\+]#!/)) {
+			my $ln = 1;
+
+			if ($realline == 2 && $prevrawline =~ /^[\s\+]#!/) {
+				$ln++;
+			}
+			if ($realline == $ln xor $rawline =~ m@^\+(#|//|/\*) 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] 4+ messages in thread

* Re: [PATCH v3] checkpatch.pl: Add SPDX license tag check
  2017-11-10 20:19 [PATCH v3] checkpatch.pl: Add SPDX license tag check Rob Herring
@ 2017-11-11 13:53 ` Joe Perches
  2017-11-11 14:22   ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2017-11-11 13:53 UTC (permalink / raw)
  To: Rob Herring, linux-kernel; +Cc: Andy Whitcroft, Greg Kroah-Hartman

On Fri, 2017-11-10 at 14:19 -0600, Rob Herring wrote:
> SPDX license tags are a thing now in the kernel[1]. It has also been
> decided to make them the first line in files. As Linus put it:

Yes, SPDX tags are used in about a quarter of the files
in the kernel.

Again, where is this shown to be desired that this goes
into _every_ file?

If that is so, it needs to be specified _first_ somewhere
in the Documentation/ tree.

Probably in the process - 1.5 Licensing section.

> "The real reason _I_ personally would like to see at least all the new
> SPDX lines to go at the very top of the file is that every time when
> we have some kind of ambiguity about placement, we end up with
> multiple cases, and then people don't notice when merging, and you end
> up having two - or you just end up having unnecessary merge conflicts
> because two different people picked two different choices)."
> 
> Add a warning if SPDX-License-Identifier tag is not present in the first
> line (or 2nd for #! scripts) of files.
> 
> [1] https://lwn.net/Articles/738235/

subscription only link

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

* Re: [PATCH v3] checkpatch.pl: Add SPDX license tag check
  2017-11-11 13:53 ` Joe Perches
@ 2017-11-11 14:22   ` Greg Kroah-Hartman
  2017-11-11 14:26     ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2017-11-11 14:22 UTC (permalink / raw)
  To: Joe Perches; +Cc: Rob Herring, linux-kernel, Andy Whitcroft

On Sat, Nov 11, 2017 at 05:53:12AM -0800, Joe Perches wrote:
> On Fri, 2017-11-10 at 14:19 -0600, Rob Herring wrote:
> > SPDX license tags are a thing now in the kernel[1]. It has also been
> > decided to make them the first line in files. As Linus put it:
> 
> Yes, SPDX tags are used in about a quarter of the files
> in the kernel.
> 
> Again, where is this shown to be desired that this goes
> into _every_ file?

The documentation that states this should be published this weekend, or
on Monday, depending on people's travel schedules, please give it a
chance...

thanks,

greg k-h

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

* Re: [PATCH v3] checkpatch.pl: Add SPDX license tag check
  2017-11-11 14:22   ` Greg Kroah-Hartman
@ 2017-11-11 14:26     ` Joe Perches
  0 siblings, 0 replies; 4+ messages in thread
From: Joe Perches @ 2017-11-11 14:26 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Rob Herring, linux-kernel, Andy Whitcroft

On Sat, 2017-11-11 at 15:22 +0100, Greg Kroah-Hartman wrote:
> On Sat, Nov 11, 2017 at 05:53:12AM -0800, Joe Perches wrote:
> > On Fri, 2017-11-10 at 14:19 -0600, Rob Herring wrote:
> > > SPDX license tags are a thing now in the kernel[1]. It has also been
> > > decided to make them the first line in files. As Linus put it:
> > 
> > Yes, SPDX tags are used in about a quarter of the files
> > in the kernel.
> > 
> > Again, where is this shown to be desired that this goes
> > into _every_ file?
> 
> The documentation that states this should be published this weekend, or
> on Monday, depending on people's travel schedules, please give it a
> chance...
> 
> thanks,

checkpatch should not take the lead in setting licensing policy.
So unless and until the documentation patch is accepted: nak.

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

end of thread, other threads:[~2017-11-11 14:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-10 20:19 [PATCH v3] checkpatch.pl: Add SPDX license tag check Rob Herring
2017-11-11 13:53 ` Joe Perches
2017-11-11 14:22   ` Greg Kroah-Hartman
2017-11-11 14:26     ` Joe Perches

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).