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 'courgette/third_party/qsufsort.h': [ # http://crbug.com/98095
135 'native_client': [ # http://crbug.com/98099
138 'native_client/toolchain': [
139 'BSD GPL (v2 or later)',
140 'BSD MIT/X11 (BSD like)',
141 'BSD (2 clause) GPL (v2 or later)',
142 'BSD (3 clause) GPL (v2 or later)',
143 'BSD (4 clause) ISC',
145 'BSL (v1.0) GPL (v3.1)',
147 'GPL (unversioned/unknown version)',
152 'MPL (v1.1) LGPL (unversioned/unknown version)',
154 'third_party/WebKit': [
158 # http://code.google.com/p/angleproject/issues/detail?id=217
159 'third_party/angle': [
163 # http://crbug.com/222828
164 # http://bugs.python.org/issue17514
165 'third_party/chromite/third_party/argparse.py': [
169 # http://crbug.com/326117
170 # https://bitbucket.org/chrisatlee/poster/issue/21
171 'third_party/chromite/third_party/poster': [
175 # http://crbug.com/333508
176 'third_party/clang_format/script': [
180 # http://crbug.com/333508
181 'buildtools/clang_format/script': [
185 # https://mail.python.org/pipermail/cython-devel/2014-July/004062.html
186 'third_party/cython': [
190 'third_party/devscripts': [
193 'third_party/catapult/tracing/third_party/devscripts': [
197 # https://github.com/shazow/apiclient/issues/8
199 'third_party/catapult/third_party/apiclient': [
202 'third_party/catapult/dashboard/third_party/apiclient': [
206 # https://bugs.launchpad.net/beautifulsoup/+bug/1481316
208 'third_party/catapult/third_party/beautifulsoup': [
211 'third_party/catapult/dashboard/third_party/beautifulsoup': [
215 # https://code.google.com/p/graphy/issues/detail?id=6
217 'third_party/catapult/third_party/graphy': [
220 'third_party/catapult/dashboard/third_party/graphy': [
224 # https://github.com/html5lib/html5lib-python/issues/125
226 'third_party/catapult/third_party/html5lib-python': [
230 # https://github.com/jcgregorio/httplib2/issues/307
232 'third_party/catapult/third_party/httplib2': [
235 'third_party/catapult/dashboard/third_party/httplib2': [
239 # https://github.com/GoogleCloudPlatform/appengine-mapreduce/issues/71
241 'third_party/catapult/third_party/mapreduce': [
244 'third_party/catapult/dashboard/third_party/mapreduce': [
248 # https://code.google.com/p/webapp-improved/issues/detail?id=103
250 'third_party/catapult/third_party/webapp2': [
253 'third_party/catapult/dashboard/third_party/webapp2': [
257 # https://github.com/Pylons/webob/issues/211
259 'third_party/catapult/third_party/WebOb': [
262 'third_party/catapult/dashboard/third_party/WebOb': [
266 # https://github.com/Pylons/webtest/issues/141
268 'third_party/catapult/third_party/webtest': [
271 'third_party/catapult/dashboard/third_party/webtest': [
275 # https://bitbucket.org/ianb/paste/issues/12/add-license-headers-to-source-files
277 'third_party/catapult/third_party/Paste': [
280 'third_party/catapult/dashboard/third_party/Paste': [
284 # https://github.com/google/oauth2client/issues/231
286 'third_party/catapult/third_party/oauth2client': [
289 'third_party/catapult/dashboard/third_party/oauth2client': [
293 # https://bitbucket.org/gutworth/six/issues/129/add-license-headers-to-source-files
295 'third_party/catapult/third_party/six': [
298 'third_party/catapult/dashboard/third_party/six': [
302 'third_party/expat/files/lib': [ # http://crbug.com/98121
305 'third_party/ffmpeg': [
310 'UNKNOWN', # http://crbug.com/98123
312 'third_party/fontconfig': [
313 # https://bugs.freedesktop.org/show_bug.cgi?id=73401
316 'third_party/freetype2': [ # http://crbug.com/177319
319 'third_party/hunspell': [ # http://crbug.com/98134
322 'third_party/iccjpeg': [ # http://crbug.com/98137
325 'third_party/icu': [ # http://crbug.com/98301
328 'third_party/jsoncpp/source': [
329 # https://github.com/open-source-parsers/jsoncpp/issues/234
332 'third_party/junit/src': [
333 # https://github.com/junit-team/junit/issues/1132
336 'third_party/lcov': [ # http://crbug.com/98304
339 'third_party/lcov/contrib/galaxy/genflat.pl': [
342 'third_party/libevent': [ # http://crbug.com/98309
345 'third_party/libjingle/source/talk': [ # http://crbug.com/98310
348 'third_party/libjpeg_turbo': [ # http://crbug.com/98314
352 # Many liblouis files are mirrored but not used in the NaCl module.
353 # They are not excluded from the mirror because of lack of infrastructure
354 # support. Getting license headers added to the files where missing is
355 # tracked in https://github.com/liblouis/liblouis/issues/22.
356 'third_party/liblouis/src': [
361 'third_party/libpng': [ # http://crbug.com/98318
365 # The following files lack license headers, but are trivial.
366 'third_party/libusb/src/libusb/os/poll_posix.h': [
370 'third_party/libvpx/source': [ # http://crbug.com/98319
373 'third_party/libxml': [
376 'third_party/libxslt': [
379 'third_party/lzma_sdk': [
382 'third_party/mesa/src': [
385 'MIT/X11 (BSD like) GPL (v3 or later) with Bison parser exception',
386 'UNKNOWN', # http://crbug.com/98450
388 'third_party/modp_b64': [
391 'third_party/openmax_dl/dl' : [
394 'third_party/openssl': [ # http://crbug.com/98451
397 'third_party/boringssl': [
398 # There are some files in BoringSSL which came from OpenSSL and have no
399 # license in them. We don't wish to add the license header ourselves
400 # thus we don't expect to pass license checks.
403 'third_party/ots/tools/ttf-checksum.py': [ # http://code.google.com/p/ots/issues/detail?id=2
406 'third_party/molokocacao': [ # http://crbug.com/98453
409 'third_party/ocmock/OCMock': [ # http://crbug.com/98454
412 'third_party/protobuf': [ # http://crbug.com/98455
416 # https://bitbucket.org/ned/coveragepy/issue/313/add-license-file-containing-2-3-or-4
417 # BSD 2-clause license.
418 'third_party/pycoverage': [
422 'third_party/pyelftools': [ # http://crbug.com/222831
425 'third_party/scons-2.0.1/engine/SCons': [ # http://crbug.com/98462
428 'third_party/simplejson': [
431 'third_party/skia': [ # http://crbug.com/98463
434 'third_party/snappy/src': [ # http://crbug.com/98464
437 'third_party/smhasher/src': [ # http://crbug.com/98465
440 'third_party/speech-dispatcher/libspeechd.h': [
443 'third_party/sqlite': [
447 # http://crbug.com/334668
449 'tools/swarming_client/third_party/httplib2': [
453 # http://crbug.com/334668
455 'tools/swarming_client/third_party/oauth2client': [
459 # http://crbug.com/471372
461 'tools/swarming_client/third_party/pyasn1': [
465 # http://crbug.com/471372
467 'tools/swarming_client/third_party/rsa': [
471 # https://github.com/kennethreitz/requests/issues/1610
472 'tools/swarming_client/third_party/requests': [
476 'third_party/talloc': [
478 'UNKNOWN', # http://crbug.com/98588
480 'third_party/tcmalloc': [
481 'UNKNOWN', # http://crbug.com/98589
483 'third_party/tlslite': [
486 'third_party/webdriver': [ # http://crbug.com/98590
490 # https://github.com/html5lib/html5lib-python/issues/125
491 # https://github.com/KhronosGroup/WebGL/issues/435
492 'third_party/webgl/src': [
496 'third_party/webrtc': [ # http://crbug.com/98592
499 'third_party/xdg-utils': [ # http://crbug.com/98593
502 'third_party/yasm/source': [ # http://crbug.com/98594
505 'third_party/zlib/contrib/minizip': [
508 'third_party/zlib/trees.h': [
511 'tools/emacs': [ # http://crbug.com/98595
517 'tools/python/google/__init__.py': [
520 'tools/stats_viewer/Properties/AssemblyInfo.cs': [
523 'tools/symsrc/pefile.py': [
526 # Not shipped, MIT license but the header files contain no licensing info.
527 'tools/telemetry/third_party/altgraph': [
530 # Not shipped, downloaded on trybots sometimes.
531 'tools/telemetry/third_party/gsutil': [
532 'BSD MIT/X11 (BSD like)',
535 # Not shipped, MIT license but the header files contain no licensing info.
536 'tools/telemetry/third_party/modulegraph': [
539 'tools/telemetry/third_party/pyserial': [
540 # https://sourceforge.net/p/pyserial/feature-requests/35/
543 'v8/test/cctest': [ # http://crbug.com/98597
546 'v8/src/third_party/kernel/tools/perf/util/jitdump.h': [ # http://crbug.com/391716
552 def check_licenses(options
, args
):
553 # Figure out which directory we have to check.
555 # No directory to check specified, use the repository root.
556 start_dir
= options
.base_directory
558 # Directory specified. Start here. It's supposed to be relative to the
560 start_dir
= os
.path
.abspath(os
.path
.join(options
.base_directory
, args
[0]))
562 # More than one argument, we don't handle this.
566 print "Using base directory:", options
.base_directory
567 print "Checking:", start_dir
570 licensecheck_path
= os
.path
.abspath(os
.path
.join(options
.base_directory
,
575 licensecheck
= subprocess
.Popen([licensecheck_path
,
578 stdout
=subprocess
.PIPE
,
579 stderr
=subprocess
.PIPE
)
580 stdout
, stderr
= licensecheck
.communicate()
582 print '----------- licensecheck stdout -----------'
584 print '--------- end licensecheck stdout ---------'
585 if licensecheck
.returncode
!= 0 or stderr
:
586 print '----------- licensecheck stderr -----------'
588 print '--------- end licensecheck stderr ---------'
592 used_suppressions
= set()
595 for line
in stdout
.splitlines():
596 filename
, license
= line
.split(':', 1)
597 filename
= os
.path
.relpath(filename
.strip(), options
.base_directory
)
599 # All files in the build output directory are generated one way or another.
600 # There's no need to check them.
601 if filename
.startswith('out/'):
604 # For now we're just interested in the license.
605 license
= license
.replace('*No copyright*', '').strip()
607 # Skip generated files.
608 if 'GENERATED FILE' in license
:
611 if license
in WHITELISTED_LICENSES
:
614 if not options
.ignore_suppressions
:
616 prefix
for prefix
in PATH_SPECIFIC_WHITELISTED_LICENSES
617 if filename
.startswith(prefix
) and
618 license
in PATH_SPECIFIC_WHITELISTED_LICENSES
[prefix
]]
620 used_suppressions
.update(set(matched_prefixes
))
623 errors
.append({'filename': filename
, 'license': license
})
626 with
open(options
.json
, 'w') as f
:
631 print "'%s' has non-whitelisted license '%s'" % (
632 error
['filename'], error
['license'])
635 print "http://www.chromium.org/developers/adding-3rd-party-libraries"
636 print "for more info how to handle the failure."
638 print "Please respect OWNERS of checklicenses.py. Changes violating"
639 print "this requirement may be reverted."
641 # Do not print unused suppressions so that above message is clearly
642 # visible and gets proper attention. Too much unrelated output
643 # would be distracting and make the important points easier to miss.
650 unused_suppressions
= set(
651 PATH_SPECIFIC_WHITELISTED_LICENSES
.iterkeys()).difference(
653 if unused_suppressions
:
654 print "\nNOTE: unused suppressions detected:\n"
655 print '\n'.join(unused_suppressions
)
661 default_root
= os
.path
.abspath(
662 os
.path
.join(os
.path
.dirname(__file__
), '..', '..'))
663 option_parser
= optparse
.OptionParser()
664 option_parser
.add_option('--root', default
=default_root
,
665 dest
='base_directory',
666 help='Specifies the repository root. This defaults '
667 'to "../.." relative to the script file, which '
668 'will normally be the repository root.')
669 option_parser
.add_option('-v', '--verbose', action
='store_true',
670 default
=False, help='Print debug logging')
671 option_parser
.add_option('--ignore-suppressions',
674 help='Ignore path-specific license whitelist.')
675 option_parser
.add_option('--json', help='Path to JSON output file')
676 options
, args
= option_parser
.parse_args()
677 return check_licenses(options
, args
)
680 if '__main__' == __name__
: