2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
14 # * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 """Makes sure that all files contain proper licensing information."""
40 print """Usage: python checklicenses.py [--root <root>] [tocheck]
41 --root Specifies the repository root. This defaults to ".." relative
42 to the script file. This will be correct given the normal location
43 of the script in "<root>/tools".
45 --ignore-suppressions Ignores path-specific license whitelist. Useful when
46 trying to remove a suppression/whitelist entry.
48 tocheck Specifies the directory, relative to root, to check. This defaults
49 to "." so it checks everything.
52 python checklicenses.py
53 python checklicenses.py --root ~/chromium/src third_party"""
56 WHITELISTED_LICENSES = [
58 'Apache (v2.0) BSD (2 clause)',
59 'Apache (v2.0) GPL (v2)',
60 'Apple MIT', # https://fedoraproject.org/wiki/Licensing/Apple_MIT_License
62 'APSL (v2) BSD (4 clause)',
65 'BSD (2 clause) GPL (v2 or later)',
66 'BSD (2 clause) MIT/X11 (BSD like)',
69 'BSD (3 clause) LGPL (v2 or later)',
70 'BSD (3 clause) LGPL (v2.1 or later)',
71 'BSD (3 clause) MIT/X11 (BSD like)',
75 # TODO(phajdan.jr): Make licensecheck not print BSD-like twice.
76 'BSD-like MIT/X11 (BSD like)',
80 'GPL (v2 or later) with Bison parser exception',
81 'GPL (v2 or later) with libtool exception',
82 'GPL (v3 or later) with Bison parser exception',
83 'GPL with Bison parser exception',
86 'ISC GPL (v2 or later)',
93 # TODO(phajdan.jr): Make licensecheck convert that comma to a dot.
94 'LGPL (v2,1 or later)',
96 'LGPL (v2.1 or later)',
97 'MPL (v1.0) LGPL (v2 or later)',
99 'MPL (v1.1) BSD-like',
100 'MPL (v1.1) BSD-like GPL (unversioned/unknown version)',
101 'MPL (v1.1,) BSD (3 clause) GPL (unversioned/unknown version) '
102 'LGPL (v2.1 or later)',
103 'MPL (v1.1) GPL (unversioned/unknown version)',
106 # TODO(phajdan.jr): Make licensecheck not print the comma after 1.1.
107 'MPL (v1.1,) GPL (unversioned/unknown version) LGPL (v2 or later)',
108 'MPL (v1.1,) GPL (unversioned/unknown version) LGPL (v2.1 or later)',
110 'MIT/X11 (BSD like)',
114 'Public domain BSD (3 clause)',
115 'Public domain BSD-like',
116 'Public domain GPL (v2 or later)',
117 'Public domain LGPL (v2.1 or later)',
120 'zlib/libpng GPL (v2 or later)',
121 'SGI Free Software License B',
122 'University of Illinois/NCSA Open Source License (BSD like)',
126 PATH_SPECIFIC_WHITELISTED_LICENSES = {
136 'wiretap/ascend.c': [
139 'wiretap/ascend.h': [
142 'packaging/macosx': [
157 'plugins/mate/mate_grammar.c': [
158 'GPL (v2 or later) LGPL (v2 or later)', # licensecheck bug?
160 'plugins/mate/mate_grammar.h': [
163 'cmake/TestFileOffsetBits.c': [
166 'cmake/TestWindowsFSeek.c': [
169 'epan/dissectors/pidl/idl_types.h': [
170 # Special IDL license that appears to be compatible as far as I (not a
171 # lawyer) can tell. See
172 # https://www.wireshark.org/lists/wireshark-dev/201310/msg00234.html
175 # The following tools are under incompatible licenses (mostly GPLv3 or
176 # GPLv3+), but this is OK since they are not actually linked into Wireshark
180 'tools/html2text.py': [
186 def check_licenses(options, args):
187 # Figure out which directory we have to check.
189 # No directory to check specified, use the repository root.
190 start_dir = options.base_directory
192 # Directory specified. Start here. It's supposed to be relative to the
194 start_dir = os.path.abspath(os.path.join(options.base_directory, args[0]))
196 # More than one argument, we don't handle this.
200 print "Using base directory:", options.base_directory
201 print "Checking:", start_dir
204 #licensecheck_path = os.path.abspath(os.path.join(options.base_directory,
207 # 'licensecheck.pl'))
208 licensecheck_path = 'licensecheck'
210 licensecheck = subprocess.Popen([licensecheck_path,
213 stdout=subprocess.PIPE,
214 stderr=subprocess.PIPE)
215 stdout, stderr = licensecheck.communicate()
217 print '----------- licensecheck stdout -----------'
219 print '--------- end licensecheck stdout ---------'
220 if licensecheck.returncode != 0 or stderr:
221 print '----------- licensecheck stderr -----------'
223 print '--------- end licensecheck stderr ---------'
228 for line in stdout.splitlines():
229 filename, license = line.split(':', 1)
230 filename = os.path.relpath(filename.strip(), options.base_directory)
232 # All files in the build output directory are generated one way or another.
233 # There's no need to check them.
234 if filename.startswith('out/') or filename.startswith('sconsbuild/'):
237 # For now we're just interested in the license.
238 license = license.replace('*No copyright*', '').strip()
240 # Skip generated files.
241 if 'GENERATED FILE' in license:
244 if license in WHITELISTED_LICENSES:
247 if not options.ignore_suppressions:
248 found_path_specific = False
249 for prefix in PATH_SPECIFIC_WHITELISTED_LICENSES:
250 if (filename.startswith(prefix) and
251 license in PATH_SPECIFIC_WHITELISTED_LICENSES[prefix]):
252 found_path_specific = True
254 if found_path_specific:
257 print "'%s' has non-whitelisted license '%s'" % (filename, license)
266 print "http://www.chromium.org/developers/adding-3rd-party-libraries"
267 print "for more info how to handle the failure."
269 print "Please respect OWNERS of checklicenses.py. Changes violating"
270 print "this requirement may be reverted."
275 default_root = os.path.abspath(
276 os.path.join(os.path.dirname(__file__), '..'))
277 option_parser = optparse.OptionParser()
278 option_parser.add_option('--root', default=default_root,
279 dest='base_directory',
280 help='Specifies the repository root. This defaults '
281 'to "../.." relative to the script file, which '
282 'will normally be the repository root.')
283 option_parser.add_option('-v', '--verbose', action='store_true',
284 default=False, help='Print debug logging')
285 option_parser.add_option('--ignore-suppressions',
288 help='Ignore path-specific license whitelist.')
289 options, args = option_parser.parse_args()
290 return check_licenses(options, args)
293 if '__main__' == __name__: