Skip to content
Snippets Groups Projects
Commit ced6dc49 authored by Ariel D'Alessandro's avatar Ariel D'Alessandro
Browse files

ci-license-scan: Report filename on blacklisted/unknown license entries


Now that license information for all the files is kept, even for those
being whitelisted, filename should be printed in the case of blacklisted
or unknown license entries. Otherwise, there's no way to detect which
copyright entry is the offending one.

Signed-off-by: default avatarAriel D'Alessandro <ariel.dalessandro@collabora.com>
parent a51aa6de
No related branches found
No related tags found
2 merge requests!226T7878: ci-license-scan: Manually check whitelisted files,!93WIP: documentation-builder: Rebase on Apertis instead of Debian Buster
......@@ -8,6 +8,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import argparse
from collections import namedtuple
from pathlib import Path
from io import BufferedReader
from itertools import chain
......@@ -332,6 +333,8 @@ class MutableCopyright(Copyright):
def paragraphs(self):
return self._Copyright__paragraphs
CopyrightEntry = namedtuple('CopyrightEntry', ['file', 'license'])
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--fail-on-change', dest='fail_on_change', action='store_true', default=False, help='fail on any changes')
......@@ -379,7 +382,7 @@ def main():
print(report, file=f)
# open for parsing as binary since copyrights may (incorrectly) contain binary data
bad_licenses = set()
unknown_licensed = False
unknown_licensed = set()
fixups = dict()
fixups_applied = set()
try:
......@@ -403,14 +406,15 @@ def main():
if copyright is not None and license is not None:
if license.synopsis.rstrip('+').lower() in disallowlist:
if not is_whitelisted(whitelist_patterns, f):
bad_licenses.add(license.synopsis)
bad_licenses.add(CopyrightEntry(f, license.synopsis))
fixups.setdefault(copyright, {}).setdefault(license, []).append(p)
else:
unknown_licensed = True
if not is_whitelisted(whitelist_patterns, f):
unknown_licensed.add(CopyrightEntry(f, p.license.synopsis))
elif p.license.synopsis.rstrip('+').lower() in disallowlist:
for f in p.files:
if not is_whitelisted(whitelist_patterns, f):
bad_licenses.add(p.license.synopsis)
bad_licenses.add(CopyrightEntry(f, p.license.synopsis))
if p.copyright and is_gibberish(p.copyright):
p.copyright = 'no-info-found'
if fixups:
......@@ -450,11 +454,11 @@ def main():
if unknown_licensed or bad_licenses:
print("\nERROR:", file=sys.stderr)
should_fail = False
if unknown_licensed:
print(" Files with UNKNOWN license found.", file=sys.stderr)
for l in unknown_licensed:
print(f" UNKNOWN license entry found: {l}", file=sys.stderr)
should_fail = args.fail_on_unknown
for l in bad_licenses:
print(f" Blacklisted license {l} found.", file=sys.stderr)
print(f" Blacklisted license entry found: {l}", file=sys.stderr)
should_fail = True
if should_fail:
sys.exit(1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment