Make check_licenses about 5x faster.

I've used a profiler and removed code that takes long time
bug we don't use, and optimized several regular expressions.

BUG=28291

Review URL: http://codereview.chromium.org/7988008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102307 0039d316-1c4b-4281-b951-d872f2087c98
parent 50d8c0ee
--- licensecheck.pl.orig 2011-09-12 15:54:33.369133553 -0700 --- licensecheck.pl.orig 2011-09-22 10:51:25.934402455 -0700
+++ licensecheck.pl 2011-09-12 16:53:51.189069386 -0700 +++ licensecheck.pl 2011-09-22 10:45:54.585545044 -0700
@@ -406,7 +406,7 @@ @@ -277,10 +277,6 @@
while (<F>) {
last if ($. > $opt_lines);
$content .= $_;
- $copyright_match = parse_copyright($_);
- if ($copyright_match) {
- $copyrights{lc("$copyright_match")} = "$copyright_match";
- }
}
close(F);
@@ -298,7 +294,6 @@
$license = parselicense($content);
print "$file: ";
- print "*No copyright* " unless $copyright;
print $license . "\n";
print " [Copyright: " . $copyright . "]\n"
if $copyright and $opt_copyright;
@@ -398,15 +393,11 @@
$gplver = " (v$1 or later)";
}
- if ($licensetext =~ /(?:675 Mass Ave|59 Temple Place|51 Franklin Steet|02139|02111-1307)/i) {
- $extrainfo = " (with incorrect FSF address)$extrainfo";
- }
-
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"
} }
...@@ -9,7 +36,30 @@ ...@@ -9,7 +36,30 @@
$license = "GENERATED FILE"; $license = "GENERATED FILE";
} }
@@ -437,7 +437,7 @@ @@ -414,20 +405,12 @@
$license = "LGPL$gplver$extrainfo $license";
}
- if ($licensetext =~ /is free software.? you can redistribute it and\/or modify it under the terms of the (GNU Affero General Public License|AGPL)/i) {
- $license = "AGPL$gplver$extrainfo $license";
- }
-
if ($licensetext =~ /is free software.? you (can|may) redistribute it and\/or modify it under the terms of (?:version [^ ]+ (?:\(?only\)? )?of )?the GNU General Public License/i) {
$license = "GPL$gplver$extrainfo $license";
- }
-
- if ($licensetext =~ /is distributed under the terms of the GNU General Public License,/
+ } elsif ($licensetext =~ /is distributed under the terms of the GNU General Public License,/
and length $gplver) {
$license = "GPL$gplver$extrainfo $license";
- }
-
- if ($licensetext =~ /is distributed.*terms.*GPL/) {
+ } elsif ($licensetext =~ /is distributed.*terms.*GPL/) {
$license = "GPL (unversioned/unknown version) $license";
}
@@ -437,7 +420,7 @@
$license = "QPL $license"; $license = "QPL $license";
} }
...@@ -18,29 +68,39 @@ ...@@ -18,29 +68,39 @@
$license = "MIT/X11 (BSD like) $license"; $license = "MIT/X11 (BSD like) $license";
} elsif ($licensetext =~ /Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files \(the Software\), to deal in the Software/) { } elsif ($licensetext =~ /Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files \(the Software\), to deal in the Software/) {
$license = "MIT/X11 (BSD like) $license"; $license = "MIT/X11 (BSD like) $license";
@@ -459,6 +459,12 @@ @@ -448,15 +431,19 @@
}
} }
+ if ($licensetext =~ /Use of this source code is governed by a BSD-style license/) { 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) {
+ if ($licensetext =~ /All advertising materials mentioning features or use of this software must display the following/) {
$license = "BSD (4 clause) $license";
- } elsif ($licensetext =~ /(The name of .*? may not|Neither the names? of .*? nor the names of (its|their) contributors may) be used to endorse or promote products derived from this software/i) {
+ } elsif ($licensetext =~ /be used to endorse or promote products derived from this software/) {
$license = "BSD (3 clause) $license";
- } elsif ($licensetext =~ /Redistributions of source code must retain the above copyright notice/i) {
+ } elsif ($licensetext =~ /Redistributions of source code must retain the above copyright notice/) {
$license = "BSD (2 clause) $license";
} else {
$license = "BSD $license";
}
+ } elsif ($licensetext =~ /Use of this source code is governed by a BSD-style license/) {
+ $license = "BSD-like $license"; + $license = "BSD-like $license";
+ } elsif ($licensetext =~ /BSD terms apply.*see.*COPYING.*for details/) { + } elsif ($licensetext =~ /BSD terms apply/) {
+ $license = "BSD-like $license"; + $license = "BSD-like $license";
+ }
+
if ($licensetext =~ /Mozilla Public License Version ([^ ]+)/) {
$license = "MPL (v$1) $license";
} }
@@ -495,7 +501,7 @@
if ($licensetext =~ /Mozilla Public License Version ([^ ]+)/) {
@@ -495,7 +482,7 @@
$license = "SGI Free Software License B $license"; $license = "SGI Free Software License B $license";
} }
- if ($licensetext =~ /is in the public domain/i) { - if ($licensetext =~ /is in the public domain/i) {
+ if ($licensetext =~ /is.*in the public domain|disclaims copyright/i) { + if ($licensetext =~ /in the public domain/i) {
$license = "Public domain"; $license = "Public domain";
} }
@@ -503,6 +509,10 @@ @@ -503,6 +490,10 @@
$license = "CDDL " . ($1 ? "(v$2) " : '') . $license; $license = "CDDL " . ($1 ? "(v$2) " : '') . $license;
} }
...@@ -51,12 +111,24 @@ ...@@ -51,12 +111,24 @@
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 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) { $licensetext =~ /Boost Software License([ ,-]+Version ([^ ]+)?(\.))/i) {
$license = "BSL " . ($1 ? "(v$2) " : '') . $license; $license = "BSL " . ($1 ? "(v$2) " : '') . $license;
@@ -515,6 +525,8 @@ @@ -515,18 +506,8 @@
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 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/) { $licensetext =~ /see copyright notice in zlib\.h/) {
$license = "zlib/libpng $license"; $license = "zlib/libpng $license";
- }
-
- if ($licensetext =~ /Do What The Fuck You Want To Public License, Version ([^, ]+)/i) {
- $license = "WTFPL (v$1)";
- }
-
- if ($licensetext =~ /Do what The Fuck You Want To Public License/i) {
- $license = "WTFPL";
- }
-
- if ($licensetext =~ /(License WTFPL|Under (the|a) WTFPL)/i) {
- $license = "WTFPL";
+ } elsif ($licensetext =~ /This code is released under the libpng license/) { + } elsif ($licensetext =~ /This code is released under the libpng license/) {
+ $license = "libpng $license"; + $license = "libpng $license";
} }
if ($licensetext =~ /Do What The Fuck You Want To Public License, Version ([^, ]+)/i) { $license = "UNKNOWN" if (!length($license));
...@@ -277,10 +277,6 @@ while (@files) { ...@@ -277,10 +277,6 @@ while (@files) {
while (<F>) { while (<F>) {
last if ($. > $opt_lines); last if ($. > $opt_lines);
$content .= $_; $content .= $_;
$copyright_match = parse_copyright($_);
if ($copyright_match) {
$copyrights{lc("$copyright_match")} = "$copyright_match";
}
} }
close(F); close(F);
...@@ -298,7 +294,6 @@ while (@files) { ...@@ -298,7 +294,6 @@ while (@files) {
$license = parselicense($content); $license = parselicense($content);
print "$file: "; print "$file: ";
print "*No copyright* " unless $copyright;
print $license . "\n"; print $license . "\n";
print " [Copyright: " . $copyright . "]\n" print " [Copyright: " . $copyright . "]\n"
if $copyright and $opt_copyright; if $copyright and $opt_copyright;
...@@ -398,10 +393,6 @@ sub parselicense($) { ...@@ -398,10 +393,6 @@ sub parselicense($) {
$gplver = " (v$1 or later)"; $gplver = " (v$1 or later)";
} }
if ($licensetext =~ /(?:675 Mass Ave|59 Temple Place|51 Franklin Steet|02139|02111-1307)/i) {
$extrainfo = " (with incorrect FSF address)$extrainfo";
}
if ($licensetext =~ /permission (?:is (also granted|given))? to link (the code of )?this program with (any edition of )?(Qt|the Qt library)/i) { 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"
} }
...@@ -414,20 +405,12 @@ sub parselicense($) { ...@@ -414,20 +405,12 @@ sub parselicense($) {
$license = "LGPL$gplver$extrainfo $license"; $license = "LGPL$gplver$extrainfo $license";
} }
if ($licensetext =~ /is free software.? you can redistribute it and\/or modify it under the terms of the (GNU Affero General Public License|AGPL)/i) {
$license = "AGPL$gplver$extrainfo $license";
}
if ($licensetext =~ /is free software.? you (can|may) redistribute it and\/or modify it under the terms of (?:version [^ ]+ (?:\(?only\)? )?of )?the GNU General Public License/i) { if ($licensetext =~ /is free software.? you (can|may) redistribute it and\/or modify it under the terms of (?:version [^ ]+ (?:\(?only\)? )?of )?the GNU General Public License/i) {
$license = "GPL$gplver$extrainfo $license"; $license = "GPL$gplver$extrainfo $license";
} } elsif ($licensetext =~ /is distributed under the terms of the GNU General Public License,/
if ($licensetext =~ /is distributed under the terms of the GNU General Public License,/
and length $gplver) { and length $gplver) {
$license = "GPL$gplver$extrainfo $license"; $license = "GPL$gplver$extrainfo $license";
} } elsif ($licensetext =~ /is distributed.*terms.*GPL/) {
if ($licensetext =~ /is distributed.*terms.*GPL/) {
$license = "GPL (unversioned/unknown version) $license"; $license = "GPL (unversioned/unknown version) $license";
} }
...@@ -448,20 +431,18 @@ sub parselicense($) { ...@@ -448,20 +431,18 @@ sub parselicense($) {
} }
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 =~ /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) { if ($licensetext =~ /All advertising materials mentioning features or use of this software must display the following/) {
$license = "BSD (4 clause) $license"; $license = "BSD (4 clause) $license";
} elsif ($licensetext =~ /(The name of .*? may not|Neither the names? of .*? nor the names of (its|their) contributors may) be used to endorse or promote products derived from this software/i) { } elsif ($licensetext =~ /be used to endorse or promote products derived from this software/) {
$license = "BSD (3 clause) $license"; $license = "BSD (3 clause) $license";
} elsif ($licensetext =~ /Redistributions of source code must retain the above copyright notice/i) { } elsif ($licensetext =~ /Redistributions of source code must retain the above copyright notice/) {
$license = "BSD (2 clause) $license"; $license = "BSD (2 clause) $license";
} else { } else {
$license = "BSD $license"; $license = "BSD $license";
} }
} } elsif ($licensetext =~ /Use of this source code is governed by a BSD-style license/) {
if ($licensetext =~ /Use of this source code is governed by a BSD-style license/) {
$license = "BSD-like $license"; $license = "BSD-like $license";
} elsif ($licensetext =~ /BSD terms apply.*see.*COPYING.*for details/) { } elsif ($licensetext =~ /BSD terms apply/) {
$license = "BSD-like $license"; $license = "BSD-like $license";
} }
...@@ -501,7 +482,7 @@ sub parselicense($) { ...@@ -501,7 +482,7 @@ sub parselicense($) {
$license = "SGI Free Software License B $license"; $license = "SGI Free Software License B $license";
} }
if ($licensetext =~ /is.*in the public domain|disclaims copyright/i) { if ($licensetext =~ /in the public domain/i) {
$license = "Public domain"; $license = "Public domain";
} }
...@@ -529,18 +510,6 @@ sub parselicense($) { ...@@ -529,18 +510,6 @@ sub parselicense($) {
$license = "libpng $license"; $license = "libpng $license";
} }
if ($licensetext =~ /Do What The Fuck You Want To Public License, Version ([^, ]+)/i) {
$license = "WTFPL (v$1)";
}
if ($licensetext =~ /Do what The Fuck You Want To Public License/i) {
$license = "WTFPL";
}
if ($licensetext =~ /(License WTFPL|Under (the|a) WTFPL)/i) {
$license = "WTFPL";
}
$license = "UNKNOWN" if (!length($license)); $license = "UNKNOWN" if (!length($license));
return $license; return $license;
......
...@@ -37,14 +37,12 @@ WHITELISTED_LICENSES = [ ...@@ -37,14 +37,12 @@ WHITELISTED_LICENSES = [
'BSD (2 clause) MIT/X11 (BSD like)', 'BSD (2 clause) MIT/X11 (BSD like)',
'BSD (3 clause)', 'BSD (3 clause)',
'BSD (3 clause) ISC', 'BSD (3 clause) ISC',
'BSD (3 clause) LGPL (v2.1 or later) (with incorrect FSF address)', 'BSD (3 clause) LGPL (v2.1 or later)',
'BSD (3 clause) MIT/X11 (BSD like)', 'BSD (3 clause) MIT/X11 (BSD like)',
'BSD (4 clause)', 'BSD (4 clause)',
'BSD-like', 'BSD-like',
# TODO(phajdan.jr): Make licensecheck not print BSD-like twice. # TODO(phajdan.jr): Make licensecheck not print BSD-like twice.
'BSD-like BSD (2 clause)',
'BSD-like BSD (3 clause)',
'BSD-like MIT/X11 (BSD like)', 'BSD-like MIT/X11 (BSD like)',
'BSL (v1.0)', 'BSL (v1.0)',
...@@ -54,7 +52,6 @@ WHITELISTED_LICENSES = [ ...@@ -54,7 +52,6 @@ WHITELISTED_LICENSES = [
'LGPL', 'LGPL',
'LGPL (v2)', 'LGPL (v2)',
'LGPL (v2 or later)', 'LGPL (v2 or later)',
'LGPL (v2 or later) (with incorrect FSF address)',
'LGPL (v2.1)', 'LGPL (v2.1)',
'LGPL (v3 or later)', 'LGPL (v3 or later)',
...@@ -62,8 +59,7 @@ WHITELISTED_LICENSES = [ ...@@ -62,8 +59,7 @@ WHITELISTED_LICENSES = [
'LGPL (v2,1 or later)', 'LGPL (v2,1 or later)',
'LGPL (v2.1 or later)', 'LGPL (v2.1 or later)',
'LGPL (v2.1 or later) (with incorrect FSF address)', 'MPL (v1.0) LGPL (v2 or later)',
'MPL (v1.0) LGPL (v2 or later) (with incorrect FSF address)',
'MPL (v1.1)', 'MPL (v1.1)',
'MPL (v1.1) BSD-like', 'MPL (v1.1) BSD-like',
'MPL (v1.1) BSD-like GPL (unversioned/unknown version)', 'MPL (v1.1) BSD-like GPL (unversioned/unknown version)',
...@@ -129,11 +125,10 @@ PATH_SPECIFIC_WHITELISTED_LICENSES = { ...@@ -129,11 +125,10 @@ PATH_SPECIFIC_WHITELISTED_LICENSES = {
'UNKNOWN', 'UNKNOWN',
], ],
'native_client/toolchain': [ 'native_client/toolchain': [
'BSD GPL (v2 or later) (with incorrect FSF address)', 'BSD GPL (v2 or later)',
'BSD (2 clause) GPL (v2 or later)', 'BSD (2 clause) GPL (v2 or later)',
'BSL (v1.0) GPL', 'BSL (v1.0) GPL',
'GPL', 'GPL',
'GPL (with incorrect FSF address)',
'GPL (unversioned/unknown version)', 'GPL (unversioned/unknown version)',
'GPL (v2)', 'GPL (v2)',
...@@ -141,7 +136,6 @@ PATH_SPECIFIC_WHITELISTED_LICENSES = { ...@@ -141,7 +136,6 @@ PATH_SPECIFIC_WHITELISTED_LICENSES = {
'GPL (v2,)', 'GPL (v2,)',
'GPL (v2 or later)', 'GPL (v2 or later)',
'GPL (v2 or later) (with incorrect FSF address)',
# TODO(phajdan.jr): Make licensecheck not print the comma after 3.1. # TODO(phajdan.jr): Make licensecheck not print the comma after 3.1.
'GPL (v3.1,)', 'GPL (v3.1,)',
...@@ -153,7 +147,7 @@ PATH_SPECIFIC_WHITELISTED_LICENSES = { ...@@ -153,7 +147,7 @@ PATH_SPECIFIC_WHITELISTED_LICENSES = {
'UNKNOWN', 'UNKNOWN',
], ],
'net/tools/spdyshark': [ 'net/tools/spdyshark': [
'GPL (v2 or later) (with incorrect FSF address)', 'GPL (v2 or later)',
'UNKNOWN', 'UNKNOWN',
], ],
'ppapi/c/documentation/check.sh': [ 'ppapi/c/documentation/check.sh': [
...@@ -181,8 +175,8 @@ PATH_SPECIFIC_WHITELISTED_LICENSES = { ...@@ -181,8 +175,8 @@ PATH_SPECIFIC_WHITELISTED_LICENSES = {
'GPL', 'GPL',
], ],
'third_party/WebKit/Source/JavaScriptCore/tests/mozilla': [ 'third_party/WebKit/Source/JavaScriptCore/tests/mozilla': [
'GPL',
'GPL (unversioned/unknown version)', 'GPL (unversioned/unknown version)',
'GPL (with incorrect FSF address)',
], ],
'third_party/active_doc': [ 'third_party/active_doc': [
'UNKNOWN', 'UNKNOWN',
...@@ -256,7 +250,7 @@ PATH_SPECIFIC_WHITELISTED_LICENSES = { ...@@ -256,7 +250,7 @@ PATH_SPECIFIC_WHITELISTED_LICENSES = {
'UNKNOWN', 'UNKNOWN',
], ],
'third_party/lcov/contrib/galaxy/genflat.pl': [ 'third_party/lcov/contrib/galaxy/genflat.pl': [
'GPL (v2 or later) (with incorrect FSF address)', 'GPL (v2 or later)',
], ],
'third_party/leveldatabase/src/util/posix_logger.h': [ 'third_party/leveldatabase/src/util/posix_logger.h': [
'UNKNOWN', 'UNKNOWN',
...@@ -284,7 +278,6 @@ PATH_SPECIFIC_WHITELISTED_LICENSES = { ...@@ -284,7 +278,6 @@ PATH_SPECIFIC_WHITELISTED_LICENSES = {
], ],
'third_party/libvpx/source/libvpx/examples/includes': [ 'third_party/libvpx/source/libvpx/examples/includes': [
'GPL (v2 or later)', 'GPL (v2 or later)',
'GPL (v2 or later) (with incorrect FSF address)',
], ],
'third_party/libwebp': [ 'third_party/libwebp': [
'UNKNOWN', 'UNKNOWN',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment