2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Makes sure that all files contain proper licensing information."""
17 print """Usage: python checklicenses.py [--root <root>] [tocheck]
18 --root Specifies the repository root. This defaults to "../.." relative
19 to the script file. This will be correct given the normal location
20 of the script in "<root>/tools/checklicenses".
22 --ignore-suppressions Ignores path-specific license whitelist. Useful when
23 trying to remove a suppression/whitelist entry.
25 tocheck Specifies the directory, relative to root, to check. This defaults
26 to "." so it checks everything.
29 python checklicenses.py
30 python checklicenses.py --root ~/chromium/src third_party"""
33 WHITELISTED_LICENSES
= [
34 'Anti-Grain Geometry',
36 'Apache (v2.0) BSD (2 clause)',
37 'Apache (v2.0) GPL (v2)',
38 'Apple MIT', # https://fedoraproject.org/wiki/Licensing/Apple_MIT_License
40 'APSL (v2) BSD (4 clause)',
44 'BSD (2 clause) MIT/X11 (BSD like)',
46 'BSD (3 clause) GPL (v2)',
48 'BSD (3 clause) LGPL (v2 or later)',
49 'BSD (3 clause) LGPL (v2.1 or later)',
50 'BSD (3 clause) MIT/X11 (BSD like)',
54 # TODO(phajdan.jr): Make licensecheck not print BSD-like twice.
55 'BSD-like MIT/X11 (BSD like)',
58 'FreeType (BSD like)',
59 'FreeType (BSD like) with patent clause',
60 'GPL (v2) LGPL (v2.1 or later)',
61 'GPL (v2 or later) with Bison parser exception',
62 'GPL (v2 or later) with libtool exception',
63 'GPL (v3 or later) with Bison parser exception',
64 'GPL with Bison parser exception',
65 'Independent JPEG Group License',
67 'LGPL (unversioned/unknown version)',
71 'LGPL (v2.1 or later)',
74 'MIT/X11 (BSD like) LGPL (v2.1 or later)',
75 'MPL (v1.0) LGPL (v2 or later)',
77 'MPL (v1.1) BSD (3 clause) GPL (v2) LGPL (v2.1 or later)',
78 'MPL (v1.1) BSD (3 clause) LGPL (v2.1 or later)',
79 'MPL (v1.1) BSD-like',
80 'MPL (v1.1) BSD-like GPL (unversioned/unknown version)',
81 'MPL (v1.1) BSD-like GPL (v2) LGPL (v2.1 or later)',
82 'MPL (v1.1) GPL (v2)',
83 'MPL (v1.1) GPL (v2) LGPL (v2 or later)',
84 'MPL (v1.1) GPL (v2) LGPL (v2.1 or later)',
85 'MPL (v1.1) GPL (unversioned/unknown version)',
86 'MPL (v1.1) LGPL (v2 or later)',
87 'MPL (v1.1) LGPL (v2.1 or later)',
92 'Public domain BSD (3 clause)',
93 'Public domain BSD-like',
94 'Public domain LGPL (v2.1 or later)',
97 'SGI Free Software License B',
99 'University of Illinois/NCSA Open Source License (BSD like)',
100 ('University of Illinois/NCSA Open Source License (BSD like) '
101 'MIT/X11 (BSD like)'),
105 PATH_SPECIFIC_WHITELISTED_LICENSES
= {
106 'base/third_party/icu': [ # http://crbug.com/98087
110 # http://code.google.com/p/google-breakpad/issues/detail?id=450
115 'buildtools/third_party/libc++/trunk/test': [
116 # http://llvm.org/bugs/show_bug.cgi?id=18291
120 'chrome/common/extensions/docs/examples': [ # http://crbug.com/98092
123 # This contains files copied from elsewhere from the tree. Since the copied
124 # directories might have suppressions below (like simplejson), whitelist the
125 # whole directory. This is also not shipped code.
126 'chrome/common/extensions/docs/server2/third_party': [
129 'courgette/third_party/bsdiff_create.cc': [ # http://crbug.com/98095
132 'native_client': [ # http://crbug.com/98099
135 'native_client/toolchain': [
136 'BSD GPL (v2 or later)',
137 'BSD MIT/X11 (BSD like)',
138 'BSD (2 clause) GPL (v2 or later)',
139 'BSD (3 clause) GPL (v2 or later)',
140 'BSD (4 clause) ISC',
142 'BSL (v1.0) GPL (v3.1)',
144 'GPL (unversioned/unknown version)',
149 'MPL (v1.1) LGPL (unversioned/unknown version)',
151 'third_party/WebKit': [
155 # http://code.google.com/p/angleproject/issues/detail?id=217
156 'third_party/angle': [
160 # http://crbug.com/222828
161 # http://bugs.python.org/issue17514
162 'third_party/chromite/third_party/argparse.py': [
166 # http://crbug.com/326117
167 # https://bitbucket.org/chrisatlee/poster/issue/21
168 'third_party/chromite/third_party/poster': [
172 # http://crbug.com/333508
173 'third_party/clang_format/script': [
177 # http://crbug.com/333508
178 'buildtools/clang_format/script': [
182 # https://mail.python.org/pipermail/cython-devel/2014-July/004062.html
183 'third_party/cython': [
187 'third_party/devscripts': [
190 'third_party/expat/files/lib': [ # http://crbug.com/98121
193 'third_party/ffmpeg': [
198 'UNKNOWN', # http://crbug.com/98123
200 'third_party/fontconfig': [
201 # https://bugs.freedesktop.org/show_bug.cgi?id=73401
204 'third_party/freetype2': [ # http://crbug.com/177319
207 'third_party/hunspell': [ # http://crbug.com/98134
210 'third_party/iccjpeg': [ # http://crbug.com/98137
213 'third_party/icu': [ # http://crbug.com/98301
216 'third_party/jsoncpp/source': [
217 # https://github.com/open-source-parsers/jsoncpp/issues/234
220 'third_party/junit/src': [
221 # https://github.com/junit-team/junit/issues/1132
224 'third_party/lcov': [ # http://crbug.com/98304
227 'third_party/lcov/contrib/galaxy/genflat.pl': [
230 'third_party/libevent': [ # http://crbug.com/98309
233 'third_party/libjingle/source/talk': [ # http://crbug.com/98310
236 'third_party/libjpeg_turbo': [ # http://crbug.com/98314
240 # Many liblouis files are mirrored but not used in the NaCl module.
241 # They are not excluded from the mirror because of lack of infrastructure
242 # support. Getting license headers added to the files where missing is
243 # tracked in https://github.com/liblouis/liblouis/issues/22.
244 'third_party/liblouis/src': [
249 'third_party/libpng': [ # http://crbug.com/98318
253 # The following files lack license headers, but are trivial.
254 'third_party/libusb/src/libusb/os/poll_posix.h': [
258 'third_party/libvpx/source': [ # http://crbug.com/98319
261 'third_party/libxml': [
264 'third_party/libxslt': [
267 'third_party/lzma_sdk': [
270 'third_party/mesa/src': [
273 'MIT/X11 (BSD like) GPL (v3 or later) with Bison parser exception',
274 'UNKNOWN', # http://crbug.com/98450
276 'third_party/modp_b64': [
279 'third_party/openmax_dl/dl' : [
282 'third_party/openssl': [ # http://crbug.com/98451
285 'third_party/boringssl': [
286 # There are some files in BoringSSL which came from OpenSSL and have no
287 # license in them. We don't wish to add the license header ourselves
288 # thus we don't expect to pass license checks.
291 'third_party/ots/tools/ttf-checksum.py': [ # http://code.google.com/p/ots/issues/detail?id=2
294 'third_party/molokocacao': [ # http://crbug.com/98453
297 'third_party/ocmock/OCMock': [ # http://crbug.com/98454
300 'third_party/protobuf': [ # http://crbug.com/98455
304 # https://bitbucket.org/ned/coveragepy/issue/313/add-license-file-containing-2-3-or-4
305 # BSD 2-clause license.
306 'third_party/pycoverage': [
310 'third_party/pyelftools': [ # http://crbug.com/222831
313 'third_party/scons-2.0.1/engine/SCons': [ # http://crbug.com/98462
316 'third_party/simplejson': [
319 'third_party/skia': [ # http://crbug.com/98463
322 'third_party/snappy/src': [ # http://crbug.com/98464
325 'third_party/smhasher/src': [ # http://crbug.com/98465
328 'third_party/speech-dispatcher/libspeechd.h': [
331 'third_party/sqlite': [
335 # http://crbug.com/334668
337 'tools/swarming_client/third_party/httplib2': [
341 # http://crbug.com/334668
343 'tools/swarming_client/third_party/oauth2client': [
347 # http://crbug.com/471372
349 'tools/swarming_client/third_party/pyasn1': [
353 # http://crbug.com/471372
355 'tools/swarming_client/third_party/rsa': [
359 # https://github.com/kennethreitz/requests/issues/1610
360 'tools/swarming_client/third_party/requests': [
364 'third_party/talloc': [
366 'UNKNOWN', # http://crbug.com/98588
368 'third_party/tcmalloc': [
369 'UNKNOWN', # http://crbug.com/98589
371 'third_party/tlslite': [
374 'third_party/webdriver': [ # http://crbug.com/98590
378 # https://github.com/html5lib/html5lib-python/issues/125
379 # https://github.com/KhronosGroup/WebGL/issues/435
380 'third_party/webgl/src': [
384 'third_party/webrtc': [ # http://crbug.com/98592
387 'third_party/xdg-utils': [ # http://crbug.com/98593
390 'third_party/yasm/source': [ # http://crbug.com/98594
393 'third_party/zlib/contrib/minizip': [
396 'third_party/zlib/trees.h': [
399 'tools/emacs': [ # http://crbug.com/98595
405 'tools/python/google/__init__.py': [
408 'tools/stats_viewer/Properties/AssemblyInfo.cs': [
411 'tools/symsrc/pefile.py': [
414 # Not shipped, downloaded on trybots sometimes.
415 'tools/telemetry/third_party/gsutil': [
416 'BSD MIT/X11 (BSD like)',
419 'tools/telemetry/third_party/pyserial': [
420 # https://sourceforge.net/p/pyserial/feature-requests/35/
423 'v8/test/cctest': [ # http://crbug.com/98597
426 'v8/src/third_party/kernel/tools/perf/util/jitdump.h': [ # http://crbug.com/391716
432 def check_licenses(options
, args
):
433 # Figure out which directory we have to check.
435 # No directory to check specified, use the repository root.
436 start_dir
= options
.base_directory
438 # Directory specified. Start here. It's supposed to be relative to the
440 start_dir
= os
.path
.abspath(os
.path
.join(options
.base_directory
, args
[0]))
442 # More than one argument, we don't handle this.
446 print "Using base directory:", options
.base_directory
447 print "Checking:", start_dir
450 licensecheck_path
= os
.path
.abspath(os
.path
.join(options
.base_directory
,
455 licensecheck
= subprocess
.Popen([licensecheck_path
,
458 stdout
=subprocess
.PIPE
,
459 stderr
=subprocess
.PIPE
)
460 stdout
, stderr
= licensecheck
.communicate()
462 print '----------- licensecheck stdout -----------'
464 print '--------- end licensecheck stdout ---------'
465 if licensecheck
.returncode
!= 0 or stderr
:
466 print '----------- licensecheck stderr -----------'
468 print '--------- end licensecheck stderr ---------'
472 used_suppressions
= set()
475 for line
in stdout
.splitlines():
476 filename
, license
= line
.split(':', 1)
477 filename
= os
.path
.relpath(filename
.strip(), options
.base_directory
)
479 # All files in the build output directory are generated one way or another.
480 # There's no need to check them.
481 if filename
.startswith('out/'):
484 # For now we're just interested in the license.
485 license
= license
.replace('*No copyright*', '').strip()
487 # Skip generated files.
488 if 'GENERATED FILE' in license
:
491 if license
in WHITELISTED_LICENSES
:
494 if not options
.ignore_suppressions
:
496 prefix
for prefix
in PATH_SPECIFIC_WHITELISTED_LICENSES
497 if filename
.startswith(prefix
) and
498 license
in PATH_SPECIFIC_WHITELISTED_LICENSES
[prefix
]]
500 used_suppressions
.update(set(matched_prefixes
))
503 errors
.append({'filename': filename
, 'license': license
})
506 with
open(options
.json
, 'w') as f
:
511 print "'%s' has non-whitelisted license '%s'" % (
512 error
['filename'], error
['license'])
515 print "http://www.chromium.org/developers/adding-3rd-party-libraries"
516 print "for more info how to handle the failure."
518 print "Please respect OWNERS of checklicenses.py. Changes violating"
519 print "this requirement may be reverted."
521 # Do not print unused suppressions so that above message is clearly
522 # visible and gets proper attention. Too much unrelated output
523 # would be distracting and make the important points easier to miss.
530 unused_suppressions
= set(
531 PATH_SPECIFIC_WHITELISTED_LICENSES
.iterkeys()).difference(
533 if unused_suppressions
:
534 print "\nNOTE: unused suppressions detected:\n"
535 print '\n'.join(unused_suppressions
)
541 default_root
= os
.path
.abspath(
542 os
.path
.join(os
.path
.dirname(__file__
), '..', '..'))
543 option_parser
= optparse
.OptionParser()
544 option_parser
.add_option('--root', default
=default_root
,
545 dest
='base_directory',
546 help='Specifies the repository root. This defaults '
547 'to "../.." relative to the script file, which '
548 'will normally be the repository root.')
549 option_parser
.add_option('-v', '--verbose', action
='store_true',
550 default
=False, help='Print debug logging')
551 option_parser
.add_option('--ignore-suppressions',
554 help='Ignore path-specific license whitelist.')
555 option_parser
.add_option('--json', help='Path to JSON output file')
556 options
, args
= option_parser
.parse_args()
557 return check_licenses(options
, args
)
560 if '__main__' == __name__
: