Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Unified Diff: third_party/devscripts/licensecheck.pl

Issue 15736030: Add JSON.pm to third_party (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update to v2.59, proper override Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/devscripts/licensecheck.pl
diff --git a/third_party/devscripts/licensecheck.pl b/third_party/devscripts/licensecheck.pl
index beb1d3bdf511464c28a5f47e07e8a0b3a39530c7..3166030b154846b8d459189f74f1de8f443c6ebd 100755
--- a/third_party/devscripts/licensecheck.pl
+++ b/third_party/devscripts/licensecheck.pl
@@ -136,10 +136,13 @@ use strict;
use warnings;
use Getopt::Long qw(:config gnu_getopt);
use File::Basename;
+use Tie::File;
+use Fcntl 'O_RDONLY';
sub fatal($);
sub parse_copyright($);
sub parselicense($);
+sub remove_comments($);
my $progname = basename($0);
@@ -284,7 +287,7 @@ while (@ARGV) {
while (@files) {
my $file = shift @files;
- my $content = '';
+ my $header = '';
Paweł Hajdan Jr. 2013/06/06 18:16:03 Please remove these modifications from this CL.
Nils Barth (inactive) 2013/06/07 09:10:13 Got it, handled in: Issue 16426003: Add footer lic
my $copyright_match;
my $copyright = '';
my $license = '';
@@ -293,24 +296,35 @@ while (@files) {
open (F, "<$file") or die "Unable to access $file\n";
while (<F>) {
last if ($. > $opt_lines);
- $content .= $_;
+ $header .= $_;
}
close(F);
$copyright = join(" / ", values %copyrights);
- print qq(----- $file header -----\n$content----- end header -----\n\n)
+ print qq(----- $file header -----\n$header----- end header -----\n\n)
if $opt_verbose;
- # Remove Fortran comments
- $content =~ s/^[cC] //gm;
- $content =~ tr/\t\r\n/ /;
- # Remove C / C++ comments
- $content =~ s#(\*/|/[/*])##g;
- $content =~ tr% A-Za-z.,@;0-9\(\)/-%%cd;
- $content =~ tr/ //s;
+ remove_comments($header);
+ $license = parselicense($header);
+
+ # If no license in header, check footer (slow, because read file backwards)
+ # Need for instance for Perl files, which often use the footer
+ if ($license eq "UNKNOWN") {
+ my $footer = '';
+ tie(my @file_lines, "Tie::File", $file, autochomp => 0, mode => O_RDONLY) or die("Unable to access $file\n");
+ # Avoid indexing error if header is entire file
+ if ($#file_lines >= $opt_lines) {
+ foreach (@file_lines[-$opt_lines .. -1]) {
+ $footer .= $_;
+ }
+ }
+ print qq(----- $file footer -----\n$header----- end footer -----\n\n)
+ if $opt_verbose;
+ remove_comments($footer);
+ $license = parselicense($footer);
+ }
- $license = parselicense($content);
if ($opt_machine) {
print "$file\t$license";
print "\t" . ($copyright or "*No copyright*") if $opt_copyright;
@@ -325,6 +339,18 @@ while (@files) {
}
}
+sub remove_comments($) {
+ $_ = $_[0];
+ # Remove Fortran comments
+ s/^[cC] //gm;
+ tr/\t\r\n/ /;
+ # Remove C / C++ comments
+ s#(\*/|/[/*])##g;
+ tr% A-Za-z.,@;0-9\(\)/-%%cd;
+ tr/ //s;
+ $_[0] = $_;
+}
+
sub parse_copyright($) {
my $copyright = '';
my $match;
@@ -498,7 +524,7 @@ sub parselicense($) {
$license = "Artistic $license";
}
- if ($licensetext =~ /This program is free software; you can redistribute it and\/or modify it under the same terms as Perl itself/) {
+ if ($licensetext =~ /This (program|library) is free software; you can redistribute it and\/or modify it under the same terms as Perl itself/) {
$license = "Perl $license";
}

Powered by Google App Engine
This is Rietveld 408576698