~chromium-team/chromium-browser/artful-beta

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/perl -w

# Check licenses of a large subtree. It uses licensecheck from devscripts
# then postprocess the results
# (c) 2009, Fabien Tassin <fta@sofaraway.org>

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

use strict;
use Getopt::Std;

my $white_listed_licenses = [
  'global BSD-style Chromium',
  'global BSD-style Webkit/LGPL 2.1',
  'Public domain',
  'Apache (v2.0)',
  'Apache (v2.0) GENERATED FILE',
  'Apache (v2.0) BSD (2 clause)',
  'BSD (2 clause)',
  'BSD (3 clause)',
  'BSD (3 clause) GENERATED FILE',
  'BSD (4 clause)',
  'BSL (v1.0)',
  'BSL (v1) BSD (3 clause) GENERATED FILE',
  'dual GPLv1+/Artistic License',
  'GPL (with incorrect FSF address)',
  'GPL (unversioned/unknown version)',
  'GPL (v2 or later)',
  'GPL (v2 or later) (with incorrect FSF address)',
  'GPL (v2 or later) GENERATED FILE',
  'ISC',
  'LGPL',
  'LGPL (v2)',
  'LGPL (v2 or later)',
  'LGPL (v2 or later) GENERATED FILE',
  'LGPL (v2 or later) (with incorrect FSF address)',
  'LGPL (v2 or later) (with incorrect FSF address) GENERATED FILE',
  'LGPL (v2.1 or later)',
  'LGPL (v2.1 or later) (with incorrect FSF address)',
  'MIT/X11 (BSD like)',
  'MIT/X11 (BSD like) GENERATED FILE',
  'MPL (v1.1,) GPL (unversioned/unknown version) LGPL (v2.1 or later)',
  'MPL (v1.1,) GPL (unversioned/unknown version) LGPL (v2 or later)',
  'MPL (v1.1) GPL (unversioned/unknown version)',
  'MPL (v1.1) GPL (unversioned/unknown version) GENERATED FILE',
  'zlib/libpng',
  'GENERATED FILE',
];

my $manually_identified = {
  '/third_party/sqlite/'   => [
    'Public domain',
    'The author disclaims all copyright. The library is in the public domain.'
  ],
  '/third_party/WebKit/WebKitLibraries/WebCoreSQLite3/' => [
    'Public domain',
    'The author disclaims all copyright. The library is in the public domain.'
  ],
  '/third_party/zlib/' => [
    'zlib/libpng',
    'This software is provided \'as-is\', without any express or implied'
  ],
  '/third_party/lzma_sdk/' => [
    'Public domain',
    'LZMA SDK is placed in the public domain.'
  ],
  '/third_party/hunspell/src/hunspell/' => [
    'MPL 1.1/GPL 2.0/LGPL 2.1',
    'The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License")'
  ],
  '/webkit/data/layout_tests' => [
    'global BSD-style Webkit/LGPL 2.1',
    'http://webkit.org/projects/goals.html'
  ],
};

my $opt = {};
getopts('ah', $opt) || &Usage();
&Usage() if $$opt{'h'};

sub Usage {
  die "Usage: $0 [options] directory\n" .
    "  -a           display all licenses found (default will hide whitelisted licenses)\n" .
    "  -h           this help screen\n";
}

my $dir = shift @ARGV;

sub get_license {
  my $file      = shift;
  my $license   = shift;
  my $copyright = shift;

  return("empty file", "empty") if -z $file;
  open(FILE, $file) || die "Can't open $file: $!\n";
  my $maxline = 60;
  my $linenum = 0;
  while (!eof(FILE) && defined (my $line = <FILE>) && $linenum < $maxline) {
    $linenum++;
    next unless $line =~ m/Copyright/i;
    chomp $line;
    # Remove indents/comments
    $line =~ s,^\s*(\#|/\*|//)\s*,,;
    # remove everything before the copyright
    $line =~ s/.*(Copyright)/$1/i;
    my $text = $line;
     while (!eof(FILE) && defined (my $line = <FILE>) && $linenum < $maxline) {
       chomp $line;
       # Remove indents/comments
       $line =~ s,^\s*(\#|/\*|//)\s*,,;
       $text .= " " .$line;
       $text =~ m/Copyright.*?The Chromium Authors. All rights reserved.*?BSD-style license.*?found.*?in the.*?LICENSE file/ && do {
         close FILE;
         return("global BSD-style Chromium", $text);
       } ||
       $text =~ m/It is free software.*?under the.*?terms of either.*?GNU General Public License.*?either version (\d+).*?any later version.*?Artistic License/ && do {
         close FILE;
         return("dual GPLv$1+/Artistic License", $text);
       } ||
       $text =~ m/The use and distribution terms for this software are covered by the.*?Microsoft Permissive License \(Ms-PL\).*?/ && do {
         close FILE;
         return("Ms-PL", $text);
       }
    }
  }
  close FILE;
  ($license, $copyright);
}

my $data = {};
my $line;
local *LC;
open(LC, "/usr/bin/licensecheck -r --copyright $dir |") ||
  die "Can't open /usr/bin/licensecheck: $!\n";
while (!eof(LC) && defined($line = <LC>)) {
  chomp $line;
  my ($file, $license, $copyright) = (undef, undef, 'UNKNOWN');
  if ($line =~ m/^(\S[^:]+): (.*)/) {
    $file = $1;
    $license = $2;
    $license =~ s/\s*$//;
    $line = <LC>;
    if ($line =~ m/^  \[(.*.)\]/) {
      $copyright = $1;
      $line = <LC>;
    }
    # check for manual identification
    for my $manual (keys %$manually_identified) {
      if ($file =~ m,$manual,) {
        my $res = $$manually_identified{$manual};
        ($license, $copyright) = @$res;
        last;
      }
    }
    if ($license eq 'UNKNOWN') {
      # Look further into that file. licensecheck may have missed something
      ($license, $copyright) = get_license($file, $license, $copyright);
    }
    #printf "%-80s %-30s %s\n", $file, $license, $copyright;
    my $path = $file;
    $path =~ s,/[^/]*$,,;
    push @{$$data{$path}{$license}}, [ $file, $copyright ];
    next if $line =~ m/^$/;
  }
  die "line='$line'\n";
}
close LC;

print "Whitelisted licenses: \n  - '" . (join "'\n  - '", @$white_listed_licenses) . "'\n\n" unless $$opt{'a'};

for my $dir (sort keys %$data) {
  my $l = 0;
  for my $license (sort keys %{$$data{$dir}}) {
    my $skip = 0;
    for my $w (@$white_listed_licenses) {
      $skip++ if $w eq $license;
    }
    next if !$$opt{'a'} && $skip;
    print "$dir/\n" if $l == 0;;
    $l++;
    print "  [ $license ]:\n";
    for my $file (sort { $$a[0] cmp $$b[0] } @{$$data{$dir}{$license}}) {
      printf "      %-80s  %s\n", $$file[0], $$file[1];
    }
  }
  print "\n" if $l;
}