Chromium Code Reviews| Index: tools/checklicenses/checklicenses.py |
| diff --git a/tools/checklicenses/checklicenses.py b/tools/checklicenses/checklicenses.py |
| index f037d8b2ee13fb821733f9a301692b78c043f025..d46f06bfe464b15794154726ac0a3219657b75a5 100755 |
| --- a/tools/checklicenses/checklicenses.py |
| +++ b/tools/checklicenses/checklicenses.py |
| @@ -6,6 +6,7 @@ |
| """Makes sure that all files contain proper licensing information.""" |
| +import json |
| import optparse |
| import os.path |
| import subprocess |
| @@ -422,8 +423,8 @@ def check_licenses(options, args): |
| return 1 |
| used_suppressions = set() |
| + errors = [] |
| - success = True |
| for line in stdout.splitlines(): |
| filename, license = line.split(':', 1) |
| filename = os.path.relpath(filename.strip(), options.base_directory) |
| @@ -452,21 +453,16 @@ def check_licenses(options, args): |
| used_suppressions.update(set(matched_prefixes)) |
| continue |
| - print "'%s' has non-whitelisted license '%s'" % (filename, license) |
| - success = False |
| + errors.append({'filename': filename, 'license': license}) |
| - if success: |
| - print "\nSUCCESS\n" |
| + if options.json: |
| + with open(options.json, 'w') as f: |
|
M-A Ruel
2014/06/05 15:01:47
'wb'
Paweł Hajdan Jr.
2014/06/05 15:38:14
For now using 'w' for consistency with other json
|
| + json.dump(errors, f) |
| - if not len(args): |
| - unused_suppressions = set( |
| - PATH_SPECIFIC_WHITELISTED_LICENSES.keys()).difference(used_suppressions) |
| - if unused_suppressions: |
| - print "\nNOTE: unused suppressions detected:\n" |
| - print '\n'.join(unused_suppressions) |
| - |
| - return 0 |
| - else: |
| + if errors: |
| + for error in errors: |
| + print "'%s' has non-whitelisted license '%s'" % ( |
| + error['filename'], error['license']) |
| print "\nFAILED\n" |
| print "Please read", |
| print "http://www.chromium.org/developers/adding-3rd-party-libraries" |
| @@ -481,6 +477,17 @@ def check_licenses(options, args): |
| return 1 |
| + print "\nSUCCESS\n" |
| + |
| + if not len(args): |
| + unused_suppressions = set( |
| + PATH_SPECIFIC_WHITELISTED_LICENSES.keys()).difference(used_suppressions) |
|
M-A Ruel
2014/06/05 15:01:47
.keys() is unnecessary, it creates a list when a g
Paweł Hajdan Jr.
2014/06/05 15:38:14
Done.
|
| + if unused_suppressions: |
| + print "\nNOTE: unused suppressions detected:\n" |
| + print '\n'.join(unused_suppressions) |
| + |
| + return 0 |
| + |
| def main(): |
| default_root = os.path.abspath( |
| @@ -497,6 +504,7 @@ def main(): |
| action='store_true', |
| default=False, |
| help='Ignore path-specific license whitelist.') |
| + option_parser.add_option('--json', help='Path to JSON output file') |
| options, args = option_parser.parse_args() |
| return check_licenses(options, args) |