~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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#!/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 libjingle',
  'Public domain',
  'Apache (v2.0)',
  'Apache (v2.0) GENERATED FILE',
  'Apache (v2.0) BSD (2 clause)',
  'BSD (2 clause)',
  'BSD (2 clause) GENERATED FILE',
  'BSD (2 clause)/LGPL 2 (or later)/LGPL 2.1 (or later)',
  'BSD (2 or 3 clause)',
  'BSD (3 clause)',
  'BSD (3 clause) GENERATED FILE',
  'BSD (2 clause) MIT/X11 (BSD like)',
  'BSL (v1)',
  'BSL (v1) BSD (3 clause) GENERATED FILE',
  'ICU-License',
  'GPL (with incorrect FSF address)',
  'GPL (unversioned/unknown version)',
  'GPL (v2 or later)',
  'GPL (v2 or later) compatible',
  'GPL (v2 or later) (with incorrect FSF address)',
  'GPL (v2 or later) GENERATED FILE',
  'GPL 2.0/LGPL 2.1/MPL 1.1 tri-license',
  'GPL (v3 or later)',
  'harfbuzz-License',
  'ISC GENERATED FILE',
  'ISC',
  'LGPL',
  'LGPL (v2)',
  'LGPL (v2 or later)',
  'LGPL (v2 or later) GENERATED FILE',
  'LGPL (v2.1 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)',
  'LGPL (v2.1 or later)',
  'LGPL (v2.1 or later) (with incorrect FSF address)',
  'MIT/X11 (BSD like)',
  'MIT/X11 (BSD like) GENERATED FILE',
  'MIT/X11-like (expat)',
  '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,) BSD (3 clause) GPL (unversioned/unknown version) LGPL (v2.1 or later)',
  'MPL (v1.1) GPL (unversioned/unknown version)',
  'MPL (v1.1) GPL (unversioned/unknown version) GENERATED FILE',
  'MPL 1.1/GPL 2.0/LGPL 2.1',
  'Paul Hsieh\'s Public Domain Option',
  'SGI Free Software B License (v2.0)',
  'zlib/libpng',
  'GENERATED FILE',
  '*No copyright* Apache (v2.0)',
  '*No copyright* BSD (2 clause)',
  '*No copyright* GPL (v2 or later)',
  '*No copyright* LGPL (v2 or later)',
  '*No copyright* LGPL (v2.1 or later)',
  '*No copyright* LGPL (v2 or later) (with incorrect FSF address) GENERATED FILE',
  '*No copyright* GENERATED FILE',
  '*No copyright* Public domain',
  'ZERO-CODE-FILES or GENERATED',
];

