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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/perl -w 1 #!/usr/bin/perl -w
2 # This script was originally based on the script of the same name from 2 # This script was originally based on the script of the same name from
3 # the KDE SDK (by dfaure@kde.org) 3 # the KDE SDK (by dfaure@kde.org)
4 # 4 #
5 # This version is 5 # This version is
6 # Copyright (C) 2007, 2008 Adam D. Barratt 6 # Copyright (C) 2007, 2008 Adam D. Barratt
7 # Copyright (C) 2012 Francesco Poli 7 # Copyright (C) 2012 Francesco Poli
8 # 8 #
9 # This program is free software; you can redistribute it and/or modify 9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by 10 # it under the terms of the GNU General Public License as published by
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 =head1 AUTHOR 129 =head1 AUTHOR
130 130
131 Adam D. Barratt <adam@adam-barratt.org.uk> 131 Adam D. Barratt <adam@adam-barratt.org.uk>
132 132
133 =cut 133 =cut
134 134
135 use strict; 135 use strict;
136 use warnings; 136 use warnings;
137 use Getopt::Long qw(:config gnu_getopt); 137 use Getopt::Long qw(:config gnu_getopt);
138 use File::Basename; 138 use File::Basename;
139 use Tie::File;
140 use Fcntl 'O_RDONLY';
139 141
140 sub fatal($); 142 sub fatal($);
141 sub parse_copyright($); 143 sub parse_copyright($);
142 sub parselicense($); 144 sub parselicense($);
145 sub remove_comments($);
143 146
144 my $progname = basename($0); 147 my $progname = basename($0);
145 148
146 # From dpkg-source 149 # From dpkg-source
147 my $default_ignore_regex = ' 150 my $default_ignore_regex = '
148 # Ignore general backup files 151 # Ignore general backup files
149 (?:^|/).*~$| 152 (?:^|/).*~$|
150 # Ignore emacs recovery files 153 # Ignore emacs recovery files
151 (?:^|/)\.#.*$| 154 (?:^|/)\.#.*$|
152 # Ignore vi swap files 155 # Ignore vi swap files
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 } 280 }
278 close FIND; 281 close FIND;
279 } else { 282 } else {
280 next unless ($files_count == 1) or $file =~ m%$opt_check_regex%; 283 next unless ($files_count == 1) or $file =~ m%$opt_check_regex%;
281 push @files, $file unless $file =~ m%$opt_ignore_regex%; 284 push @files, $file unless $file =~ m%$opt_ignore_regex%;
282 } 285 }
283 } 286 }
284 287
285 while (@files) { 288 while (@files) {
286 my $file = shift @files; 289 my $file = shift @files;
287 my $content = ''; 290 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
288 my $copyright_match; 291 my $copyright_match;
289 my $copyright = ''; 292 my $copyright = '';
290 my $license = ''; 293 my $license = '';
291 my %copyrights; 294 my %copyrights;
292 295
293 open (F, "<$file") or die "Unable to access $file\n"; 296 open (F, "<$file") or die "Unable to access $file\n";
294 while (<F>) { 297 while (<F>) {
295 last if ($. > $opt_lines); 298 last if ($. > $opt_lines);
296 $content .= $_; 299 $header .= $_;
297 } 300 }
298 close(F); 301 close(F);
299 302
300 $copyright = join(" / ", values %copyrights); 303 $copyright = join(" / ", values %copyrights);
301 304
302 print qq(----- $file header -----\n$content----- end header -----\n\n) 305 print qq(----- $file header -----\n$header----- end header -----\n\n)
303 if $opt_verbose; 306 if $opt_verbose;
304 307
305 # Remove Fortran comments 308 remove_comments($header);
306 $content =~ s/^[cC] //gm; 309 $license = parselicense($header);
307 $content =~ tr/\t\r\n/ /;
308 # Remove C / C++ comments
309 $content =~ s#(\*/|/[/*])##g;
310 $content =~ tr% A-Za-z.,@;0-9\(\)/-%%cd;
311 $content =~ tr/ //s;
312 310
313 $license = parselicense($content); 311 # If no license in header, check footer (slow, because read file backwards)
312 # Need for instance for Perl files, which often use the footer
313 if ($license eq "UNKNOWN") {
314 my $footer = '';
315 tie(my @file_lines, "Tie::File", $file, autochomp => 0, mode => O_RDONLY ) or die("Unable to access $file\n");
316 # Avoid indexing error if header is entire file
317 if ($#file_lines >= $opt_lines) {
318 foreach (@file_lines[-$opt_lines .. -1]) {
319 $footer .= $_;
320 }
321 }
322 print qq(----- $file footer -----\n$header----- end footer -----\n\n)
323 if $opt_verbose;
324 remove_comments($footer);
325 $license = parselicense($footer);
326 }
327
314 if ($opt_machine) { 328 if ($opt_machine) {
315 print "$file\t$license"; 329 print "$file\t$license";
316 print "\t" . ($copyright or "*No copyright*") if $opt_copyright; 330 print "\t" . ($copyright or "*No copyright*") if $opt_copyright;
317 print "\n"; 331 print "\n";
318 } else { 332 } else {
319 print "$file: "; 333 print "$file: ";
320 print "*No copyright* " unless $copyright; 334 print "*No copyright* " unless $copyright;
321 print $license . "\n"; 335 print $license . "\n";
322 print " [Copyright: " . $copyright . "]\n" 336 print " [Copyright: " . $copyright . "]\n"
323 if $copyright and $opt_copyright; 337 if $copyright and $opt_copyright;
324 print "\n" if $opt_copyright; 338 print "\n" if $opt_copyright;
325 } 339 }
326 } 340 }
327 341
342 sub remove_comments($) {
343 $_ = $_[0];
344 # Remove Fortran comments
345 s/^[cC] //gm;
346 tr/\t\r\n/ /;
347 # Remove C / C++ comments
348 s#(\*/|/[/*])##g;
349 tr% A-Za-z.,@;0-9\(\)/-%%cd;
350 tr/ //s;
351 $_[0] = $_;
352 }
353
328 sub parse_copyright($) { 354 sub parse_copyright($) {
329 my $copyright = ''; 355 my $copyright = '';
330 my $match; 356 my $match;
331 357
332 my $copyright_indicator_regex = ' 358 my $copyright_indicator_regex = '
333 (?:copyright # The full word 359 (?:copyright # The full word
334 |copr\. # Legally-valid abbreviation 360 |copr\. # Legally-valid abbreviation
335 |\x{00a9} # Unicode character COPYRIGHT SIGN 361 |\x{00a9} # Unicode character COPYRIGHT SIGN
336 |\xc2\xa9 # Unicode copyright sign encoded in iso8859 362 |\xc2\xa9 # Unicode copyright sign encoded in iso8859
337 |\(c\) # Legally-null representation of sign 363 |\(c\) # Legally-null representation of sign
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 } 517 }
492 518
493 if ($licensetext =~ /Released under the terms of the Artistic License ([^ ]+ )/) { 519 if ($licensetext =~ /Released under the terms of the Artistic License ([^ ]+ )/) {
494 $license = "Artistic (v$1) $license"; 520 $license = "Artistic (v$1) $license";
495 } 521 }
496 522
497 if ($licensetext =~ /is free software under the Artistic [Ll]icense/) { 523 if ($licensetext =~ /is free software under the Artistic [Ll]icense/) {
498 $license = "Artistic $license"; 524 $license = "Artistic $license";
499 } 525 }
500 526
501 if ($licensetext =~ /This program is free software; you can redistribute it and\/or modify it under the same terms as Perl itself/) { 527 if ($licensetext =~ /This (program|library) is free software; you can redist ribute it and\/or modify it under the same terms as Perl itself/) {
502 $license = "Perl $license"; 528 $license = "Perl $license";
503 } 529 }
504 530
505 if ($licensetext =~ /under the terms of the Apache ([^ ]+) License OR versio n 2 of the GNU/) { 531 if ($licensetext =~ /under the terms of the Apache ([^ ]+) License OR versio n 2 of the GNU/) {
506 $license = "Apache (v$1) GPL (v2) $license"; 532 $license = "Apache (v$1) GPL (v2) $license";
507 } elsif ($licensetext =~ /under the Apache License, Version ([^ ]+)/) { 533 } elsif ($licensetext =~ /under the Apache License, Version ([^ ]+)/) {
508 $license = "Apache (v$1) $license"; 534 $license = "Apache (v$1) $license";
509 } 535 }
510 536
511 if ($licensetext =~ /(THE BEER-WARE LICENSE)/i) { 537 if ($licensetext =~ /(THE BEER-WARE LICENSE)/i) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 return $license; 617 return $license;
592 } 618 }
593 619
594 sub fatal($) { 620 sub fatal($) {
595 my ($pack,$file,$line); 621 my ($pack,$file,$line);
596 ($pack,$file,$line) = caller(); 622 ($pack,$file,$line) = caller();
597 (my $msg = "$progname: fatal error at line $line:\n@_\n") =~ tr/\0//d; 623 (my $msg = "$progname: fatal error at line $line:\n@_\n") =~ tr/\0//d;
598 $msg =~ s/\n\n$/\n/; 624 $msg =~ s/\n\n$/\n/;
599 die $msg; 625 die $msg;
600 } 626 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698