nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 #!/usr/bin/env python
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
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
13 # distribution.
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.
17 #
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.
29  
30 """Makes sure that all files contain proper licensing information."""
31  
32  
33 import optparse
34 import os.path
35 import subprocess
36 import sys
37  
38  
39 def PrintUsage():
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".
44  
45 --ignore-suppressions Ignores path-specific license whitelist. Useful when
46 trying to remove a suppression/whitelist entry.
47  
48 tocheck Specifies the directory, relative to root, to check. This defaults
49 to "." so it checks everything.
50  
51 Examples:
52 python checklicenses.py
53 python checklicenses.py --root ~/chromium/src third_party""")
54  
55  
56 WHITELISTED_LICENSES = [
57 'BSD',
58 'BSD (2 clause)',
59 'BSD (2 clause) GPL (v2 or later)',
60 'BSD (3 clause)',
61 'GPL (v2 or later)',
62 'GPL (v3 or later) (with Bison parser exception)',
63 'ISC',
64 'ISC GPL (v2 or later)',
65 'LGPL (v2 or later)',
66 'LGPL (v2.1 or later)',
67 'MIT/X11 (BSD like)',
68 'Public domain',
69 'Public domain GPL (v2 or later)',
70 'Public domain MIT/X11 (BSD like)',
71 'zlib/libpng',
72 'zlib/libpng GPL (v2 or later)',
73 ]
74  
75  
76 PATH_SPECIFIC_WHITELISTED_LICENSES = {
77 'dtds': [
78 'UNKNOWN',
79 ],
80 'diameter/dictionary.dtd': [
81 'UNKNOWN',
82 ],
83 'wimaxasncp/dictionary.dtd': [
84 'UNKNOWN',
85 ],
86 'doc/': [
87 'UNKNOWN',
88 ],
89 'docbook/custom_layer_pdf.xsl': [
90 'UNKNOWN',
91 ],
92 'docbook/custom_layer_chm.xsl': [
93 'UNKNOWN',
94 ],
95 'docbook/ws.css' : [
96 'UNKNOWN'
97 ],
98 'fix': [
99 'UNKNOWN',
100 ],
101 'wsutil/g711.c': [
102 'UNKNOWN',
103 ],
104 'packaging/macosx': [
105 'UNKNOWN',
106 ],
107 'epan/except.c': [
108 'UNKNOWN',
109 ],
110 'epan/except.h': [
111 'UNKNOWN',
112 ],
113 'cmake/TestFileOffsetBits.c': [
114 'UNKNOWN',
115 ],
116 'cmake/TestWindowsFSeek.c': [
117 'UNKNOWN',
118 ],
119 # Generated header files by lex/yacc/whatever
120 'epan/dtd_grammar.h': [
121 'UNKNOWN',
122 ],
123 'epan/dfilter/grammar.h': [
124 'UNKNOWN',
125 ],
126 'epan/dfilter/grammar.c': [
127 'UNKNOWN',
128 ],
129 'epan/dissectors/packet-dtn.c': [
130 'GPL (v2 or later) GPL (v2 or later)' # TODO: make licensecheck handle this better
131 ],
132 'epan/dissectors/packet-ieee80211-radiotap-iter.': [ # Using ISC license only
133 'ISC GPL (v2)'
134 ],
135 'epan/dissectors/packet-ppi.c': [ # Using BSD (3 clause) license
136 'BSD (3 clause) GPL (v2)'
137 ],
138 'plugins/mate/mate_grammar.h': [
139 'UNKNOWN',
140 ],
141 'version.h': [
142 'UNKNOWN',
143 ],
144 # Special IDL license that appears to be compatible as far as I (not a
145 # lawyer) can tell. See
146 # https://www.wireshark.org/lists/wireshark-dev/201310/msg00234.html
147 'epan/dissectors/pidl/idl_types.h': [
148 'UNKNOWN',
149 ],
150 # Written by Ronnie Sahlberg and correctly licensed, but cannot include
151 # a license header despite the file extension as they need to be
152 # parsed by the pidl tool
153 'epan/dissectors/pidl/mapi/request.cnf.c': [
154 'UNKNOWN',
155 ],
156 'epan/dissectors/pidl/mapi/response.cnf.c': [
157 'UNKNOWN',
158 ],
159 # The following tools are under incompatible licenses (mostly GPLv3 or
160 # GPLv3+), but this is OK since they are not actually linked into Wireshark
161 'tools/pidl': [
162 'UNKNOWN',
163 ],
164 'tools/lemon': [
165 'UNKNOWN',
166 ],
167 'tools/licensecheck.pl': [
168 'GPL (v2)'
169 ],
170 # Generated files for GTK pixbuf binary bundling
171 'ui/gtk/wireshark-gresources.h': [
172 'UNKNOWN',
173 ],
174 'ui/gtk/wireshark-gresources.c': [
175 'UNKNOWN',
176 ],
177 # The airpcap code is using BSD (3 clause)
178 'epan/crypt/airpdcap_interop.h': [
179 'BSD (3 clause) GPL (v2)'
180 ],
181 'epan/crypt/airpdcap_tkip.c': [
182 'BSD (3 clause) GPL (v2)'
183 ],
184 'epan/crypt/airpdcap_ws.h': [
185 'BSD (3 clause) GPL (v2)'
186 ],
187 'epan/crypt/wep-wpadefs.h': [
188 'BSD (3 clause) GPL (v2)'
189 ],
190 'epan/crypt/airpdcap_system.h': [
191 'BSD (3 clause) GPL (v2)'
192 ],
193 'epan/crypt/airpdcap_user.h': [
194 'BSD (3 clause) GPL (v2)'
195 ],
196 'epan/crypt/airpdcap_ccmp.c': [
197 'BSD (3 clause) GPL (v2)'
198 ],
199 'epan/crypt/airpdcap_int.h': [
200 'BSD (3 clause) GPL (v2)'
201 ],
202 'epan/crypt/airpdcap.c': [
203 'BSD (3 clause) GPL (v2)'
204 ],
205 'epan/crypt/airpdcap_debug.h': [
206 'BSD (3 clause) GPL (v2)'
207 ],
208 'wsutil/airpdcap_wep.c': [
209 'BSD (3 clause) GPL (v2)'
210 ],
211 }
212  
213 def check_licenses(options, args):
214 # Figure out which directory we have to check.
215 if len(args) == 0:
216 # No directory to check specified, use the repository root.
217 start_dir = options.base_directory
218 elif len(args) == 1:
219 # Directory specified. Start here. It's supposed to be relative to the
220 # base directory.
221 start_dir = os.path.abspath(os.path.join(options.base_directory, args[0]))
222 else:
223 # More than one argument, we don't handle this.
224 PrintUsage()
225 return 1
226  
227 print("Using base directory: %s" % options.base_directory)
228 print("Checking: %s" % start_dir)
229 print("")
230  
231 licensecheck_path = os.path.abspath(os.path.join(options.base_directory,
232 'tools',
233 'licensecheck.pl'))
234  
235 licensecheck = subprocess.Popen([licensecheck_path,
236 '-l', '150',
237 '-r', start_dir],
238 stdout=subprocess.PIPE,
239 stderr=subprocess.PIPE)
240 stdout, stderr = licensecheck.communicate()
241 if sys.version_info[0] >= 3:
242 stdout = stdout.decode('utf-8')
243 stderr = stderr.decode('utf-8')
244 if options.verbose:
245 print('----------- licensecheck stdout -----------')
246 print(stdout)
247 print('--------- end licensecheck stdout ---------')
248 if licensecheck.returncode != 0 or stderr:
249 print('----------- licensecheck stderr -----------')
250 print(stderr)
251 print('--------- end licensecheck stderr ---------')
252 print("\nFAILED\n")
253 return 1
254  
255 success = True
256 exit_status = 0
257 for line in stdout.splitlines():
258 filename, license = line.split(':', 1)
259 filename = os.path.relpath(filename.strip(), options.base_directory)
260  
261 # All files in the build output directory are generated one way or another.
262 # There's no need to check them.
263 if filename.startswith('out/') or filename.startswith('sconsbuild/'):
264 continue
265  
266 # For now we're just interested in the license.
267 license = license.replace('*No copyright*', '').strip()
268  
269 # Skip generated files.
270 if 'GENERATED FILE' in license:
271 continue
272  
273 if license in WHITELISTED_LICENSES:
274 continue
275  
276 if not options.ignore_suppressions:
277 found_path_specific = False
278 for prefix in PATH_SPECIFIC_WHITELISTED_LICENSES:
279 if (filename.startswith(prefix) and
280 license in PATH_SPECIFIC_WHITELISTED_LICENSES[prefix]):
281 found_path_specific = True
282 break
283 if found_path_specific:
284 continue
285  
286 reason = "'%s' has non-whitelisted license '%s'" % (filename, license)
287 success = False
288 print(reason)
289 exit_status = 1
290  
291 if success:
292 print("\nSUCCESS\n")
293 return 0
294 else:
295 print("\nFAILED\n")
296 return exit_status
297  
298  
299 def main():
300 default_root = os.path.abspath(
301 os.path.join(os.path.dirname(__file__), '..'))
302 option_parser = optparse.OptionParser()
303 option_parser.add_option('--root', default=default_root,
304 dest='base_directory',
305 help='Specifies the repository root. This defaults '
306 'to "../.." relative to the script file, which '
307 'will normally be the repository root.')
308 option_parser.add_option('-v', '--verbose', action='store_true',
309 default=False, help='Print debug logging')
310 option_parser.add_option('--ignore-suppressions',
311 action='store_true',
312 default=False,
313 help='Ignore path-specific license whitelist.')
314 options, args = option_parser.parse_args()
315 return check_licenses(options, args)
316  
317  
318 if '__main__' == __name__:
319 sys.exit(main())