lkml.org 
[lkml]   [2017]   [Dec]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v4] checkpatch.pl: Add SPDX license tag check
From
Date
On Wed, 2017-12-20 at 17:46 -0600, Rob Herring wrote:
> 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
[]
> @@ -2866,6 +2866,31 @@ sub process {
> }
> }
>
> +# check for using SPDX license tag at beginning of files
> + if ($rawline =~ /^\+/ && !($realline == 1 && $rawline =~ /^[\s\+]#!/)) {

This test will enter this block for every added line of the patch.

Needs to be /^[ \+]/ and not [\t\+] and probably should just be ^\+

I'd probably have something like
my $checklicenseline = 1;

at the start of sub process

and use something

if ($realline == $checklicenseline) {
if ($realfile =~ /\.(?:sh|pl|py)/ && $rawline =~ /\[ \+]\s*\!\#/) {
$checklicenseline = 2;
} elsif (etc...) {
}
}

> + } elsif ($realfile =~ /\.rst$/) {
> + $comment = '..';

\.\.

What about .txt, .json, .cocci, and .awk ?

\
 
 \ /
  Last update: 2017-12-21 07:29    [W:3.330 / U:0.004 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site