Index: third_party/devscripts/licensecheck.pl |
diff --git a/third_party/devscripts/licensecheck.pl b/third_party/devscripts/licensecheck.pl |
index 3be28de6cd40dad97ac2a3d045f5e654106f22b1..a17ac8bceef7a4f7ad307f1aa200e8e73948e45e 100755 |
--- a/third_party/devscripts/licensecheck.pl |
+++ b/third_party/devscripts/licensecheck.pl |
@@ -288,12 +288,26 @@ while (@files) { |
my $copyright_match; |
my $copyright = ''; |
my $license = ''; |
+ my $line; |
my %copyrights; |
open (F, "<$file") or die "Unable to access $file\n"; |
while (<F>) { |
- last if ($. > $opt_lines); |
- $content .= $_; |
+ unless ($. > $opt_lines) { |
Paweł Hajdan Jr.
2013/01/25 17:54:33
This change seems pretty invasive compared to just
mnaganov (inactive)
2013/01/28 14:51:54
I'm feeding all the lines (not only up to $opt_lin
Paweł Hajdan Jr.
2013/01/28 16:28:29
If that's the case, could you rather implement tha
mnaganov (inactive)
2013/01/28 17:12:38
Finding copyrighted code isn't Android-specific (I
Paweł Hajdan Jr.
2013/01/29 09:29:38
And this is way beyond what the original licensech
|
+ $content .= $_; |
+ next unless ($opt_copyright); |
+ } else { |
+ last unless ($opt_copyright); |
+ } |
+ $line = $_; |
+ # Remove C / C++ strings to avoid false positives. |
+ if (index($line, '"') != -1) { |
+ $line =~ s/"[^"\\]*(?:\\.[^"\\]*)*"//g; |
+ } |
+ $copyright_match = parse_copyright($line); |
+ if ($copyright_match) { |
+ $copyrights{lc("$copyright_match")} = "$copyright_match"; |
+ } |
} |
close(F); |
@@ -326,6 +340,16 @@ while (@files) { |
} |
sub parse_copyright($) { |
+ |
+ my $line = $_[0]; |
Paweł Hajdan Jr.
2013/01/25 17:54:33
This seems pretty invasive too - what are you tryi
mnaganov (inactive)
2013/01/28 14:51:54
Just speeding things up. Since for Chromium, about
Paweł Hajdan Jr.
2013/01/28 16:28:29
Please include difference in run time when speed i
mnaganov (inactive)
2013/01/28 17:12:38
Not sure, what do you mean by "Android-specific sc
Paweł Hajdan Jr.
2013/01/29 09:29:38
Changes should be upstreamable though.
|
+ my $uc_line = uc($line); |
+ # Fast bailout, uses the same patterns as the regexp. |
+ return '' if (index($uc_line, 'COPYRIGHT') == -1 && |
+ index($uc_line, 'COPR.') == -1 && |
+ index($uc_line, '\x{00a9}') == -1 && |
+ index($uc_line, '\xc2\xa9') == -1 && |
+ index($uc_line, '(C)') == -1); |
+ |
my $copyright = ''; |
my $match; |
@@ -342,7 +366,7 @@ sub parse_copyright($) { |
|and|or # Part of a sentence |
)\b'; |
- if (m%$copyright_indicator_regex(?::\s*|\s+)(\S.*)$%ix) { |
+ if ($line =~ m%\W$copyright_indicator_regex(?::\s*|\s+)(\w.*)$%ix) { |
$match = $1; |
# Ignore lines matching "see foo for copyright information" etc. |
@@ -404,6 +428,7 @@ EOF |
sub parselicense($) { |
my ($licensetext) = @_; |
+ my $upcase_licensetext = uc($licensetext); |
my $gplver = ""; |
my $extrainfo = ""; |
@@ -423,8 +448,14 @@ sub parselicense($) { |
$extrainfo = " (with Qt exception)$extrainfo" |
} |
- if ($licensetext =~ /(All changes made in this file will be lost|DO NOT (EDIT|delete this file)|Generated (automatically|by|from)|generated.*file)/i) { |
- $license = "GENERATED FILE"; |
+ # The regexp is slow. First, do a quick check using index. |
Paweł Hajdan Jr.
2013/01/25 17:54:33
Is this really needed?
mnaganov (inactive)
2013/01/28 14:51:54
Yes. According to the profiler, this expression ma
Paweł Hajdan Jr.
2013/01/28 16:28:29
What is the difference in run time?
mnaganov (inactive)
2013/01/28 17:12:38
For the Android use case (scan excluding third-par
Paweł Hajdan Jr.
2013/01/29 09:29:38
Again, not worth it. Each of these modifications h
|
+ if (index($upcase_licensetext, 'ALL CHANGES MADE IN THIS FILE WILL BE LOST') != -1 || |
+ index($upcase_licensetext, 'DO NOT EDIT') != -1 || |
+ index($upcase_licensetext, 'DO NOT DELETE') != -1 || |
+ index($upcase_licensetext, 'GENERATED') != -1) { |
+ if ($licensetext =~ /(All changes made in this file will be lost|DO NOT (EDIT|delete this file)|Generated (at|automatically|data|by|from)|Automatically generated|\Wgenerated\s+(?:\w+\s+)*file\W)/i) { |
+ $license = "GENERATED FILE"; |
+ } |
} |
if ($licensetext =~ /is (free software.? you can redistribute it and\/or modify it|licensed) under the terms of (version [^ ]+ of )?the (GNU (Library |Lesser )General Public License|LGPL)/i) { |