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 'epan/dissectors/pidl/idl_types.h': [
167 # Special IDL license that appears to be compatible as far as I (not a
168 # lawyer) can tell. See
169 # https://www.wireshark.org/lists/wireshark-dev/201310/msg00234.html
172 # The following tools are under incompatible licenses (mostly GPLv3 or
173 # GPLv3+), but this is OK since they are not actually linked into Wireshark
177 'tools/html2text.py': [
183 def check_licenses(options
, args
):
184 # Figure out which directory we have to check.
186 # No directory to check specified, use the repository root.
187 start_dir
= options
.base_directory
189 # Directory specified. Start here. It's supposed to be relative to the
191 start_dir
= os
.path
.abspath(os
.path
.join(options
.base_directory
, args
[0]))
193 # More than one argument, we don't handle this.
197 print "Using base directory:", options
.base_directory
198 print "Checking:", start_dir
201 #licensecheck_path = os.path.abspath(os.path.join(options.base_directory,
204 # 'licensecheck.pl'))
205 licensecheck_path
= 'licensecheck'
207 licensecheck
= subprocess
.Popen([licensecheck_path
,
210 stdout
=subprocess
.PIPE
,
211 stderr
=subprocess
.PIPE
)
212 stdout
, stderr
= licensecheck
.communicate()
214 print '----------- licensecheck stdout -----------'
216 print '--------- end licensecheck stdout ---------'
217 if licensecheck
.returncode
!= 0 or stderr
:
218 print '----------- licensecheck stderr -----------'
220 print '--------- end licensecheck stderr ---------'
225 for line
in stdout
.splitlines():
226 filename
, license
= line
.split(':', 1)
227 filename
= os
.path
.relpath(filename
.strip(), options
.base_directory
)
229 # All files in the build output directory are generated one way or another.
230 # There's no need to check them.
231 if filename
.startswith('out/') or filename
.startswith('sconsbuild/'):
234 # For now we're just interested in the license.
235 license
= license
.replace('*No copyright*', '').strip()
237 # Skip generated files.
238 if 'GENERATED FILE' in license
:
241 if license
in WHITELISTED_LICENSES
:
244 if not options
.ignore_suppressions
:
245 found_path_specific
= False
246 for prefix
in PATH_SPECIFIC_WHITELISTED_LICENSES
:
247 if (filename
.startswith(prefix
) and
248 license
in PATH_SPECIFIC_WHITELISTED_LICENSES
[prefix
]):
249 found_path_specific
= True
251 if found_path_specific
:
254 print "'%s' has non-whitelisted license '%s'" % (filename
, license
)
263 print "http://www.chromium.org/developers/adding-3rd-party-libraries"
264 print "for more info how to handle the failure."
266 print "Please respect OWNERS of checklicenses.py. Changes violating"
267 print "this requirement may be reverted."
272 default_root
= os
.path
.abspath(
273 os
.path
.join(os
.path
.dirname(__file__
), '..'))
274 option_parser
= optparse
.OptionParser()
275 option_parser
.add_option('--root', default
=default_root
,
276 dest
='base_directory',
277 help='Specifies the repository root. This defaults '
278 'to "../.." relative to the script file, which '
279 'will normally be the repository root.')
280 option_parser
.add_option('-v', '--verbose', action
='store_true',
281 default
=False, help='Print debug logging')
282 option_parser
.add_option('--ignore-suppressions',
285 help='Ignore path-specific license whitelist.')
286 options
, args
= option_parser
.parse_args()
287 return check_licenses(options
, args
)
290 if '__main__' == __name__
: