diff options
author | Peter Kjellerstedt <peter.kjellerstedt@axis.com> | 2017-09-29 17:52:34 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-10-06 12:03:33 +0100 |
commit | 312b4d6175e189852c0787ca2fe99b99ce92d1bd (patch) | |
tree | 74f244d7966571ba173fdc0a0d47ddeaf9af963b /meta/lib/oe | |
parent | 50cfc0d7118c747726445a9be7bc4c496dbb8248 (diff) | |
download | openembedded-core-contrib-312b4d6175e189852c0787ca2fe99b99ce92d1bd.tar.gz |
license.py: Correct selection of licenses in is_included()
When faced with multiple sets of licenses combined with | (OR), it was
possible for oe.license.is_included() to choose a set of licenses with
a blacklisted license and then report failure, even if choosing
another set of licenses would have resulted in a successful
result. This happened when the chosen set still contained more
whitelisted licenses than the other set.
This change makes sure a set with any blacklisted license is always
considered with a lower weight than a set with only whitelisted
licenses.
Example: Faced with the license string "GPL-3.0 & GPL-2.0 & LGPL-2.1 |
Proprietary" and with "GPL-3.0" being blacklisted, the old code would
report a failure since "GPL-3.0 & GPL-2.0 & LGPL-2.1" still contains
more whitelisted licenses than "Proprietary" does.
This change also adds a unit test for oe.license.is_included().
Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Diffstat (limited to 'meta/lib/oe')
-rw-r--r-- | meta/lib/oe/license.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/meta/lib/oe/license.py b/meta/lib/oe/license.py index 8d2fd1709c..ca385d5187 100644 --- a/meta/lib/oe/license.py +++ b/meta/lib/oe/license.py @@ -106,7 +106,8 @@ def is_included(licensestr, whitelist=None, blacklist=None): license string matches the whitelist and does not match the blacklist. Returns a tuple holding the boolean state and a list of the applicable - licenses which were excluded (or None, if the state is True) + licenses that were excluded if state is False, or the licenses that were + included if the state is True. """ def include_license(license): @@ -117,10 +118,17 @@ def is_included(licensestr, whitelist=None, blacklist=None): def choose_licenses(alpha, beta): """Select the option in an OR which is the 'best' (has the most - included licenses).""" - alpha_weight = len(list(filter(include_license, alpha))) - beta_weight = len(list(filter(include_license, beta))) - if alpha_weight > beta_weight: + included licenses and no excluded licenses).""" + # The factor 1000 below is arbitrary, just expected to be much larger + # that the number of licenses actually specified. That way the weight + # will be negative if the list of licenses contains an excluded license, + # but still gives a higher weight to the list with the most included + # licenses. + alpha_weight = (len(list(filter(include_license, alpha))) - + 1000 * (len(list(filter(exclude_license, alpha))) > 0)) + beta_weight = (len(list(filter(include_license, beta))) - + 1000 * (len(list(filter(exclude_license, beta))) > 0)) + if alpha_weight >= beta_weight: return alpha else: return beta |