Skip to content
Snippets Groups Projects
Commit 2bac485c authored by Walter Lozano's avatar Walter Lozano
Browse files

ci-license-scan: Add proposed whitelist


While working with license scan is very common to add whitelist for
files and folders. To make this job easier, allow ci-license-scan to
propose a whitelist based on known patterns.

This feature is only meant to help developers to reduce the overheard
of the manual work, hence, the proposed changed need to be carefully
reviewed.

Signed-off-by: default avatarWalter Lozano <walter.lozano@collabora.com>
parent ea9987f3
No related branches found
No related tags found
2 merge requests!103Backport v2025 <- v2026dev1: ci-license-scan: Add proposed whitelist,!101ci-license-scan: Add proposed whitelist
......@@ -388,6 +388,36 @@ def get_pattern_broadness(pattern):
return pattern.count("*") + pattern.count("?")
def propose_whitelist(license):
reason = None
if license.file.startswith("debian/"):
reason = "# debian metadata is not part of build artifacts\n"
elif license.file.startswith(("doc/", "docs/")):
reason = "# docs are not meant to be installed in target\n"
elif license.file.startswith(("test/", "tests/", "testsuite/")):
reason = "# tests are not meant to be installed in target\n"
elif license.file.startswith(("example/", "examples/")):
reason = "# examples are not meant to be installed in target\n"
elif license.file.startswith("m4/") or license.file.endswith(".m4"):
reason = "# preprocesor files are not meant to be installed in target\n"
elif license.file.startswith(("build/", "build-aux")) or license.file.endswith(
(".am", ".in", ".make")
):
reason = "# build scripts are not meant to be installed in target\n"
else:
reason = "# PLEASE FILL THE REASON TO WHITELIST\n"
if reason:
with open("debian/apertis/copyright.whitelist", "a+") as f:
f.seek(0)
buf = f.read()
data = ""
if len(buf) and buf[-1] != "\n":
data += "\n"
data += reason
data += license.file + "\n"
f.write(data)
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
......@@ -434,6 +464,11 @@ def main():
default=["debian/apertis/copyright.whitelist"],
help="extra file whitelist",
)
parser.add_argument(
"--propose-whitelist",
action="store_true",
help="propose a whitelist in case of failure",
)
args = parser.parse_args()
print("%s fail on change" % ("Will" if args.fail_on_change else "Will not"))
print(
......@@ -599,9 +634,18 @@ def main():
for license in sorted(unknown_licensed):
print(f" UNKNOWN license entry found: {license}", file=sys.stderr)
should_fail = args.fail_on_unknown
if args.propose_whitelist:
propose_whitelist(license)
for license in sorted(bad_licenses):
print(f" Blacklisted license entry found: {license}", file=sys.stderr)
if args.propose_whitelist:
propose_whitelist(license)
should_fail = True
if args.propose_whitelist:
print(
"\nPROPOSED WHITELIST HAVE BEEN ADDED, PLEASE REVIEW THEM!!!\n",
file=sys.stderr,
)
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