OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Checks third-party licenses for the purposes of the Android WebView build. | 6 """Checks third-party licenses for the purposes of the Android WebView build. |
7 | 7 |
8 The Android tree includes a snapshot of Chromium in order to power the system | 8 The Android tree includes a snapshot of Chromium in order to power the system |
9 WebView. This tool checks that all code uses open-source licenses compatible | 9 WebView. This tool checks that all code uses open-source licenses compatible |
10 with Android, and that we meet the requirements of those licenses. It can also | 10 with Android, and that we meet the requirements of those licenses. It can also |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 for directory in sorted(third_party_dirs): | 290 for directory in sorted(third_party_dirs): |
291 metadata = licenses.ParseDir(directory, REPOSITORY_ROOT, | 291 metadata = licenses.ParseDir(directory, REPOSITORY_ROOT, |
292 require_license_file=False) | 292 require_license_file=False) |
293 license_file = metadata['License File'] | 293 license_file = metadata['License File'] |
294 if license_file and license_file != licenses.NOT_SHIPPED: | 294 if license_file and license_file != licenses.NOT_SHIPPED: |
295 content.append(_ReadFile(license_file)) | 295 content.append(_ReadFile(license_file)) |
296 | 296 |
297 return '\n'.join(content) | 297 return '\n'.join(content) |
298 | 298 |
299 | 299 |
| 300 def _ProcessIncompatibleResult(incompatible_directories): |
| 301 if incompatible_directories: |
| 302 print ("Incompatibly licensed directories found:\n" + |
| 303 "\n".join(sorted(incompatible_directories))) |
| 304 return ScanResult.Errors |
| 305 return ScanResult.Ok |
| 306 |
300 def main(): | 307 def main(): |
301 class FormatterWithNewLines(optparse.IndentedHelpFormatter): | 308 class FormatterWithNewLines(optparse.IndentedHelpFormatter): |
302 def format_description(self, description): | 309 def format_description(self, description): |
303 paras = description.split('\n') | 310 paras = description.split('\n') |
304 formatted_paras = [textwrap.fill(para, self.width) for para in paras] | 311 formatted_paras = [textwrap.fill(para, self.width) for para in paras] |
305 return '\n'.join(formatted_paras) + '\n' | 312 return '\n'.join(formatted_paras) + '\n' |
306 | 313 |
307 parser = optparse.OptionParser(formatter=FormatterWithNewLines(), | 314 parser = optparse.OptionParser(formatter=FormatterWithNewLines(), |
308 usage='%prog [options]') | 315 usage='%prog [options]') |
309 parser.description = (__doc__ + | 316 parser.description = (__doc__ + |
310 '\nCommands:\n' \ | 317 '\nCommands:\n' \ |
311 ' scan Check licenses.\n' \ | 318 ' scan Check licenses.\n' \ |
312 ' notice Generate Android NOTICE file on stdout. \n' \ | 319 ' notice Generate Android NOTICE file on stdout.\n' \ |
313 ' incompatible_directories Scan for incompatibly' | 320 ' incompatible_directories Scan for incompatibly' |
314 ' licensed directories.') | 321 ' licensed directories.\n' |
| 322 ' all_incompatible_directories Scan for incompatibly' |
| 323 ' licensed directories (even those in' |
| 324 ' known_issues.py).\n') |
315 (_, args) = parser.parse_args() | 325 (_, args) = parser.parse_args() |
316 if len(args) != 1: | 326 if len(args) != 1: |
317 parser.print_help() | 327 parser.print_help() |
318 return ScanResult.Errors | 328 return ScanResult.Errors |
319 | 329 |
320 if args[0] == 'scan': | 330 if args[0] == 'scan': |
321 scan_result = _Scan() | 331 scan_result = _Scan() |
322 if scan_result == ScanResult.Ok: | 332 if scan_result == ScanResult.Ok: |
323 print 'OK!' | 333 print 'OK!' |
324 return scan_result | 334 return scan_result |
325 elif args[0] == 'notice': | 335 elif args[0] == 'notice': |
326 print GenerateNoticeFile() | 336 print GenerateNoticeFile() |
327 return ScanResult.Ok | 337 return ScanResult.Ok |
328 elif args[0] == 'incompatible_directories': | 338 elif args[0] == 'incompatible_directories': |
329 incompatible_directories = GetUnknownIncompatibleDirectories() | 339 return _ProcessIncompatibleResult(GetUnknownIncompatibleDirectories()) |
330 if incompatible_directories: | 340 elif args[0] == 'all_incompatible_directories': |
331 print ("Incompatibly licensed directories found:\n" + | 341 return _ProcessIncompatibleResult(GetIncompatibleDirectories()) |
332 "\n".join(sorted(incompatible_directories))) | |
333 return ScanResult.Errors | |
334 return ScanResult.Ok | |
335 | |
336 parser.print_help() | 342 parser.print_help() |
337 return ScanResult.Errors | 343 return ScanResult.Errors |
338 | 344 |
339 if __name__ == '__main__': | 345 if __name__ == '__main__': |
340 sys.exit(main()) | 346 sys.exit(main()) |
OLD | NEW |