From 312b4d6175e189852c0787ca2fe99b99ce92d1bd Mon Sep 17 00:00:00 2001 From: Peter Kjellerstedt Date: Fri, 29 Sep 2017 17:52:34 +0200 Subject: 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 Signed-off-by: Ross Burton --- meta/lib/oeqa/selftest/cases/oelib/license.py | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'meta/lib/oeqa/selftest/cases') diff --git a/meta/lib/oeqa/selftest/cases/oelib/license.py b/meta/lib/oeqa/selftest/cases/oelib/license.py index bfd9ed9c29..d7f91fb2f4 100644 --- a/meta/lib/oeqa/selftest/cases/oelib/license.py +++ b/meta/lib/oeqa/selftest/cases/oelib/license.py @@ -66,3 +66,34 @@ class TestComplexCombinations(TestSimpleCombinations): "(GPL-2.0|Proprietary)&BSD-4-clause&MIT": ["GPL-2.0", "BSD-4-clause", "MIT"], } preferred = ["BAR", "OMEGA", "BETA", "GPL-2.0"] + +class TestIsIncluded(TestCase): + tests = { + ("FOO | BAR", None, None): + [True, ["FOO"]], + ("FOO | BAR", None, "FOO"): + [True, ["BAR"]], + ("FOO | BAR", "BAR", None): + [True, ["BAR"]], + ("FOO | BAR & FOOBAR", "*BAR", None): + [True, ["BAR", "FOOBAR"]], + ("FOO | BAR & FOOBAR", None, "FOO*"): + [False, ["FOOBAR"]], + ("(FOO | BAR) & FOOBAR | BARFOO", None, "FOO"): + [True, ["BAR", "FOOBAR"]], + ("(FOO | BAR) & FOOBAR | BAZ & MOO & BARFOO", None, "FOO"): + [True, ["BAZ", "MOO", "BARFOO"]], + ("GPL-3.0 & GPL-2.0 & LGPL-2.1 | Proprietary", None, None): + [True, ["GPL-3.0", "GPL-2.0", "LGPL-2.1"]], + ("GPL-3.0 & GPL-2.0 & LGPL-2.1 | Proprietary", None, "GPL-3.0"): + [True, ["Proprietary"]], + ("GPL-3.0 & GPL-2.0 & LGPL-2.1 | Proprietary", None, "GPL-3.0 Proprietary"): + [False, ["GPL-3.0"]] + } + + def test_tests(self): + for args, expected in self.tests.items(): + is_included, licenses = oe.license.is_included( + args[0], (args[1] or '').split(), (args[2] or '').split()) + self.assertEqual(is_included, expected[0]) + self.assertListEqual(licenses, expected[1]) -- cgit 1.2.3-korg