From 0f4163a12ea431d0ba6265880ee1e557333d3211 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Wed, 3 Aug 2016 16:32:15 +0300 Subject: license: simple verification of LICENSE_ values LICENSE should be a superset of all LICENSE_ values. That is, LICENSE should contain all licenses and LICENSE_ can be used to "filter" this on a per-package basis. LICENSE_ shouldn't contain anything that isn't specified in LICENSE. This patch implements simple checking of LICENSE_ values. It does do not do advanced parsing/matching of license expressions, but, checks that all licenses mentioned in LICENSE_ are also specified in LICENSE. A warning is printed if problems are found. Signed-off-by: Markus Lehtonen Signed-off-by: Ross Burton --- meta/lib/oe/license.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'meta/lib') diff --git a/meta/lib/oe/license.py b/meta/lib/oe/license.py index 39ef9654fc..8d2fd1709c 100644 --- a/meta/lib/oe/license.py +++ b/meta/lib/oe/license.py @@ -215,3 +215,21 @@ def manifest_licenses(licensestr, dont_want_licenses, canonical_license, d): manifest.licensestr = manifest.licensestr.replace('[', '(').replace(']', ')') return (manifest.licensestr, manifest.licenses) + +class ListVisitor(LicenseVisitor): + """Record all different licenses found in the license string""" + def __init__(self): + self.licenses = set() + + def visit_Str(self, node): + self.licenses.add(node.s) + +def list_licenses(licensestr): + """Simply get a list of all licenses mentioned in a license string. + Binary operators are not applied or taken into account in any way""" + visitor = ListVisitor() + try: + visitor.visit_string(licensestr) + except SyntaxError as exc: + raise LicenseSyntaxError(licensestr, exc) + return visitor.licenses -- cgit 1.2.3-korg