linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
* [Linux-kernel-mentees] [PATCH] checkpatch: Fix SPDX license check for scripts
@ 2020-07-13  9:57 Mrinal Pandey
  2020-07-13 19:46 ` Lukas Bulwahn
  0 siblings, 1 reply; 14+ messages in thread
From: Mrinal Pandey @ 2020-07-13  9:57 UTC (permalink / raw)
  To: lukas.bulwahn; +Cc: Linux-kernel-mentees


[-- Attachment #1.1: Type: text/plain, Size: 1776 bytes --]

In all the scripts, the SPDX license should be on the second line,
the first line being the "sh-bang", but checkpatch issues a warning
"Misplaced SPDX-License-Identifier tag - use line 1 instead" for the
scripts that have SPDX license in the second line.

However, this warning is not issued when checkpatch is run on a file using
`-f` option. The case for files has been handled gracefully by changing
`$checklicenseline` to `2` but a corresponding check when running checkpatch
on a commit hash is missing.

I noticed this false positive while running checkpatch on the set of
commits from v5.7 to v5.8-rc1 of the kernel on the commits which modified
a script file.

This check is missing in checkpatch since commit a8da38a9cf0e
("checkpatch: add test for SPDX-License-Identifier on wrong line #")
when the corresponding rule was first commited.

Fix this by setting `$checklicenseline` to `2` when the diff content that
is being checked originates from a script, thus, informing checkpatch that
the SPDX license should be on the second line.

Signed-off-by: Mrinal Pandey <mrinalmni@gmail.com>
---
 scripts/checkpatch.pl | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4c820607540b..bbffd0c4449d 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3218,6 +3218,9 @@ sub process {
 		next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/);
 
 # check for using SPDX-License-Identifier on the wrong line number
+		if ($realfile =~ /^scripts/) {
+                    $checklicenseline = 2;
+	        }
 		if ($realline != $checklicenseline &&
 		    $rawline =~ /\bSPDX-License-Identifier:/ &&
 		    substr($line, @-, @+ - @-) eq "$;" x (@+ - @-)) {
-- 
2.25.1


[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply related	[flat|nested] 14+ messages in thread
* [Linux-kernel-mentees] [PATCH] checkpatch: Fix SPDX license check for scripts
@ 2020-07-21  5:44 Mrinal Pandey
  2020-07-22 10:20 ` Lukas Bulwahn
  0 siblings, 1 reply; 14+ messages in thread
From: Mrinal Pandey @ 2020-07-21  5:44 UTC (permalink / raw)
  To: lukas.bulwahn, skhan, Linux-kernel-mentees


[-- Attachment #1.1: Type: text/plain, Size: 2122 bytes --]

In all the scripts, the SPDX license should be on the second line,
the first line being the shebang, but checkpatch issues a warning
"Misplaced SPDX-License-Identifier tag - use line 1 instead" for the
scripts that have SPDX license in the second line.

However, this warning is not issued when checkpatch is run on a file.
The case for files has been handled gracefully by checking first line of
the file to be a shebang and then setting `$checklicenseline` to `2`but
this doesn't work when we don't have shebang in diff content of a patch
and `$checklicenseline` continues to be `1` in such cases. Therefore,
checkpatch expects the line `1` to contain the SPDX license when it
should have been `2` instead.

I noticed this false positive while running checkpatch on the set of
commits from v5.7 to v5.8-rc1 of the kernel on the commits which modified
a script file.

This false positive exists in checkpatch since commit a8da38a9cf0e
("checkpatch: add test for SPDX-License-Identifier on wrong line #")
when the corresponding rule was first commited.

Fix this by setting `$checklicenseline` to `2` whenever the file or diff
content we are checking comes from a script instead of checking first
line to be a shebang, thus, informing checkpatch that the SPDX license
should be expected on the second line.

Signed-off-by: Mrinal Pandey <mrinalmni@gmail.com>
---
 scripts/checkpatch.pl | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4c820607540b..bdd2f9a80891 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3166,10 +3166,11 @@ sub process {
 		}
 
 # check for using SPDX license tag at beginning of files
+		if ($realfile =~ /.*\.\(py\|sh\|pl\|awk\|tc\|yaml\)/) {
+			$checklicenseline = 2;
+		}
 		if ($realline == $checklicenseline) {
-			if ($rawline =~ /^[ \+]\s*\#\!\s*\//) {
-				$checklicenseline = 2;
-			} elsif ($rawline =~ /^\+/) {
+			if ($rawline =~ /^\+/) {
 				my $comment = "";
 				if ($realfile =~ /\.(h|s|S)$/) {
 					$comment = '/*';
-- 
2.25.1


[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

end of thread, other threads:[~2020-07-24  8:09 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-13  9:57 [Linux-kernel-mentees] [PATCH] checkpatch: Fix SPDX license check for scripts Mrinal Pandey
2020-07-13 19:46 ` Lukas Bulwahn
2020-07-14  5:35   ` Mrinal Pandey
2020-07-14  6:03     ` Lukas Bulwahn
2020-07-16  5:15       ` Mrinal Pandey
2020-07-16  5:31         ` Lukas Bulwahn
2020-07-17  9:54           ` Mrinal Pandey
2020-07-17 11:47             ` Lukas Bulwahn
2020-07-19  6:27               ` Mrinal Pandey
2020-07-19  7:13                 ` Lukas Bulwahn
2020-07-21  5:44 Mrinal Pandey
2020-07-22 10:20 ` Lukas Bulwahn
2020-07-24  7:02   ` Mrinal Pandey
2020-07-24  8:09     ` Lukas Bulwahn

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