1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6from oeqa.selftest.case import OESelftestTestCase
7from oeqa.utils.commands import bitbake
8
9class IncompatibleLicenseTestObsolete(OESelftestTestCase):
10
11    def lic_test(self, pn, pn_lic, lic, error_msg=None):
12        if not error_msg:
13            error_msg = 'ERROR: Nothing PROVIDES \'%s\'\n%s was skipped: it has incompatible license(s): %s' % (pn, pn, pn_lic)
14
15        self.write_config("INCOMPATIBLE_LICENSE += \"%s\"" % (lic))
16
17        result = bitbake('%s --dry-run' % (pn), ignore_status=True)
18        if error_msg not in result.output:
19            raise AssertionError(result.output)
20
21    # Verify that a package with an SPDX license cannot be built when
22    # INCOMPATIBLE_LICENSE contains an alias (in SPDXLICENSEMAP) of this SPDX
23    # license
24    def test_incompatible_alias_spdx_license(self):
25        self.lic_test('incompatible-license', 'GPL-3.0-only', 'GPLv3', "is an obsolete license, please use an SPDX reference in INCOMPATIBLE_LICENSE")
26
27    # Verify that a package with an SPDX license cannot be built when
28    # INCOMPATIBLE_LICENSE contains a wildcarded alias license matching this
29    # SPDX license
30    def test_incompatible_alias_spdx_license_wildcard(self):
31        self.lic_test('incompatible-license', 'GPL-3.0-only', '*GPLv3', "*GPLv3 is an invalid license wildcard entry")
32
33    # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
34    # license cannot be built when INCOMPATIBLE_LICENSE contains this alias
35    def test_incompatible_alias_spdx_license_alias(self):
36        self.lic_test('incompatible-license-alias', 'GPL-3.0-only', 'GPLv3', "is an obsolete license, please use an SPDX reference in INCOMPATIBLE_LICENSE")
37
38    # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
39    # license cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded
40    # license matching this SPDX license
41    def test_incompatible_spdx_license_alias_wildcard(self):
42        self.lic_test('incompatible-license-alias', 'GPL-3.0-only', '*GPL-3.0', "*GPL-3.0 is an invalid license wildcard entry")
43
44    # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
45    # license cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded
46    # alias license matching the SPDX license
47    def test_incompatible_alias_spdx_license_alias_wildcard(self):
48        self.lic_test('incompatible-license-alias', 'GPL-3.0-only', '*GPLv3', "*GPLv3 is an invalid license wildcard entry")
49
50
51    # Verify that a package with multiple SPDX licenses cannot be built when
52    # INCOMPATIBLE_LICENSE contains a wildcard to some of them
53    def test_incompatible_spdx_licenses_wildcard(self):
54        self.lic_test('incompatible-licenses', 'GPL-3.0-only LGPL-3.0-only', '*GPL-3.0-only', "*GPL-3.0-only is an invalid license wildcard entry")
55
56
57    # Verify that a package with multiple SPDX licenses cannot be built when
58    # INCOMPATIBLE_LICENSE contains a wildcard matching all licenses
59    def test_incompatible_all_licenses_wildcard(self):
60        self.lic_test('incompatible-licenses', 'GPL-2.0-only GPL-3.0-only LGPL-3.0-only', '*', "* is an invalid license wildcard entry")
61
62class IncompatibleLicenseTests(OESelftestTestCase):
63
64    def lic_test(self, pn, pn_lic, lic):
65        error_msg = 'ERROR: Nothing PROVIDES \'%s\'\n%s was skipped: it has incompatible license(s): %s' % (pn, pn, pn_lic)
66
67        self.write_config("INCOMPATIBLE_LICENSE += \"%s\"" % (lic))
68
69        result = bitbake('%s --dry-run' % (pn), ignore_status=True)
70        if error_msg not in result.output:
71            raise AssertionError(result.output)
72
73    # Verify that a package with an SPDX license cannot be built when
74    # INCOMPATIBLE_LICENSE contains this SPDX license
75    def test_incompatible_spdx_license(self):
76        self.lic_test('incompatible-license', 'GPL-3.0-only', 'GPL-3.0-only')
77
78    # Verify that a package with an SPDX license cannot be built when
79    # INCOMPATIBLE_LICENSE contains a wildcarded license matching this SPDX
80    # license
81    def test_incompatible_spdx_license_wildcard(self):
82        self.lic_test('incompatible-license', 'GPL-3.0-only', 'GPL-3.0*')
83
84    # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
85    # license cannot be built when INCOMPATIBLE_LICENSE contains this SPDX
86    # license
87    def test_incompatible_spdx_license_alias(self):
88        self.lic_test('incompatible-license-alias', 'GPL-3.0-only', 'GPL-3.0-only')
89
90    # Verify that a package with multiple SPDX licenses cannot be built when
91    # INCOMPATIBLE_LICENSE contains some of them
92    def test_incompatible_spdx_licenses(self):
93        self.lic_test('incompatible-licenses', 'GPL-3.0-only LGPL-3.0-only', 'GPL-3.0-only LGPL-3.0-only')
94
95    # Verify that a package with a non-SPDX license cannot be built when
96    # INCOMPATIBLE_LICENSE contains this license
97    def test_incompatible_nonspdx_license(self):
98        self.lic_test('incompatible-nonspdx-license', 'FooLicense', 'FooLicense')
99
100class IncompatibleLicensePerImageTests(OESelftestTestCase):
101    def default_config(self):
102        return """
103IMAGE_INSTALL:append = " bash"
104INCOMPATIBLE_LICENSE:pn-core-image-minimal = "GPL-3.0* LGPL-3.0*"
105"""
106
107    def test_bash_default(self):
108        self.write_config(self.default_config())
109        error_msg = "ERROR: core-image-minimal-1.0-r0 do_rootfs: Package bash cannot be installed into the image because it has incompatible license(s): GPL-3.0-or-later"
110
111        result = bitbake('core-image-minimal', ignore_status=True)
112        if error_msg not in result.output:
113            raise AssertionError(result.output)
114
115    def test_bash_and_license(self):
116        self.disable_class("create-spdx")
117        self.write_config(self.default_config() + '\nLICENSE:append:pn-bash = " & SomeLicense"')
118        error_msg = "ERROR: core-image-minimal-1.0-r0 do_rootfs: Package bash cannot be installed into the image because it has incompatible license(s): GPL-3.0-or-later"
119
120        result = bitbake('core-image-minimal', ignore_status=True)
121        if error_msg not in result.output:
122            raise AssertionError(result.output)
123
124    def test_bash_or_license(self):
125        self.disable_class("create-spdx")
126        self.write_config(self.default_config() + '\nLICENSE:append:pn-bash = " | SomeLicense"')
127
128        bitbake('core-image-minimal')
129
130    def test_bash_license_exceptions(self):
131        self.write_config(self.default_config() + '\nINCOMPATIBLE_LICENSE_EXCEPTIONS:pn-core-image-minimal = "bash:GPL-3.0-or-later"')
132
133        bitbake('core-image-minimal')
134
135class NoGPL3InImagesTests(OESelftestTestCase):
136    def test_core_image_minimal(self):
137        self.write_config("""
138INCOMPATIBLE_LICENSE:pn-core-image-minimal = "GPL-3.0* LGPL-3.0*"
139""")
140        bitbake('core-image-minimal')
141
142    def test_core_image_full_cmdline_weston(self):
143        self.write_config("""
144IMAGE_CLASSES += "testimage"
145INCOMPATIBLE_LICENSE:pn-core-image-full-cmdline = "GPL-3.0* LGPL-3.0*"
146INCOMPATIBLE_LICENSE:pn-core-image-weston = "GPL-3.0* LGPL-3.0*"
147
148require conf/distro/include/no-gplv3.inc
149""")
150        bitbake('core-image-full-cmdline core-image-weston')
151        bitbake('-c testimage core-image-full-cmdline core-image-weston')
152
153