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 = [
59 'BSD (2 clause) GPL (v2 or later)',
62 'GPL (v3 or later) (with Bison parser exception)',
64 'ISC GPL (v2 or later)',
66 'LGPL (v2.1 or later)',
69 'Public domain GPL (v2 or later)',
70 'Public domain MIT/X11 (BSD like)',
72 'zlib/libpng GPL (v2 or later)',
76 PATH_SPECIFIC_WHITELISTED_LICENSES = {
77 'caputils/airpcap.h': [
80 'wsutil/strnatcmp.c': [
83 'wsutil/strnatcmp.h': [
89 'diameter/dictionary.dtd': [
92 'wimaxasncp/dictionary.dtd': [
98 'docbook/custom_layer_chm.xsl': [
101 'docbook/custom_layer_single_html.xsl': [
113 'packaging/macosx': [
122 'cmake/TestFileOffsetBits.c': [
125 'cmake/TestWindowsFSeek.c': [
128 # Generated header files by lex/yacc/whatever
129 'epan/dtd_grammar.h': [
132 'epan/dfilter/grammar.h': [
135 'epan/dfilter/grammar.c': [
138 'epan/dissectors/packet-dtn.c': [
139 'GPL (v2 or later) GPL (v2 or later)' # TODO: make licensecheck handle this better
141 'epan/dissectors/packet-ieee80211-radiotap-iter.': [ # Using ISC license only
144 'epan/dissectors/packet-ppi.c': [ # Using BSD (3 clause) license
145 'BSD (3 clause) GPL (v2)'
147 'plugins/mate/mate_grammar.h': [
153 # Special IDL license that appears to be compatible as far as I (not a
154 # lawyer) can tell. See
155 # https://www.wireshark.org/lists/wireshark-dev/201310/msg00234.html
156 'epan/dissectors/pidl/idl_types.h': [
159 # Written by Ronnie Sahlberg and correctly licensed, but cannot include
160 # a license header despite the file extension as they need to be
161 # parsed by the pidl tool
162 'epan/dissectors/pidl/mapi/request.cnf.c': [
165 'epan/dissectors/pidl/mapi/response.cnf.c': [
168 # The following tools are under incompatible licenses (mostly GPLv3 or
169 # GPLv3+), but this is OK since they are not actually linked into Wireshark
176 'tools/licensecheck.pl': [
179 # Generated files for GTK pixbuf binary bundling
180 'ui/gtk/wireshark-gresources.h': [
183 'ui/gtk/wireshark-gresources.c': [
186 # The airpcap code is using BSD (3 clause)
187 'epan/crypt/dot11decrypt_interop.h': [
188 'BSD (3 clause) GPL (v2)'
190 'epan/crypt/dot11decrypt_tkip.c': [
191 'BSD (3 clause) GPL (v2)'
193 'epan/crypt/dot11decrypt_ws.h': [
194 'BSD (3 clause) GPL (v2)'
196 'epan/crypt/wep-wpadefs.h': [
197 'BSD (3 clause) GPL (v2)'
199 'epan/crypt/dot11decrypt_system.h': [
200 'BSD (3 clause) GPL (v2)'
202 'epan/crypt/dot11decrypt_user.h': [
203 'BSD (3 clause) GPL (v2)'
205 'epan/crypt/dot11decrypt_ccmp.c': [
206 'BSD (3 clause) GPL (v2)'
208 'epan/crypt/dot11decrypt_int.h': [
209 'BSD (3 clause) GPL (v2)'
211 'epan/crypt/dot11decrypt.c': [
212 'BSD (3 clause) GPL (v2)'
214 'epan/crypt/dot11decrypt_debug.h': [
215 'BSD (3 clause) GPL (v2)'
217 'wsutil/dot11decrypt_wep.c': [
218 'BSD (3 clause) GPL (v2)'
222 def check_licenses(options, args):
223 # Figure out which directory we have to check.
225 # No directory to check specified, use the repository root.
226 start_dir = options.base_directory
228 # Directory specified. Start here. It's supposed to be relative to the
230 start_dir = os.path.abspath(os.path.join(options.base_directory, args[0]))
232 # More than one argument, we don't handle this.
236 print("Using base directory: %s" % options.base_directory)
237 print("Checking: %s" % start_dir)
240 licensecheck_path = os.path.abspath(os.path.join(options.base_directory,
244 licensecheck = subprocess.Popen([licensecheck_path,
247 stdout=subprocess.PIPE,
248 stderr=subprocess.PIPE)
249 stdout, stderr = licensecheck.communicate()
250 if sys.version_info[0] >= 3:
251 stdout = stdout.decode('utf-8')
252 stderr = stderr.decode('utf-8')
254 print('----------- licensecheck stdout -----------')
256 print('--------- end licensecheck stdout ---------')
257 if licensecheck.returncode != 0 or stderr:
258 print('----------- licensecheck stderr -----------')
260 print('--------- end licensecheck stderr ---------')
266 for line in stdout.splitlines():
267 filename, license = line.split(':', 1)
268 filename = os.path.relpath(filename.strip(), options.base_directory)
270 # All files in the build output directory are generated one way or another.
271 # There's no need to check them.
272 if filename.startswith('out/') or filename.startswith('sconsbuild/'):
275 # For now we're just interested in the license.
276 license = license.replace('*No copyright*', '').strip()
278 # Skip generated files.
279 if 'GENERATED FILE' in license:
282 if license in WHITELISTED_LICENSES:
285 if not options.ignore_suppressions:
286 found_path_specific = False
287 for prefix in PATH_SPECIFIC_WHITELISTED_LICENSES:
288 if (filename.startswith(prefix) and
289 license in PATH_SPECIFIC_WHITELISTED_LICENSES[prefix]):
290 found_path_specific = True
292 if found_path_specific:
295 reason = "'%s' has non-whitelisted license '%s'" % (filename, license)
309 default_root = os.path.abspath(
310 os.path.join(os.path.dirname(__file__), '..'))
311 option_parser = optparse.OptionParser()
312 option_parser.add_option('--root', default=default_root,
313 dest='base_directory',
314 help='Specifies the repository root. This defaults '
315 'to "../.." relative to the script file, which '
316 'will normally be the repository root.')
317 option_parser.add_option('-v', '--verbose', action='store_true',
318 default=False, help='Print debug logging')
319 option_parser.add_option('--ignore-suppressions',
322 help='Ignore path-specific license whitelist.')
323 options, args = option_parser.parse_args()
324 return check_licenses(options, args)
327 if '__main__' == __name__: