Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751346AbdLUHQ2 (ORCPT ); Thu, 21 Dec 2017 02:16:28 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33371 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751160AbdLUHQZ (ORCPT ); Thu, 21 Dec 2017 02:16:25 -0500 X-Google-Smtp-Source: ACJfBouzvEFcEnmiCmEvkuJs4GeAI9Xop9rJPGjKhMXf7HOKaIXFjtq4SVmT34Tx4ctRJT3U/klAuC56072oGhlniLQ= MIME-Version: 1.0 In-Reply-To: <20171220234625.16521-1-robh@kernel.org> References: <20171220234625.16521-1-robh@kernel.org> From: Philippe Ombredanne Date: Thu, 21 Dec 2017 08:15:43 +0100 Message-ID: Subject: Re: [PATCH v4] checkpatch.pl: Add SPDX license tag check To: Rob Herring Cc: LKML , Thomas Gleixner , Joe Perches , Andy Whitcroft , Greg Kroah-Hartman Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3450 Lines: 88 Rob, On Thu, Dec 21, 2017 at 12:46 AM, 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 > index 31031f10fe56..0324f845011d 100755 > --- 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\+]#!/)) { > + my $ln = 1; > + my $comment = ""; > + > + if ($realfile =~ /\.(h|s|S)$/) { > + $comment = '/\*'; > + } elsif ($realfile =~ /\.(c|dts|dtsi)$/) { > + $comment = '//'; > + } elsif ($realfile =~ /\.(sh|pl|py)$/) { > + if ($prevrawline =~ /^[\s\+]#!/) { > + $ln = 2; > + } > + $comment = '#'; > + } elsif ($realfile =~ /\.rst$/) { > + $comment = '..'; > + } > + > + if ($comment !~ /^$/ && > + ($realline == $ln xor $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); > + } > + } > + > # 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 > My Perl is terribly rusty. But heck this is checkpatch.pl, not checkpatch.py ;) This looks good to me though. FWIW I maintain a comprehensive license expression parser and boolean minimizer that could be a nice addition but is likely overkill even for deeper checks. Instead, in the future what we could add to checkpatch.pl could be some simple table lookup to ensure that the actual expression is a known one since we have a finite number of licenses in the kernel. Reviewed-by: Philippe Ombredanne [1] https://github.com/nexB/license-expression/ -- Cordially Philippe Ombredanne