[PATCH v4 9/9] scripts/checkpatch: reject license boilerplate on new files

Daniel P. Berrangé posted 9 patches 6 months ago
There is a newer version of this series
[PATCH v4 9/9] scripts/checkpatch: reject license boilerplate on new files
Posted by Daniel P. Berrangé 6 months ago
The previous commit mandates use of SPDX-License-Identifier on common
source files, and encourages it on all other files.

Some contributors are none the less still also including the license
boilerplate text. This is redundant and will potentially cause
trouble if inconsistent with the SPDX declaration.

Match common boilerplate text blurbs and report them as invalid,
for newly added files.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 scripts/checkpatch.pl | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index dc2c3e6aa1..691c267a8c 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -365,6 +365,17 @@ our @typeList = (
 	qr{guintptr},
 );
 
+# Match text found in common license boilerplate comments:
+# for new files the SPDX-License-Identifier line is sufficient.
+our $LICENSE_BOILERPLATE = qr{
+    licensed under the terms of the GNU GPL|
+    under the terms of the GNU General Public License|
+    under the terms of the GNU Lesser General Public|
+    Permission is hereby granted, free of charge|
+    GNU GPL, version 2 or later|
+    See the COPYING file
+}x;
+
 # Load common spelling mistakes and build regular expression list.
 my $misspellings;
 my %spelling_fix;
@@ -1497,6 +1508,13 @@ sub process_end_of_file {
 			     "' need 'SPDX-License-Identifier'?");
 		}
 	}
+	if ($fileinfo->{action} eq "new" &&
+	    !exists $fileinfo->{facts}->{sawboilerplate}) {
+		ERROR("New file '" . $fileinfo->{filenew} . "' must " .
+		      "not have license boilerplate header text, only " .
+		      "the SPDX-License-Identifier, unless this file was " .
+		      "copied from existing code already having such text.");
+	}
 }
 
 sub process {
@@ -1799,6 +1817,10 @@ sub process {
 			&checkspdx($realfile, $1);
 		}
 
+		if ($rawline =~ /$LICENSE_BOILERPLATE/) {
+			$fileinfo->{facts}->{sawboilerplate} = 1;
+		}
+
 		if ($rawline =~ m,(SPDX-[a-zA-Z0-9-_]+):,) {
 			my $tag = $1;
 			my @permitted = qw(
-- 
2.49.0


Re: [PATCH v4 9/9] scripts/checkpatch: reject license boilerplate on new files
Posted by Cédric Le Goater 6 months ago
On 5/19/25 18:37, Daniel P. Berrangé wrote:
> The previous commit mandates use of SPDX-License-Identifier on common
> source files, and encourages it on all other files.
> 
> Some contributors are none the less still also including the license
> boilerplate text. This is redundant and will potentially cause
> trouble if inconsistent with the SPDX declaration.
> 
> Match common boilerplate text blurbs and report them as invalid,
> for newly added files.
> 
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   scripts/checkpatch.pl | 22 ++++++++++++++++++++++
>   1 file changed, 22 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index dc2c3e6aa1..691c267a8c 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -365,6 +365,17 @@ our @typeList = (
>   	qr{guintptr},
>   );
>   
> +# Match text found in common license boilerplate comments:
> +# for new files the SPDX-License-Identifier line is sufficient.
> +our $LICENSE_BOILERPLATE = qr{
> +    licensed under the terms of the GNU GPL|
> +    under the terms of the GNU General Public License|
> +    under the terms of the GNU Lesser General Public|
> +    Permission is hereby granted, free of charge|
> +    GNU GPL, version 2 or later|
> +    See the COPYING file
> +}x;
> +
>   # Load common spelling mistakes and build regular expression list.
>   my $misspellings;
>   my %spelling_fix;
> @@ -1497,6 +1508,13 @@ sub process_end_of_file {
>   			     "' need 'SPDX-License-Identifier'?");
>   		}
>   	}
> +	if ($fileinfo->{action} eq "new" &&
> +	    !exists $fileinfo->{facts}->{sawboilerplate}) {

oops

C.


> +		ERROR("New file '" . $fileinfo->{filenew} . "' must " .
> +		      "not have license boilerplate header text, only " .
> +		      "the SPDX-License-Identifier, unless this file was " .
> +		      "copied from existing code already having such text.");
> +	}
>   }
>   
>   sub process {
> @@ -1799,6 +1817,10 @@ sub process {
>   			&checkspdx($realfile, $1);
>   		}
>   
> +		if ($rawline =~ /$LICENSE_BOILERPLATE/) {
> +			$fileinfo->{facts}->{sawboilerplate} = 1;
> +		}
> +
>   		if ($rawline =~ m,(SPDX-[a-zA-Z0-9-_]+):,) {
>   			my $tag = $1;
>   			my @permitted = qw(


Re: [PATCH v4 9/9] scripts/checkpatch: reject license boilerplate on new files
Posted by Peter Maydell 6 months ago
On Mon, 19 May 2025 at 17:37, Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> The previous commit mandates use of SPDX-License-Identifier on common
> source files, and encourages it on all other files.
>
> Some contributors are none the less still also including the license
> boilerplate text. This is redundant and will potentially cause
> trouble if inconsistent with the SPDX declaration.
>
> Match common boilerplate text blurbs and report them as invalid,
> for newly added files.
>
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  scripts/checkpatch.pl | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index dc2c3e6aa1..691c267a8c 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -365,6 +365,17 @@ our @typeList = (
>         qr{guintptr},
>  );
>
> +# Match text found in common license boilerplate comments:
> +# for new files the SPDX-License-Identifier line is sufficient.
> +our $LICENSE_BOILERPLATE = qr{
> +    licensed under the terms of the GNU GPL|
> +    under the terms of the GNU General Public License|
> +    under the terms of the GNU Lesser General Public|
> +    Permission is hereby granted, free of charge|
> +    GNU GPL, version 2 or later|
> +    See the COPYING file
> +}x;
> +
>  # Load common spelling mistakes and build regular expression list.
>  my $misspellings;
>  my %spelling_fix;
> @@ -1497,6 +1508,13 @@ sub process_end_of_file {
>                              "' need 'SPDX-License-Identifier'?");
>                 }
>         }
> +       if ($fileinfo->{action} eq "new" &&
> +           !exists $fileinfo->{facts}->{sawboilerplate}) {

Looks like you still forgot to remove the "!" ?

> +               ERROR("New file '" . $fileinfo->{filenew} . "' must " .
> +                     "not have license boilerplate header text, only " .
> +                     "the SPDX-License-Identifier, unless this file was " .
> +                     "copied from existing code already having such text.");
> +       }
>  }

thanks
-- PMM
Re: [PATCH v4 9/9] scripts/checkpatch: reject license boilerplate on new files
Posted by Daniel P. Berrangé 6 months ago
On Mon, May 19, 2025 at 05:44:51PM +0100, Peter Maydell wrote:
> On Mon, 19 May 2025 at 17:37, Daniel P. Berrangé <berrange@redhat.com> wrote:
> >
> > The previous commit mandates use of SPDX-License-Identifier on common
> > source files, and encourages it on all other files.
> >
> > Some contributors are none the less still also including the license
> > boilerplate text. This is redundant and will potentially cause
> > trouble if inconsistent with the SPDX declaration.
> >
> > Match common boilerplate text blurbs and report them as invalid,
> > for newly added files.
> >
> > Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >  scripts/checkpatch.pl | 22 ++++++++++++++++++++++
> >  1 file changed, 22 insertions(+)
> >
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > index dc2c3e6aa1..691c267a8c 100755
> > --- a/scripts/checkpatch.pl
> > +++ b/scripts/checkpatch.pl
> > @@ -365,6 +365,17 @@ our @typeList = (
> >         qr{guintptr},
> >  );
> >
> > +# Match text found in common license boilerplate comments:
> > +# for new files the SPDX-License-Identifier line is sufficient.
> > +our $LICENSE_BOILERPLATE = qr{
> > +    licensed under the terms of the GNU GPL|
> > +    under the terms of the GNU General Public License|
> > +    under the terms of the GNU Lesser General Public|
> > +    Permission is hereby granted, free of charge|
> > +    GNU GPL, version 2 or later|
> > +    See the COPYING file
> > +}x;
> > +
> >  # Load common spelling mistakes and build regular expression list.
> >  my $misspellings;
> >  my %spelling_fix;
> > @@ -1497,6 +1508,13 @@ sub process_end_of_file {
> >                              "' need 'SPDX-License-Identifier'?");
> >                 }
> >         }
> > +       if ($fileinfo->{action} eq "new" &&
> > +           !exists $fileinfo->{facts}->{sawboilerplate}) {
> 
> Looks like you still forgot to remove the "!" ?

Sigh, yes. Also the $LICENSE_BOILERPLATE var content is simply not matching
at all either, so the two problems made it look like it was working


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|