Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753631AbdLUREU (ORCPT ); Thu, 21 Dec 2017 12:04:20 -0500 Received: from mail-pl0-f43.google.com ([209.85.160.43]:46822 "EHLO mail-pl0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751838AbdLURER (ORCPT ); Thu, 21 Dec 2017 12:04:17 -0500 X-Google-Smtp-Source: ACJfBotsH66tuvwu9s9oMUz3/Kv1KTobqpkilrATnjpVzg8BjrJnpdb28l0i3x8PmFgb7Vtlz/Vklg== Date: Thu, 21 Dec 2017 11:04:14 -0600 From: Rob Herring To: Joe Perches Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , Andy Whitcroft , Greg Kroah-Hartman , Philippe Ombredanne Subject: Re: [PATCH v4] checkpatch.pl: Add SPDX license tag check Message-ID: <20171221170413.qca3vnif5f62rqsk@rob-hp-laptop> References: <20171220234625.16521-1-robh@kernel.org> <1513837728.1234.146.camel@perches.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1513837728.1234.146.camel@perches.com> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2983 Lines: 96 On Wed, Dec 20, 2017 at 10:28:48PM -0800, Joe Perches wrote: > 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 > > Cc: Joe Perches > > Cc: Greg Kroah-Hartman > > Cc: Thomas Gleixner > > Cc: Philippe Ombredanne > > Signed-off-by: Rob Herring > > --- > > 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...) { > } > } Okay, here's what I've ended up with: 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 !~ 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); } } } > > > + } elsif ($realfile =~ /\.rst$/) { > > + $comment = '..'; > > \.\. > > What about .txt, .json, .cocci, and .awk ? What about them? They aren't documented in license-rules.rst and I'm just implementing what's documented as you said I should on v3. Rob