From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1B3EC43331 for ; Fri, 6 Sep 2019 11:37:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7953020842 for ; Fri, 6 Sep 2019 11:37:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567769841; bh=9PTFmo9AJ6WXLhqUUB28yZLsaJ9n0G/IWCUozokCMlA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-ID:From; b=2onPWQRXHybnF2VICkfmlSt834t+AATM5DxcgQEeJwVhk/y5CAdEo1yCgKsispWwU BbHPSzRveCJT6QniRGWCVM42/gGDCXg9rIBGlNGjMoAB3L/SzqJF6zTQkQPqYk9xZ7 c7beSpN04BWpw4XtHe7IjOaMmog46vQaun2zf6Os= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390123AbfIFLhU (ORCPT ); Fri, 6 Sep 2019 07:37:20 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:35432 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389971AbfIFLhU (ORCPT ); Fri, 6 Sep 2019 07:37:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To: From:Date:Sender:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=BaJkMB0z7Fy2B1fYpEwhEuwf2lT0IavJbz0NGtBNe7A=; b=Yi4+2SyNocYccqH5MaR05tEwk UhWa7a8ZwoiMYGKa7iNi6YtrkC7IQm2mYtRRmN+DxRdmBy2ecV4WVuB9yc7r/UNYLHtYnAzP5yG6+ pvotiKG+LSMrLD04qx5Cy0drkF7LLJlwoa9r4PdTVL2j+lAwCiBPK+PN+OQY/ZlPPUiw0mi8Xu/3C bVTyfZ7DX+LAr5nqg4zh+6PiyTCsY8SEsZT3rTOsCotDT0jv3L6HUGtsQdkpAjJJgsUTjtNXj5t9g cGIyZYV+/6BFXcKN9ry/UVb0S8kLANNXsgUaT0E+C9DCd6DTBbuQZSE6Dq9x9BBlbE8yxyyF7mTae lvrOZvzBQ==; Received: from [177.159.253.249] (helo=coco.lan) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1i6CYJ-0005fo-2Y; Fri, 06 Sep 2019 11:37:19 +0000 Date: Fri, 6 Sep 2019 08:37:14 -0300 From: Mauro Carvalho Chehab To: Joe Perches Cc: Greg Kroah-Hartman , Linux Media Mailing List , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, Jonathan Corbet , Jessica Yu , Federico Vaga , Thomas Gleixner , linux-doc@vger.kernel.org Subject: Re: [PATCH] docs: license-rules.txt: cover SPDX headers on Python scripts Message-ID: <20190906083714.0cf7eb20@coco.lan> In-Reply-To: <20190906083457.7e7934ec@coco.lan> References: <20190905055614.7958918b@coco.lan> <88e638eb959095ab6657d295f9f8c27169569bf2.1567675272.git.mchehab+samsung@kernel.org> <20190905092703.GA30899@kroah.com> <20190905090701.37dcf75e@coco.lan> <20190906083457.7e7934ec@coco.lan> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Fri, 6 Sep 2019 08:34:57 -0300 Mauro Carvalho Chehab escreveu: > Em Thu, 05 Sep 2019 10:45:36 -0700 > Joe Perches escreveu: > > > On Thu, 2019-09-05 at 09:07 -0300, Mauro Carvalho Chehab wrote: > > > There are currently 227 files that don't complain with the "up to line 3" > > > rule, including COPYING (with should probably be excluded from the check). > > > > > > Patches are at: > > > > > > https://git.linuxtv.org/mchehab/experimental.git/log/?h=spdx_pedantic > > > > > > Btw, most violations are due to: > > > > > > /* > > > * SPDX... > > > > Hey Mauro. > > > > Here's a little script to move all of the improperly located > > SPDX-License-Identifier lines in [.ch] files. > > > > Using this command line: > > > > $ git grep -n 'SPDX-License-Identifier: ' -- '*.[ch]' | \ > > grep -v ':1:' | perl move_spdx.pl > > > > and > > > > $ cat move_spdx.pl > > while (<>) { > > /^([^:]+):([^:]+):(.*)/; > > my ($file, $line, $spdx) = ($1, $2, $3); > > $spdx =~ s/^\s*\/?\*\s*//; > > $spdx =~ s/\s*\*\/\s*$//; > > if ($file =~ /\.h$/) { > > $spdx = "/* $spdx */"; > > } else { > > $spdx = "// $spdx"; > > } > > open(FH, '<', $file) or die $!; > > my @lines = ; > > close FH; > > open(FH, '>', $file) or die $!; > > print FH "$spdx\n"; > > my $count = 0; > > foreach (@lines) { > > $count++; > > next if ($count == $line); > > next if ($count == $line - 1 && $_ =~ /^\s*\*\s*$/); > > next if ($count == $line + 1 && $_ =~ /^\s*\*\s*$/); > > print FH "$_"; > > } > > close FH; > > } > > > > which gives this diff for today's -next > > Nice script! > > I did some changes on it In time: I'm enclosing the modified script. just run it directly with: perl ./move_spdx.pl and it will move the SPDX headers where pertinent. Thanks, Mauro --- #!/usr/bin/perl @file_arr = qx(git grep -n 'SPDX-License-Identifier: ' | grep -v ':1:'); foreach (@file_arr) { /^([^:]+):([^:]+):(.*)/; my ($file, $line, $spdx) = ($1, $2, $3); next if ($file =~ m,(COPYING|LICENSES/|sha1-armv4-large.S),); next if ($line > 10); $spdx =~ s/^\s*\/?\*\s*//; $spdx =~ s/\s*\*\/\s*$//; $spdx = $1 if m/(SPDX-License-Identifier:.*)/; $is_script = 0; if ($file =~ /\.(h|dts|dtsi|S)$/) { $spdx = "/* $spdx */"; } elsif ($file =~ /\.(c)$/) { $spdx = "// $spdx"; } elsif ($file =~ /\.(rst)$/) { $spdx = ".. $spdx"; } elsif ($file =~ /\.(py|pl|sh)$/ || !$file =~ /\./) { $is_script = 1; $spdx = "# $spdx"; } else { next; } open(FH, '<', $file) or die $!; my @lines = ; close FH; open(FH, '>', $file) or die $!; my $count = 0; my $print_spdx = 1; foreach (@lines) { $count++; if ($print_spdx) { if ($count == 1 && (/:orphan:/ || /^#\!/)) { print FH "$_"; next; } if ($count <= 2 && /^[ \t\f]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)/) { print FH "$_"; next; } print FH "$spdx\n"; $print_spdx = 0; } next if ($count == $line); next if ($count == $line - 1 && $_ =~ /^\s*\*\s*$/); next if ($count == $line + 1 && $_ =~ /^\s*\*\s*$/); next if ($count == $line - 1 && $_ =~ /^$/); print FH "$_"; } close FH; }