OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
2 # Copyright (c) 2011 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. | |
5 | |
6 """Makes sure that all files contain proper licensing information.""" | |
7 | |
8 | |
9 import optparse | |
10 import os.path | |
11 import subprocess | |
12 import sys | |
13 | |
14 | |
15 def PrintUsage(): | |
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". | |
20 | |
21 tocheck Specifies the directory, relative to root, to check. This defaults | |
22 to "." so it checks everything. | |
23 | |
24 Examples: | |
25 python checklicenses.py | |
26 python checklicenses.py --root ~/chromium/src third_party""" | |
27 | |
28 | |
29 WHITELISTED_LICENSES = [ | |
30 'Apache (v2.0)', | |
31 'Apache (v2.0) BSD (2 clause)', | |
32 'BSD', | |
33 'BSD (2 clause)', | |
34 'BSD (2 clause) MIT/X11 (BSD like)', | |
35 'BSD (3 clause)', | |
36 'BSD (3 clause) MIT/X11 (BSD like)', | |
37 'BSD (4 clause)', | |
38 'BSD-like', | |
39 | |
40 # TODO(phajdan.jr): Make licensecheck not print BSD-like twice. | |
41 'BSD-like BSD (2 clause)', | |
42 'BSD-like BSD (3 clause)', | |
43 'BSD-like MIT/X11 (BSD like)', | |
44 | |
45 'BSL (v1.0)', | |
46 # TODO(phajdan.jr): Make licensecheck not print the comma after 3.1. | |
47 'BSL (v1.0) GPL (v3.1,)', | |
48 'ISC', | |
49 'LGPL', | |
50 'LGPL (v2)', | |
51 'LGPL (v2 or later)', | |
52 'LGPL (v2 or later) (with incorrect FSF address)', | |
53 'LGPL (v2.1)', | |
54 'LGPL (v3 or later)', | |
55 | |
56 # TODO(phajdan.jr): Make licensecheck convert that comma to a dot. | |
57 'LGPL (v2,1 or later)', | |
58 | |
59 'LGPL (v2.1 or later)', | |
60 'LGPL (v2.1 or later) (with incorrect FSF address)', | |
61 'MPL (v1.0) LGPL (v2 or later) (with incorrect FSF address)', | |
62 'MPL (v1.1) BSD-like', | |
63 'MPL (v1.1) BSD-like GPL (unversioned/unknown version)', | |
64 'MPL (v1.1) GPL (unversioned/unknown version)', | |
65 | |
66 # TODO(phajdan.jr): Make licensecheck not print the comma after 1.1. | |
67 'MPL (v1.1,) GPL (unversioned/unknown version) LGPL (v2 or later)', | |
68 'MPL (v1.1,) GPL (unversioned/unknown version) LGPL (v2.1 or later)', | |
69 | |
70 'MIT/X11 (BSD like)', | |
71 'Ms-PL', | |
72 'Public domain', | |
73 'libpng', | |
74 'zlib/libpng', | |
75 ] | |
76 | |
77 | |
78 PATH_SPECIFIC_WHITELISTED_LICENSES = { | |
79 'base/third_party/dmg_fp': [ | |
80 'UNKNOWN', | |
81 ], | |
82 'base/third_party/icu': [ | |
83 'UNKNOWN', | |
84 ], | |
85 'breakpad/src': [ | |
86 'UNKNOWN', | |
87 ], | |
88 'chrome/common/extensions/docs/examples': [ | |
89 'UNKNOWN', | |
90 ], | |
91 'chrome/test/data/layout_tests/LayoutTests': [ | |
92 'UNKNOWN', | |
93 ], | |
94 'courgette/third_party/bsdiff_create.cc': [ | |
95 'UNKNOWN', | |
96 ], | |
97 'googleurl': [ | |
98 'UNKNOWN', | |
99 ], | |
100 'gpu/GLES2': [ | |
101 'UNKNOWN', | |
102 ], | |
103 'gpu/KHR': [ | |
104 'UNKNOWN', | |
105 ], | |
106 'gpu/gles2_conform_support/egl/native/EGL': [ | |
107 'UNKNOWN', | |
108 ], | |
109 'native_client': [ | |
110 'UNKNOWN', | |
111 ], | |
112 'native_client/toolchain/linux_x86_newlib': [ | |
113 'GPL', | |
114 'GPL (v3.1,)', | |
115 ], | |
116 'net/disk_cache/hash.cc': [ | |
117 'UNKNOWN', | |
118 ], | |
119 'net/third_party/nss/patches/applypatches.sh': [ | |
120 'UNKNOWN', | |
121 ], | |
122 'net/tools/spdyshark': [ | |
123 'GPL (v2 or later) (with incorrect FSF address)', | |
124 'UNKNOWN', | |
125 ], | |
126 'ppapi/c/documentation/check.sh': [ | |
127 'UNKNOWN', | |
128 ], | |
129 'ppapi/cpp/documentation/check.sh': [ | |
130 'UNKNOWN', | |
131 ], | |
132 'ppapi/lib/gl/include': [ | |
133 'UNKNOWN', | |
134 ], | |
135 'remoting/tools/gethosts.sh': [ | |
136 'UNKNOWN', | |
137 ], | |
138 'sdch/open-vcdiff': [ | |
139 'UNKNOWN', | |
140 ], | |
141 'third_party/WebKit': [ | |
142 'UNKNOWN', | |
143 ], | |
144 'third_party/WebKit/Source/ThirdParty/ANGLE/src/compiler': [ | |
145 'GPL', | |
146 ], | |
147 'third_party/WebKit/Source/JavaScriptCore/tests/mozilla': [ | |
148 'GPL (unversioned/unknown version)', | |
149 'GPL (with incorrect FSF address)', | |
150 ], | |
151 'third_party/active_doc': [ | |
152 'UNKNOWN', | |
153 ], | |
154 'third_party/apple/ImageAndTextCell.h': [ | |
155 'UNKNOWN', | |
156 ], | |
157 'third_party/apple_apsl': [ | |
158 'UNKNOWN', | |
159 ], | |
160 'third_party/angle': [ | |
161 'UNKNOWN', | |
162 ], | |
163 'third_party/angle/src/compiler': [ | |
164 'GPL', | |
165 ], | |
166 'third_party/ashmem/ashmem.h': [ | |
167 'UNKNOWN', | |
168 ], | |
169 'third_party/bsdiff/mbsdiff.cc': [ | |
170 'UNKNOWN', | |
171 ], | |
172 'third_party/bzip2': [ | |
173 'UNKNOWN', | |
174 ], | |
175 'third_party/cacheinvalidation': [ | |
176 'UNKNOWN', | |
177 ], | |
178 'third_party/cld/encodings/compact_lang_det': [ | |
179 'UNKNOWN', | |
180 ], | |
181 'third_party/devscripts': [ | |
182 'GPL (v2 or later)', | |
183 ], | |
184 'third_party/expat/files/lib': [ | |
185 'UNKNOWN', | |
186 ], | |
187 'third_party/ffmpeg': [ | |
188 'GPL', | |
189 'GPL (v2 or later)', | |
190 'UNKNOWN', | |
191 ], | |
192 'third_party/gles2_book': [ | |
193 'UNKNOWN', | |
194 ], | |
195 'third_party/gpsd/release-2.38/gps.h': [ | |
196 'UNKNOWN', | |
197 ], | |
198 'third_party/harfbuzz': [ | |
199 'UNKNOWN', | |
200 ], | |
201 'third_party/hunspell': [ | |
202 'UNKNOWN', | |
203 ], | |
204 'third_party/hyphen': [ | |
205 'UNKNOWN', | |
206 ], | |
207 'third_party/iccjpeg': [ | |
208 'UNKNOWN', | |
209 ], | |
210 'third_party/icu': [ | |
211 'UNKNOWN', | |
212 ], | |
213 'third_party/jemalloc': [ | |
214 'UNKNOWN', | |
215 ], | |
216 'third_party/lcov': [ | |
217 'UNKNOWN', | |
218 ], | |
219 'third_party/lcov/contrib/galaxy/genflat.pl': [ | |
220 'GPL (v2 or later) (with incorrect FSF address)', | |
221 ], | |
222 'third_party/leveldatabase/src/util/posix_logger.h': [ | |
223 'UNKNOWN', | |
224 ], | |
225 'third_party/libevent': [ | |
226 'UNKNOWN', | |
227 ], | |
228 'third_party/libjingle/source/talk': [ | |
229 'UNKNOWN', | |
230 ], | |
231 'third_party/libjpeg': [ | |
232 'UNKNOWN', | |
233 ], | |
234 'third_party/libjpeg_turbo': [ | |
235 'UNKNOWN', | |
236 ], | |
237 'third_party/libphonenumber/cpp/src': [ | |
238 'UNKNOWN', | |
239 ], | |
240 'third_party/libpng': [ | |
241 'UNKNOWN', | |
242 ], | |
243 'third_party/libvpx/source': [ | |
244 'UNKNOWN', | |
245 ], | |
246 'third_party/libvpx/source/libvpx/examples/includes': [ | |
247 'GPL (v2 or later)', | |
248 'GPL (v2 or later) (with incorrect FSF address)', | |
249 ], | |
250 'third_party/libwebp': [ | |
251 'UNKNOWN', | |
252 ], | |
253 'third_party/libxml': [ | |
254 'UNKNOWN', | |
255 ], | |
256 'third_party/libxslt': [ | |
257 'UNKNOWN', | |
258 ], | |
259 'third_party/lzma_sdk': [ | |
260 'UNKNOWN', | |
261 ], | |
262 'third_party/mesa/MesaLib': [ | |
263 'GPL (v2)', | |
264 'GPL (v3 or later)', | |
265 'UNKNOWN', | |
266 ], | |
267 'third_party/modp_b64': [ | |
268 'UNKNOWN', | |
269 ], | |
270 'third_party/npapi/npspy/extern/java': [ | |
271 'GPL (unversioned/unknown version)', | |
272 ], | |
273 'third_party/openssl': [ | |
274 'UNKNOWN', | |
275 ], | |
276 'third_party/ots/tools/ttf-checksum.py': [ | |
277 'UNKNOWN', | |
278 ], | |
279 'third_party/molokocacao/NSBezierPath+MCAdditions.h': [ | |
280 'UNKNOWN', | |
281 ], | |
282 'third_party/npapi/npspy': [ | |
283 'UNKNOWN', | |
284 ], | |
285 'third_party/ocmock/OCMock': [ | |
286 'UNKNOWN', | |
287 ], | |
288 'third_party/ply/__init__.py': [ | |
289 'UNKNOWN', | |
290 ], | |
291 'third_party/protobuf': [ | |
292 'UNKNOWN', | |
293 ], | |
294 'third_party/psutil': [ | |
295 'UNKNOWN', | |
296 ], | |
297 'third_party/pyftpdlib/src': [ | |
298 'UNKNOWN', | |
299 ], | |
300 'third_party/pylib': [ | |
301 'UNKNOWN', | |
302 ], | |
303 'third_party/qcms': [ | |
304 'UNKNOWN', | |
305 ], | |
306 'third_party/scons-2.0.1/engine/SCons': [ | |
307 'UNKNOWN', | |
308 ], | |
309 'third_party/simplejson': [ | |
310 'UNKNOWN', | |
311 ], | |
312 'third_party/skia': [ | |
313 'UNKNOWN', | |
314 ], | |
315 'third_party/snappy/src': [ | |
316 'UNKNOWN', | |
317 ], | |
318 'third_party/smhasher/src': [ | |
319 'UNKNOWN', | |
320 ], | |
321 'third_party/speex/include/speex/speex_types.h': [ | |
322 'UNKNOWN', | |
323 ], | |
324 'third_party/sqlite': [ | |
325 'UNKNOWN', | |
326 ], | |
327 'third_party/swig/Lib/linkruntime.c': [ | |
328 'UNKNOWN', | |
329 ], | |
330 'third_party/talloc': [ | |
331 'GPL (v3 or later)', | |
332 'UNKNOWN', | |
333 ], | |
334 'third_party/tcmalloc': [ | |
335 'UNKNOWN', | |
336 ], | |
337 'third_party/tlslite': [ | |
338 'UNKNOWN', | |
339 ], | |
340 'third_party/webdriver': [ | |
341 'UNKNOWN', | |
342 ], | |
343 'third_party/webrtc': [ | |
344 'UNKNOWN', | |
345 ], | |
346 'third_party/xdg-utils': [ | |
347 'UNKNOWN', | |
348 ], | |
349 'third_party/yasm/source': [ | |
350 'UNKNOWN', | |
351 ], | |
352 'third_party/zlib/contrib/minizip': [ | |
353 'UNKNOWN', | |
354 ], | |
355 'third_party/zlib/trees.h': [ | |
356 'UNKNOWN', | |
357 ], | |
358 'tools/dromaeo_benchmark_runner/dromaeo_benchmark_runner.py': [ | |
359 'UNKNOWN', | |
360 ], | |
361 'tools/emacs': [ | |
362 'UNKNOWN', | |
363 ], | |
364 'tools/grit/grit/node/custom/__init__.py': [ | |
365 'UNKNOWN', | |
366 ], | |
367 'tools/gyp/test': [ | |
368 'UNKNOWN', | |
369 ], | |
370 'tools/memory_watcher': [ | |
371 'UNKNOWN', | |
372 ], | |
373 'tools/playback_benchmark': [ | |
374 'UNKNOWN', | |
375 ], | |
376 'tools/python/google/__init__.py': [ | |
377 'UNKNOWN', | |
378 ], | |
379 'tools/site_compare': [ | |
380 'UNKNOWN', | |
381 ], | |
382 'tools/stats_viewer/Properties/AssemblyInfo.cs': [ | |
383 'UNKNOWN', | |
384 ], | |
385 'tools/symsrc/pefile.py': [ | |
386 'UNKNOWN', | |
387 ], | |
388 'tools/valgrind': [ | |
389 'UNKNOWN', | |
390 ], | |
391 'v8/test/cctest': [ | |
392 'UNKNOWN', | |
393 ], | |
394 } | |
395 | |
396 | |
397 def main(options, args): | |
398 # Figure out which directory we have to check. | |
399 if len(args) == 0: | |
400 # No directory to check specified, use the repository root. | |
401 start_dir = options.base_directory | |
402 elif len(args) == 1: | |
403 # Directory specified. Start here. It's supposed to be relative to the | |
404 # base directory. | |
405 start_dir = os.path.abspath(os.path.join(options.base_directory, args[0])) | |
406 else: | |
407 # More than one argument, we don't handle this. | |
408 PrintUsage() | |
409 sys.exit(1) | |
410 | |
411 print "Using base directory:", options.base_directory | |
412 print "Checking:", start_dir | |
413 | |
414 licensecheck_path = os.path.abspath(os.path.join(options.base_directory, | |
415 'third_party', | |
416 'devscripts', | |
417 'licensecheck.pl')) | |
418 | |
419 licensecheck = subprocess.Popen([licensecheck_path, '-r', start_dir], | |
420 stdout=subprocess.PIPE, | |
421 stderr=subprocess.PIPE) | |
422 stdout, stderr = licensecheck.communicate() | |
423 if options.verbose: | |
424 print '----------- licensecheck stdout -----------' | |
425 print stdout | |
426 print '--------- end licensecheck stdout ---------' | |
427 if licensecheck.returncode != 0 or stderr: | |
428 print '----------- licensecheck stderr -----------' | |
429 print stderr | |
430 print '--------- end licensecheck stderr ---------' | |
431 print "\nFAILED\n" | |
432 sys.exit(1) | |
433 | |
434 success = True | |
435 for line in stdout.splitlines(): | |
436 filename, license = line.split(':', 1) | |
437 filename = os.path.relpath(filename.strip(), options.base_directory) | |
438 | |
439 # For now we're just interested in the license. | |
440 license = license.replace('*No copyright*', '').strip() | |
441 | |
442 # Skip generated files. | |
443 if 'GENERATED FILE' in license: | |
444 continue | |
445 | |
446 if license in WHITELISTED_LICENSES: | |
447 continue | |
448 | |
449 found_path_specific = False | |
450 for prefix in PATH_SPECIFIC_WHITELISTED_LICENSES: | |
451 if (filename.startswith(prefix) and | |
452 license in PATH_SPECIFIC_WHITELISTED_LICENSES[prefix]): | |
453 found_path_specific = True | |
454 break | |
455 if found_path_specific: | |
456 continue | |
457 | |
458 print "'%s' has non-whitelisted license '%s'" % (filename, license) | |
459 success = False | |
460 | |
461 if success: | |
462 print "\nSUCCESS\n" | |
463 sys.exit(0) | |
464 else: | |
465 print "\nFAILED\n" | |
466 sys.exit(1) | |
467 | |
468 | |
469 if '__main__' == __name__: | |
470 default_root = os.path.abspath( | |
471 os.path.join(os.path.dirname(__file__), '..', '..')) | |
472 option_parser = optparse.OptionParser() | |
473 option_parser.add_option('', '--root', default=default_root, | |
Evan Martin
2011/09/14 01:51:27
You can leave out the empty '' arg. (add_option i
| |
474 dest='base_directory', | |
475 help='Specifies the repository root. This defaults ' | |
476 'to "../.." relative to the script file, which ' | |
477 'will normally be the repository root.') | |
478 option_parser.add_option('-v', '--verbose', action='store_true', | |
479 default=False, help='Print debug logging') | |
480 options, args = option_parser.parse_args() | |
481 main(options, args) | |
OLD | NEW |