my $manually_identified = {
  '/base/third_party/dmg_fp/'   => [
    'MIT/X11 (BSD like)',
    'Copyright (c) 1991, 2000, 2001 by Lucent Technologies.'
  ],
  '/base/third_party/purify/pure_api.c'   => [
    'Public domain',
    'Explicitly no copyright'
  ],
  '/base/third_party/purify/pure.h'   => [
    'Public domain',
    '(C) Copyright IBM Corporation. 2006, 2006. All Rights Reserved.'
  ],
  '/third_party/sqlite/'   => [
    'Public domain',
    'The author disclaims all copyright. The library is in the public domain.'
  ],
  '/src/chrome/'   => [
    'BSD (3 clause)',
    'No copyright'
  ],
  '/depot_tools/tests/pymox/'   => [
    'Apache (v2.0)',
    'No copyright'
  ],
  '/googleurl/'   => [
    'BSD (3 clause)',
    'No copyright'
  ],
  '/gpu/command_buffer/common/GLES2/'   => [
    'SGI Free Software B License (v2.0)',
    'No copyright'
  ],
  '/media/tools/qt_faststart/qt_faststart.c'   => [
    'Public domain',
    'No copyright'
  ],
  '/native_client/src/third_party/libxt/'   => [
    'MIT/X11 (BSD like)',
    'No copyright'
  ],
  '/native_client/'   => [
    'BSD (3 clause)',
    'No copyright'
  ],
  '/v8/test/cctest/'   => [
    'BSD (3 clause)',
    'No copyright'
  ],
  '/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'
  ],
  '/third_party/WebKit/JavaScriptCore/icu' => [
    'ICU-License',
    'Copyright (c) 1995-2006 International Business Machines Corporation and others'
  ],
  '/third_party/WebKit/WebCore/icu/' => [
    'ICU-License',
    'Copyright (c) 1995-2006 International Business Machines Corporation and others'
  ],
  '/third_party/icu/' => [
    'ICU-License',
    'Copyright (c) 1995-2009 International Business Machines Corporation and others'
  ],
  '/third_party/harfbuzz/' => [
    'harfbuzz-License',
    'Copyright: 2000-2009 Red Hat, Inc'
  ],
  '/third_party/WebKit/JavaScriptCore/ForwardingHeaders/' => [
    'ZERO-CODE-FILES or GENERATED',
    'No copyright'
  ],
  '/third_party/WebKit/WebCore/ForwardingHeaders/' => [
    'ZERO-CODE-FILES or GENERATED',
    'No copyright'
  ],
  'build-tree/src/third_party/WebKit/WebCore/' => [
    'BSD (2 clause)/LGPL 2 (or later)/LGPL 2.1 (or later)',
    'No copyright'
  ],
  'third_party/WebKit/JavaScriptCore/' => [
    'BSD (2 clause)/LGPL 2 (or later)/LGPL 2.1 (or later)',
    'No copyright'
  ],
  'version.h' => [
    'ZERO-CODE-FILES or GENERATED',
    'No copyright'
  ],
  '/third_party/libjingle/files/talk/' => [
    'global BSD-style libjingle',
    'No copyright'
  ],
  '/third_party/skia/' => [
    'Apache (v2.0)',
    'No copyright'
  ],
  '/third_party/hunspell/' => [
    'GPL 2.0/LGPL 2.1/MPL 1.1 tri-license',
    'No copyright'
  ],
  '/third_party/expat/' => [
    'MIT/X11-like (expat)',
    'No copyright'
  ],
  '/third_party/yasm/source/patched-yasm/modules/parsers/nasm/' => [
    'LGPL',
    'No copyright'
  ],
  '/third_party/yasm/source/patched-yasm/modules/preprocs/' => [
    'LGPL',
    'No copyright'
  ],
  '/third_party/yasm/source/patched-yasm/modules/' => [
    'BSD (2 or 3 clause)',
    'No copyright'
  ],
  '/third_party/yasm/source/patched-yasm/tools/python-yasm/' => [
    'LGPL',
    'No copyright'
  ],
  '/third_party/yasm/' => [
    'GPL (v2 or later) compatible',
    'Copyright (c) 2001-2009 Peter Johnson and other Yasm developers.'
  ],
  '/third_party/tlslite/' => [
    'Public domain',
    'No copyright'
  ],
  '/third_party/ffmpeg/' => [
    'GPL (v2 or later) compatible',
    'No copyright'
  ],
  '/third_party/libevent/' => [
    'BSD (3 clause)',
    'No copyright'
  ],
  '/third_party/protobuf2/src/' => [
    'BSD (3 clause)',
    'No copyright'
  ],
  '/third_party/tcmalloc/tcmalloc/' => [
    'BSD (3 clause)',
    'No copyright'
  ],
  '/third_party/xdg-utils/' => [
    'MIT/X11 (BSD like)',
    'No copyright'
  ],
  '/net/disk_cache/hash.cc' => [
    'Paul Hsieh\'s Public Domain Option',
    'No copyright'
  ],
};

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};
        my $tmp_license = "";
        my $tmp_copyright = "";
        ($tmp_license, $tmp_copyright) = @$res;
        if (!$copyright || $copyright =~ /.*no copyright.*/ ) {
          $copyright = $tmp_copyright;
        }
        if (!$license || $license eq "UNKNOWN" || $license eq "*No copyright* UNKNOWN") {
          $license = $tmp_license;
        }
        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}{$copyright}}, [ $file ];
    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;
    $l++;
    for my $copyright (sort keys %{$$data{$dir}{$license}}) {
      my @values = values %{$$data{$dir}{$license}};
      if ($#values == 1) {
        printf "Files: %s/*\n", $dir;
      } else {
        printf "Files: %s/{", $dir;
        my $first = 1;
        for my $file (sort { $$a[0] cmp $$b[0] } @{$$data{$dir}{$license}{$copyright}}) {
          if ($first) {
            $first = 0;
          } else { 
            printf ",";
          }
          my $filename = $$file[0];
          $filename =~ s/$dir\///;
          printf "%s", $filename;
        }
        printf "}\n";
      }
      print "Copyright: $copyright:\n";
      print "License: $license\n";
      print "\n";
    }
  }
}