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."""
16 print """Usage: python checklicenses.py [--root <root>] [tocheck]
17 --root Specifies the repository root. This defaults to "../.." relative
18 to the script file. This will be correct given the normal location
19 of the script in "<root>/tools/checklicenses".
21 --ignore-suppressions Ignores path-specific license whitelist. Useful when
22 trying to remove a suppression/whitelist entry.
24 tocheck Specifies the directory, relative to root, to check. This defaults
25 to "." so it checks everything.
28 python checklicenses.py
29 python checklicenses.py --root ~/chromium/src third_party"""
32 WHITELISTED_LICENSES
= [
34 'Apache (v2.0) BSD (2 clause)',
35 'Apache (v2.0) GPL (v2)',
36 'Apple MIT', # https://fedoraproject.org/wiki/Licensing/Apple_MIT_License
38 'APSL (v2) BSD (4 clause)',
42 'BSD (2 clause) MIT/X11 (BSD like)',
44 'BSD (3 clause) GPL (v2)',
46 'BSD (3 clause) LGPL (v2 or later)',
47 'BSD (3 clause) LGPL (v2.1 or later)',
48 'BSD (3 clause) MIT/X11 (BSD like)',
52 # TODO(phajdan.jr): Make licensecheck not print BSD-like twice.
53 'BSD-like MIT/X11 (BSD like)',
56 'GPL (v2) LGPL (v2.1 or later)',
57 'GPL (v2 or later) with Bison parser exception',
58 'GPL (v2 or later) with libtool exception',
59 'GPL (v3 or later) with Bison parser exception',
60 'GPL with Bison parser exception',
62 'LGPL (unversioned/unknown version)',
66 'LGPL (v2.1 or later)',
69 'MIT/X11 (BSD like) LGPL (v2.1 or later)',
70 'MPL (v1.0) LGPL (v2 or later)',
72 'MPL (v1.1) BSD (3 clause) GPL (v2) LGPL (v2.1 or later)',
73 'MPL (v1.1) BSD (3 clause) LGPL (v2.1 or later)',
74 'MPL (v1.1) BSD-like',
75 'MPL (v1.1) BSD-like GPL (unversioned/unknown version)',
76 'MPL (v1.1) BSD-like GPL (v2) LGPL (v2.1 or later)',
77 'MPL (v1.1) GPL (v2)',
78 'MPL (v1.1) GPL (v2) LGPL (v2 or later)',
79 'MPL (v1.1) GPL (v2) LGPL (v2.1 or later)',
80 'MPL (v1.1) GPL (unversioned/unknown version)',
81 'MPL (v1.1) LGPL (v2 or later)',
82 'MPL (v1.1) LGPL (v2.1 or later)',
87 'Public domain BSD (3 clause)',
88 'Public domain BSD-like',
89 'Public domain LGPL (v2.1 or later)',
92 'SGI Free Software License B',
93 'University of Illinois/NCSA Open Source License (BSD like)',
94 ('University of Illinois/NCSA Open Source License (BSD like) '
95 'MIT/X11 (BSD like)'),
99 PATH_SPECIFIC_WHITELISTED_LICENSES
= {
100 'base/third_party/icu': [ # http://crbug.com/98087
104 # http://code.google.com/p/google-breakpad/issues/detail?id=450
109 'chrome/common/extensions/docs/examples': [ # http://crbug.com/98092
112 'chrome/test/data/gpu/vt': [
115 'courgette/third_party/bsdiff_create.cc': [ # http://crbug.com/98095
118 'data/tab_switching': [
121 'native_client': [ # http://crbug.com/98099
124 'native_client/toolchain': [
125 'BSD GPL (v2 or later)',
126 'BSD (2 clause) GPL (v2 or later)',
127 'BSD (3 clause) GPL (v2 or later)',
129 'BSL (v1.0) GPL (v3.1)',
131 'GPL (unversioned/unknown version)',
137 'net/tools/spdyshark': [
141 'third_party/WebKit': [
145 # http://code.google.com/p/angleproject/issues/detail?id=217
146 'third_party/angle': [
150 # http://crbug.com/222828
151 # http://bugs.python.org/issue17514
152 'third_party/chromite/third_party/argparse.py': [
156 # http://crbug.com/326117
157 # https://bitbucket.org/chrisatlee/poster/issue/21
158 'third_party/chromite/third_party/poster': [
162 # http://crbug.com/333508
163 'third_party/clang_format/script': [
166 'third_party/clang_format/scripts': [
170 # Not used. http://crbug.com/156020
171 # Using third_party/cros_dbus_cplusplus/cros_dbus_cplusplus.gyp instead.
172 'third_party/cros_dbus_cplusplus/source/autogen.sh': [
175 # Included in the source tree but not built. http://crbug.com/156020
176 'third_party/cros_dbus_cplusplus/source/examples': [
179 'third_party/devscripts': [
182 'third_party/expat/files/lib': [ # http://crbug.com/98121
185 'third_party/ffmpeg': [
189 'UNKNOWN', # http://crbug.com/98123
191 'third_party/fontconfig': [
192 # https://bugs.freedesktop.org/show_bug.cgi?id=73401
195 'third_party/freetype2': [ # http://crbug.com/177319
198 'third_party/gles2_conform/GTF_ES': [ # http://crbug.com/98131
201 'third_party/hunspell': [ # http://crbug.com/98134
204 'third_party/iccjpeg': [ # http://crbug.com/98137
207 'third_party/icu': [ # http://crbug.com/98301
210 'third_party/jemalloc': [ # http://crbug.com/98302
213 'third_party/JSON': [
214 'Perl', # Build-only.
215 # License missing upstream on 3 minor files.
216 'UNKNOWN', # https://rt.cpan.org/Public/Bug/Display.html?id=85915
218 'third_party/lcov': [ # http://crbug.com/98304
221 'third_party/lcov/contrib/galaxy/genflat.pl': [
224 'third_party/libc++/trunk/include/support/solaris': [
225 # http://llvm.org/bugs/show_bug.cgi?id=18291
228 'third_party/libc++/trunk/src/support/solaris/xlocale.c': [
229 # http://llvm.org/bugs/show_bug.cgi?id=18291
232 'third_party/libc++/trunk/test': [
233 # http://llvm.org/bugs/show_bug.cgi?id=18291
236 'third_party/libevent': [ # http://crbug.com/98309
239 'third_party/libjingle/source/talk': [ # http://crbug.com/98310
242 'third_party/libjpeg': [ # http://crbug.com/98313
245 'third_party/libjpeg_turbo': [ # http://crbug.com/98314
248 'third_party/libpng': [ # http://crbug.com/98318
252 # The following files lack license headers, but are trivial.
253 'third_party/libusb/src/libusb/os/poll_posix.h': [
257 'third_party/libvpx/source': [ # http://crbug.com/98319
260 'third_party/libvpx/source/libvpx/examples/includes': [
263 'third_party/libxml': [
266 'third_party/libxslt': [
269 'third_party/lzma_sdk': [
272 'third_party/mesa/src': [
275 'MIT/X11 (BSD like) GPL (v3 or later) with Bison parser exception',
276 'UNKNOWN', # http://crbug.com/98450
278 'third_party/modp_b64': [
281 'third_party/openmax_dl/dl' : [
284 'third_party/openssl': [ # http://crbug.com/98451
287 'third_party/ots/tools/ttf-checksum.py': [ # http://code.google.com/p/ots/issues/detail?id=2
290 'third_party/molokocacao': [ # http://crbug.com/98453
293 'third_party/npapi/npspy': [
296 'third_party/ocmock/OCMock': [ # http://crbug.com/98454
299 'third_party/ply/__init__.py': [
302 'third_party/protobuf': [ # http://crbug.com/98455
306 # http://crbug.com/222831
307 # https://bitbucket.org/eliben/pyelftools/issue/12
308 'third_party/pyelftools': [
312 'third_party/scons-2.0.1/engine/SCons': [ # http://crbug.com/98462
315 'third_party/simplejson': [
318 'third_party/skia': [ # http://crbug.com/98463
321 'third_party/snappy/src': [ # http://crbug.com/98464
324 'third_party/smhasher/src': [ # http://crbug.com/98465
327 'third_party/speech-dispatcher/libspeechd.h': [
330 'third_party/sqlite': [
334 # https://code.google.com/p/colorama/issues/detail?id=44
335 'tools/swarming_client/third_party/colorama': [
339 # http://crbug.com/334668
341 'tools/swarming_client/third_party/httplib2': [
345 # http://crbug.com/334668
347 'tools/swarming_client/third_party/oauth2client': [
351 # https://github.com/kennethreitz/requests/issues/1610
352 'tools/swarming_client/third_party/requests': [
356 'third_party/swig/Lib/linkruntime.c': [ # http://crbug.com/98585
359 'third_party/talloc': [
361 'UNKNOWN', # http://crbug.com/98588
363 'third_party/tcmalloc': [
364 'UNKNOWN', # http://crbug.com/98589
366 'third_party/tlslite': [
369 'third_party/webdriver': [ # http://crbug.com/98590
373 # https://github.com/html5lib/html5lib-python/issues/125
374 # https://github.com/KhronosGroup/WebGL/issues/435
375 'third_party/webgl/src': [
379 'third_party/webrtc': [ # http://crbug.com/98592
382 'third_party/xdg-utils': [ # http://crbug.com/98593
385 'third_party/yasm/source': [ # http://crbug.com/98594
388 'third_party/zlib/contrib/minizip': [
391 'third_party/zlib/trees.h': [
394 'tools/emacs': [ # http://crbug.com/98595
400 'tools/histograms': [
403 'tools/python/google/__init__.py': [
406 'tools/stats_viewer/Properties/AssemblyInfo.cs': [
409 'tools/symsrc/pefile.py': [
412 'tools/telemetry/third_party/pyserial': [
413 # https://sourceforge.net/p/pyserial/feature-requests/35/
416 'v8/test/cctest': [ # http://crbug.com/98597
422 def check_licenses(options
, args
):
423 # Figure out which directory we have to check.
425 # No directory to check specified, use the repository root.
426 start_dir
= options
.base_directory
428 # Directory specified. Start here. It's supposed to be relative to the
430 start_dir
= os
.path
.abspath(os
.path
.join(options
.base_directory
, args
[0]))
432 # More than one argument, we don't handle this.
436 print "Using base directory:", options
.base_directory
437 print "Checking:", start_dir
440 licensecheck_path
= os
.path
.abspath(os
.path
.join(options
.base_directory
,
445 licensecheck
= subprocess
.Popen([licensecheck_path
,
448 stdout
=subprocess
.PIPE
,
449 stderr
=subprocess
.PIPE
)
450 stdout
, stderr
= licensecheck
.communicate()
452 print '----------- licensecheck stdout -----------'
454 print '--------- end licensecheck stdout ---------'
455 if licensecheck
.returncode
!= 0 or stderr
:
456 print '----------- licensecheck stderr -----------'
458 print '--------- end licensecheck stderr ---------'
462 used_suppressions
= set()
465 for line
in stdout
.splitlines():
466 filename
, license
= line
.split(':', 1)
467 filename
= os
.path
.relpath(filename
.strip(), options
.base_directory
)
469 # All files in the build output directory are generated one way or another.
470 # There's no need to check them.
471 if filename
.startswith('out/'):
474 # For now we're just interested in the license.
475 license
= license
.replace('*No copyright*', '').strip()
477 # Skip generated files.
478 if 'GENERATED FILE' in license
:
481 if license
in WHITELISTED_LICENSES
:
484 if not options
.ignore_suppressions
:
486 prefix
for prefix
in PATH_SPECIFIC_WHITELISTED_LICENSES
487 if filename
.startswith(prefix
) and
488 license
in PATH_SPECIFIC_WHITELISTED_LICENSES
[prefix
]]
490 used_suppressions
.update(set(matched_prefixes
))
493 print "'%s' has non-whitelisted license '%s'" % (filename
, license
)
499 unused_suppressions
= set(
500 PATH_SPECIFIC_WHITELISTED_LICENSES
.keys()).difference(used_suppressions
)
501 if unused_suppressions
:
502 print "\nNOTE: unused suppressions detected:\n"
503 print '\n'.join(unused_suppressions
)
509 print "http://www.chromium.org/developers/adding-3rd-party-libraries"
510 print "for more info how to handle the failure."
512 print "Please respect OWNERS of checklicenses.py. Changes violating"
513 print "this requirement may be reverted."
515 # Do not print unused suppressions so that above message is clearly
516 # visible and gets proper attention. Too much unrelated output
517 # would be distracting and make the important points easier to miss.
523 default_root
= os
.path
.abspath(
524 os
.path
.join(os
.path
.dirname(__file__
), '..', '..'))
525 option_parser
= optparse
.OptionParser()
526 option_parser
.add_option('--root', default
=default_root
,
527 dest
='base_directory',
528 help='Specifies the repository root. This defaults '
529 'to "../.." relative to the script file, which '
530 'will normally be the repository root.')
531 option_parser
.add_option('-v', '--verbose', action
='store_true',
532 default
=False, help='Print debug logging')
533 option_parser
.add_option('--ignore-suppressions',
536 help='Ignore path-specific license whitelist.')
537 options
, args
= option_parser
.parse_args()
538 return check_licenses(options
, args
)
541 if '__main__' == __name__
: