Chromium Code Reviews| Index: third_party/devscripts/licensecheck.pl |
| diff --git a/third_party/devscripts/licensecheck.pl b/third_party/devscripts/licensecheck.pl |
| index 3be28de6cd40dad97ac2a3d045f5e654106f22b1..0d8ccdad424d98aef1a18724dbab4c46963719ea 100755 |
| --- a/third_party/devscripts/licensecheck.pl |
| +++ b/third_party/devscripts/licensecheck.pl |
| @@ -164,7 +164,7 @@ my $default_ignore_regex = ' |
| $default_ignore_regex =~ s/^#.*$//mg; |
| $default_ignore_regex =~ s/\n//sg; |
| -my $default_check_regex = '\.(c(c|pp|xx)?|h(h|pp|xx)?|f(77|90)?|p(l|m)|xs|sh|php|py(|x)|rb|java|vala|el|sc(i|e)|cs|pas|inc|dtd|xsl|mod|m|tex|mli?)$'; |
| +my $default_check_regex = '\.(c(c|pp|xx)?|h(h|pp|xx)?|f(77|90)?|p(l|m)|xs|sh|php|py(|x)|rb|java|vala|el|sc(i|e)|cs|pas|inc|dtd|xsl|mod|m|tex|mli?|js|html|pac|mm|asm|idl)$'; |
|
Paweł Hajdan Jr.
2013/01/29 09:29:38
nit: Please move "mm" case near existing "m", chan
|
| my $modified_conf_msg; |
| @@ -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) { |
| + $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]; |
| + 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. |
| + 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) { |