From 2bac485c4bf65d997b2e0cb6175be121a49cf938 Mon Sep 17 00:00:00 2001 From: Walter Lozano <walter.lozano@collabora.com> Date: Thu, 16 Jan 2025 17:30:45 -0300 Subject: [PATCH] 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: Walter Lozano <walter.lozano@collabora.com> --- tools/ci-license-scan | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tools/ci-license-scan b/tools/ci-license-scan index 29b9250..453ecd5 100755 --- a/tools/ci-license-scan +++ b/tools/ci-license-scan @@ -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) -- GitLab