This is an automated email from the git hooks/post-receive script.

dod pushed a commit to branch master
in repository devscripts.

commit 8428af6556744f14ad5537e6449e14454485871c
Author: Dominique Dumont <[email protected]>
Date:   Sun May 22 15:06:38 2016 +0200

    added --deb-fmt option to use dep-5 license keywords (see #472199)
    
    This commit implements the last suggestion of #472199. The remainder
    of this bug will probably not be fixed.
---
 scripts/licensecheck.pl | 83 ++++++++++++++++++++++++++++++++++++++++++++-----
 test/test_licensecheck  |  7 +++++
 2 files changed, 83 insertions(+), 7 deletions(-)

diff --git a/scripts/licensecheck.pl b/scripts/licensecheck.pl
index c19e561..7c17ab9 100755
--- a/scripts/licensecheck.pl
+++ b/scripts/licensecheck.pl
@@ -95,6 +95,10 @@ this option is used.
 
 Also display copyright text found within the file
 
+=item B<--deb-fmt>
+
+Show license using Debian copyright format keywords (quite close to SPDX 
keywords).
+
 =item B<-e> B<--encoding>
 
 Specifies input encoding of source files. By default, input files are
@@ -273,6 +277,7 @@ my %OPT=(
     machine        => 0,
     text           => 0,
     skipped        => 0,
+    'deb-fmt'         => 0,
 );
 
 my $def_lines = 60;
@@ -326,6 +331,7 @@ GetOptions(\%OPT,
            "help|h",
            "check|c=s",
            "copyright",
+          "deb-fmt!",
           "encoding|e=s",
            "ignore|i=s",
            "lines|l=i",
@@ -641,19 +647,40 @@ sub parselicense {
     my $gplver = "";
     my $extrainfo = "";
     my $license = "";
+    my @spdx_gplver ;
+
+    # @spdx_license contains identifiers from https://spdx.org/licenses/
+    # it would be more efficient to store license info only in this
+    # array and then convert it to legacy formulation, but there are
+    # corner case (like extrainfo) that would not fit. So the old storage 
scheme
+    # is kept with the new (spdx/dep-5) scheme to keep backward compat.
+    my @spdx_license ;
+
+    my $spdx_extra;
+
+    my $gen_spdx = sub {
+       my @ret = @spdx_gplver ?  (map { "$_[0]-$_"; } @spdx_gplver) : ($_[0]) ;
+       push @ret, $spdx_extra if $spdx_extra;
+       return @ret;
+    } ;
 
     if ($licensetext =~ /version ([^ ]+)(?: of the License)?,? or(?: \(at your 
option\))? version (\d(?:[.-]\d+)*)/) {
        $gplver = " (v$1 or v$2)";
+       @spdx_gplver = ($1, $2 );
     } elsif ($licensetext =~ /version ([^, ]+?)[.,]? (?:\(?only\)?.? )?(?:of 
the GNU (Affero )?(Lesser |Library )?General Public License )?(as )?published 
by the Free Software Foundation/i or
        $licensetext =~ /GNU (?:Affero )?(?:Lesser |Library )?General Public 
License (?:as )?published by the Free Software Foundation[;,] version ([^, 
]+?)[.,]? /i) {
 
        $gplver = " (v$1)";
+       @spdx_gplver = ($1);
     } elsif ($licensetext =~ /GNU (?:Affero )?(?:Lesser |Library )?General 
Public License\s*(?:[(),GPL]+)\s*version (\d+(?:\.\d+)?)[ \.]/i) {
        $gplver = " (v$1)";
+       @spdx_gplver = ($1);
     } elsif ($licensetext =~ /either version ([^ ]+)(?: of the License)?, or 
(?:\(at your option\) )?any later version/) {
        $gplver = " (v$1 or later)";
+       @spdx_gplver = ($1.'+');
     } elsif ($licensetext =~ 
/GPL\sas\spublished\sby\sthe\sFree\sSoftware\sFoundation,\sversion\s([\d.]+)/i 
) {
        $gplver = " (v$1)";
+       @spdx_gplver = ($1);
     }
 
 
@@ -662,29 +689,35 @@ sub parselicense {
     }
 
     if ($licensetext =~ /permission (?:is (also granted|given))? to link (the 
code of )?this program with (any edition of )?(Qt|the Qt library)/i) {
-       $extrainfo = " (with Qt exception)$extrainfo"
+       $extrainfo = " (with Qt exception)$extrainfo";
+       $spdx_extra = 'with Qt exception';
     }
 
     # exclude blurb found in boost license text
     if ($licensetext =~ /(All changes made in this file will be lost|DO NOT 
((?:HAND )?EDIT|delete this file|modify)|edit the original|Generated 
(automatically|by|from|data)|generated.*file)/i
         and $licensetext !~  /unless such copies or derivative works are 
solely in the form of machine-executable object code generated by a source 
language processor/) {
        $license = "GENERATED FILE";
+       push @spdx_license, 'generated-file';
     }
 
     if ($licensetext =~ /(are made available|(is free software.? )?you can 
redistribute (it|them) and(?:\/|\s+)or modify (it|them)|is licensed) under the 
terms of (version [^ ]+ of )?the (GNU (Library |Lesser )General Public 
License|LGPL)/i) {
        $license = "LGPL$gplver$extrainfo $license";
+       push @spdx_license, $gen_spdx->('LGPL');
     }
     # For Perl modules handled by Dist::Zilla
     elsif ($licensetext =~ /this is free software,? licensed under:? (?:the 
)?(?:GNU (?:Library |Lesser )General Public License|LGPL),? version 
([\d\.]+)/i) {
        $license = "LGPL (v$1) $license";
+       push @spdx_license, "LGPL-$1";
     }
 
     if ($licensetext =~ /is free software.? you can redistribute (it|them) 
and(?:\/|\s+)or modify (it|them) under the terms of the (GNU Affero General 
Public License|AGPL)/i) {
        $license = "AGPL$gplver$extrainfo $license";
+       push @spdx_license, $gen_spdx->('AGPL');
     }
 
     if ($licensetext =~ /(is free software.? )?you (can|may) redistribute 
(it|them) and(?:\/|\s+)or modify (it|them) under the terms of (?:version [^ ]+ 
(?:\(?only\)? )?of )?the GNU General Public License/i) {
        $license = "GPL$gplver$extrainfo $license";
+       push @spdx_license, $gen_spdx->('GPL');
     }
 
     
@@ -692,52 +725,66 @@ sub parselicense {
     if ($licensetext =~ /is distributed under the terms of the GNU General 
Public License,/
        and length $gplver) {
        $license = "GPL$gplver$extrainfo $license";
+       push @spdx_license, $gen_spdx->('GPL');
     }
 
     if ($licensetext =~ /(?:is|may 
be)\s(?:(?:distributed|used).*?terms|being\s+released).*?\b(L?GPL)\b/) {
         my $v = $gplver || ' (unversioned/unknown version)';
         $license = "$1$v $license";
+       push @spdx_license, $gen_spdx->($1);
     }
 
     if ($licensetext =~ /the rights to distribute and use this software as 
governed by the terms of the Lisp Lesser General Public License|\bLLGPL\b/ ) {
         $license = "LLGPL $license";
+       push @spdx_license, 'LLGPL';
     }
 
     if ($licensetext =~ /This file is part of the .*Qt GUI Toolkit. This file 
may be distributed under the terms of the Q Public License as defined/) {
        $license = "QPL (part of Qt) $license";
     } elsif ($licensetext =~ /may (be distributed|redistribute it) under the 
terms of the Q Public License/) {
        $license = "QPL $license";
+       push @spdx_license, 'QPL';
     }
 
     if ($licensetext =~ /opensource\.org\/licenses\/mit-license\.php/) {
        $license = "MIT/X11 (BSD like) $license";
+       push @spdx_license, 'Expat';
     } elsif ($licensetext =~ /Permission is hereby granted, free of charge, to 
any person obtaining a copy of this software and(\/or)? associated 
documentation files \(the (Software|Materials)\), to deal in the 
(Software|Materials)/) {
        $license = "MIT/X11 (BSD like) $license";
+       push @spdx_license, 'Expat';
     } elsif ($licensetext =~ /Permission is hereby granted, without written 
agreement and without license or royalty fees, to use, copy, modify, and 
distribute this software and its documentation for any purpose/) {
        $license = "MIT/X11 (BSD like) $license";
+       push @spdx_license, 'Expat';
     }
 
     if ($licensetext  =~ /Permission to use, copy, modify, and(\/or)? 
distribute this software for any purpose with or without fee is hereby granted, 
provided.*copyright notice.*permission notice.*all copies/) {
        $license = "ISC $license";
+       push @spdx_license, 'ISC';
     }
 
     if ($licensetext =~ /THIS SOFTWARE IS PROVIDED .*AS IS AND ANY EXPRESS OR 
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
MERCHANTABILITY/) {
        if ($licensetext =~ /All advertising materials mentioning features or 
use of this software must display the following acknowledge?ment.*This product 
includes software developed by/i) {
            $license = "BSD (4 clause) $license";
+           push @spdx_license, 'BSD-4-Clause';
        } elsif ($licensetext =~ /(The name(?:\(s\))? .*? may not|Neither the 
(names? .*?|authors?) nor the names of( (its|their|other|any))? contributors 
may) be used to endorse or promote products derived from this software/i) {
            $license = "BSD (3 clause) $license";
+           push @spdx_license, 'BSD-3-Clause';
        } elsif ($licensetext =~ /Redistributions in binary form must reproduce 
the above copyright notice/i) {
            $license = "BSD (2 clause) $license";
+           push @spdx_license, 'BSD-2-Clause';
        } else {
            $license = "BSD $license";
+           push @spdx_license, 'BSD';
        }
     }
 
     if ($licensetext =~ /Mozilla Public License,? 
(?:(?:Version|v\.)\s+)?(\d+(?:\.\d+)?)/) {
-           $license = "MPL (v$1) $license";
+       $license = "MPL (v$1) $license";
+       push @spdx_license, "MPL-$1";
     }
     elsif ($licensetext =~ /Mozilla Public License,? \((?:Version|v\.) 
(\d+(?:\.\d+)?)\)/) {
         $license = "MPL (v$1) $license";
+       push @spdx_license, "MPL-$1";
     }
 
     # match when either:
@@ -745,99 +792,121 @@ sub parselicense {
     # - a license grant is found. i.e something like "this is free software, 
licensed under the artistic license v2.0"
    if ($licensetext =~ /(?:^\s*|(?:This is free software, licensed|Released|be 
used|use and modify this (?:module|software)) under (?:the terms of )?)[Tt]he 
Artistic License ([v\d.]*\d)/) {
        $license = "Artistic (v$1) $license";
+       push @spdx_license, "Artistic-$1";
     }
 
     if ($licensetext =~ /is free software under the Artistic [Ll]icense/) {
        $license = "Artistic $license";
+       push @spdx_license, 'Artistic';
     }
 
     if ($licensetext =~ /This program is free software; you can redistribute 
it and\/or modify it under the same terms as Perl itself/) {
        $license = "Perl $license";
+       push @spdx_license, 'Artistic', 'GPL';
     }
 
     if ($licensetext =~ /under the Apache License, Version ([^ ]+)/) {
        $license = "Apache (v$1) $license";
+       push @spdx_license, "Apache-$1";
     }
 
     if ($licensetext =~ /(THE BEER-WARE LICENSE)/i) {
        $license = "Beerware $license";
+       push @spdx_license, 'Beerware';
     }
 
     if ($licensetext =~ /distributed under the terms of the FreeType 
project/i) {
        $license = "FreeType $license"; # aka FTL see 
http://www.freetype.org/license.html
+       push @spdx_license, 'FTL';
     }
 
     if ($licensetext =~ /This source file is subject to version ([^ ]+) of the 
PHP license/) {
        $license = "PHP (v$1) $license";
-    }
-
-    if ($licensetext =~ /under the terms of the CeCILL /) {
-       $license = "CeCILL $license";
+       push @spdx_license, "PHP-$1";
     }
 
     if ($licensetext =~ /under the terms of the CeCILL-([^ ]+) /) {
        $license = "CeCILL-$1 $license";
+       push @spdx_license, "CECILL-$1";
+    }
+    elsif ($licensetext =~ /under the terms of the CeCILL /) {
+       $license = "CeCILL $license";
+       push @spdx_license, 'CECILL';
     }
 
     if ($licensetext =~ /under the SGI Free Software License B/) {
        $license = "SGI Free Software License B $license";
+       push @spdx_license, 'SGI-B';
     }
 
     if ($licensetext =~ /is in the public domain/i) {
        $license = "Public domain $license";
+       push @spdx_license, 'public-domain'; # not listed by SPDX
     }
 
     if ($licensetext =~ /terms of the Common Development and Distribution 
License(, Version ([^(]+))? \(the License\)/) {
        $license = "CDDL " . ($1 ? "(v$2) " : '') . $license;
+       push @spdx_license, 'CDDL' . ( $1 ? "-$2" : '');
     }
 
     if ($licensetext =~ /Microsoft Permissive License \(Ms-PL\)/) {
         $license = "Ms-PL $license";
+       push @spdx_license, 'MS-PL';
     }
 
     if ($licensetext =~ /Licensed under the Academic Free License version 
([\d.]+)/) {
         $license = $1 ? "AFL-$1" : "AFL";
+       push @spdx_license, 'AFL' . ( $1 ? "-$1" : '');
     }
 
     if ($licensetext =~ /This program and the accompanying materials are made 
available under the terms of the Eclipse Public License v?([\d.]+)/) {
         $license = $1 ? "EPL-$1" : "EPL";
+       push @spdx_license, 'EPL' . ( $1 ? "-$1" : '');
     }
 
     # quotes were removed by clean_comments function
     if ($licensetext =~ /Permission is hereby granted, free of charge, to any 
person or organization obtaining a copy of the software and accompanying 
documentation covered by this license \(the Software\)/ or
        $licensetext =~ /Boost Software License([ ,-]+Version ([^ ]+)?(\.))/i) {
        $license = "BSL " . ($1 ? "(v$2) " : '') . $license;
+       push @spdx_license, 'BSL' . ( $1 ? "-$2" : '');
     }
 
     if ($licensetext =~ /PYTHON SOFTWARE FOUNDATION LICENSE (VERSION ([^ 
]+))/i) {
        $license = "PSF " . ($1 ? "(v$2) " : '') . $license;
+       push @spdx_license, 'Python' . ( $1 ? "-$2" : '');
     }
 
     if ($licensetext =~ /The origin of this software must not be 
misrepresented.*Altered source versions must be plainly marked as such.*This 
notice may not be removed or altered from any source distribution/ or
         $licensetext =~ /see copyright notice in zlib\.h/) {
        $license = "zlib/libpng $license";
+       push @spdx_license, 'Zlib';
     } elsif ($licensetext =~ /This code is released under the libpng license/) 
{
         $license = "libpng $license";
+       push @spdx_license, 'Libpng';
     }
 
     if ($licensetext =~ /Do What The Fuck You Want To Public License, Version 
([^, ]+)/i) {
         $license = "WTFPL (v$1) $license";
+       push @spdx_license, "WTFPL-$1";
     }
 
     if ($licensetext =~ /Do what The Fuck You Want To Public License/i) {
         $license = "WTFPL $license";
+       push @spdx_license, "WTFPL";
     }
 
     if ($licensetext =~ /(License WTFPL|Under (the|a) WTFPL)/i) {
         $license = "WTFPL $license";
+       push @spdx_license, "WTFPL";
     }
 
     $license = "UNKNOWN" if (!length($license));
+    push @spdx_license, "UNKNOWN" unless @spdx_license;
 
     # Remove trailing spaces.
     $license =~ s/\s+$//;
 
-    return $license;
+    return $OPT{'deb-fmt'} ? join(' or ', @spdx_license) : $license;
 }
 
 sub fatal {
diff --git a/test/test_licensecheck b/test/test_licensecheck
index 3ede643..db8ffcf 100755
--- a/test/test_licensecheck
+++ b/test/test_licensecheck
@@ -46,6 +46,8 @@ testBoost() {
 testArtistic() {
     license2 "-m --copyright" "artistic-2-0-modules.pm" "Artistic (v2.0)       
2009 Moritz Lenz and the SVG::Plot contributors (see file"
     license2 "-m --copyright" "artistic-2-0.txt" "Artistic (v2.0)      
2000-2006, The Perl Foundation / 2000 Testophilus Testownik 
<[email protected]>"
+    license2 "-m --copyright --deb-fmt" "artistic-2-0-modules.pm" 
"Artistic-2.0        2009 Moritz Lenz and the SVG::Plot contributors (see file"
+    license2 "-m --copyright --deb-fmt" "artistic-2-0.txt" "Artistic-2.0       
2000-2006, The Perl Foundation / 2000 Testophilus Testownik 
<[email protected]>"
 }
 
 testAcademic() {
@@ -54,6 +56,7 @@ testAcademic() {
 
 testEclipse() {
     license2 "-m --copyright" "epl.h" "EPL-1.0 2004, 2006 IBM Corporation and 
others"
+    license2 "-m --copyright --deb-fmt" "epl.h" "EPL-1.0       2004, 2006 IBM 
Corporation and others"
 }
 
 testBSD() {
@@ -86,6 +89,9 @@ testLGPL() {
     license2  "-m --copyright" "lgpl-big-blue.h" "LGPL (v2.1)  2000, 2010 IBM 
Corporation and others. All rights reserved"
     license2  "-m --copyright" "lgpl-digia.c" "LGPL (v2.1 or v3)       2014 
Digia Plc and/or its subsidiary(-ies)"
     license2  "-m --copyright" "lgpl-by-dist-zilla.pl" "LGPL (v2.1)    2016 
Dominique Dumont"
+    license2  "-m --copyright --deb-fmt" "lgpl-big-blue.h" "LGPL-2.1   2000, 
2010 IBM Corporation and others. All rights reserved"
+    license2  "-m --copyright --deb-fmt" "lgpl-digia.c" "LGPL-2.1 or LGPL-3    
2014 Digia Plc and/or its subsidiary(-ies)"
+    license2  "-m --copyright --deb-fmt" "lgpl-by-dist-zilla.pl" "LGPL-2.1     
2016 Dominique Dumont"
 }
 
 # Lisp Lesser General Public License (BTS #806424) 
@@ -123,6 +129,7 @@ testMPL() {
 
 testFreeType() {
     license2 "-m --copyright" "freetype.c" "FreeType   2001, 2012 David 
Turner, Robert Wilhelm, and Werner Lemberg."
+    license2 "-m --copyright --deb-fmt" "freetype.c" "FTL      2001, 2012 
David Turner, Robert Wilhelm, and Werner Lemberg."
 }
 
 testCDDL() {

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/collab-maint/devscripts.git

_______________________________________________
devscripts-devel mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/devscripts-devel

Reply via email to