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.write_config(self.default_config() + '\nLICENSE:append:pn-bash = " & SomeLicense"')
117        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"
118
119        result = bitbake('core-image-minimal', ignore_status=True)
120        if error_msg not in result.output:
121            raise AssertionError(result.output)
122
123    def test_bash_or_license(self):
124        self.write_config(self.default_config() + '\nLICENSE:append:pn-bash = " | SomeLicense"')
125
126        bitbake('core-image-minimal')
127
128    def test_bash_license_exceptions(self):
129        self.write_config(self.default_config() + '\nINCOMPATIBLE_LICENSE_EXCEPTIONS:pn-core-image-minimal = "bash:GPL-3.0-or-later"')
130
131        bitbake('core-image-minimal')
132
133class NoGPL3InImagesTests(OESelftestTestCase):
134    def test_core_image_minimal(self):
135        self.write_config("""
136INCOMPATIBLE_LICENSE:pn-core-image-minimal = "GPL-3.0* LGPL-3.0*"
137""")
138        bitbake('core-image-minimal')
139
140    def test_core_image_full_cmdline_weston(self):
141        self.write_config("""
142IMAGE_CLASSES += "testimage"
143INCOMPATIBLE_LICENSE:pn-core-image-full-cmdline = "GPL-3.0* LGPL-3.0*"
144INCOMPATIBLE_LICENSE:pn-core-image-weston = "GPL-3.0* LGPL-3.0*"
145# Settings for full-cmdline
146RDEPENDS:packagegroup-core-full-cmdline-utils:remove = "bash bc coreutils cpio ed findutils gawk grep mc mc-fish mc-helpers mc-helpers-perl sed tar time"
147RDEPENDS:packagegroup-core-full-cmdline-dev-utils:remove = "diffutils m4 make patch"
148RDEPENDS:packagegroup-core-full-cmdline-multiuser:remove = "gzip"
149# Settings for weston
150# direct gpl3 dependencies
151RRECOMMENDS:packagegroup-base-vfat:remove = "dosfstools"
152PACKAGECONFIG:remove:pn-bluez5 = "readline"
153# dnf pulls in gpg which is gpl3; it also pulls in python3-rpm which pulls in rpm-build which pulls in bash
154# so install rpm but not dnf
155IMAGE_FEATURES:remove:pn-core-image-weston = "package-management"
156CORE_IMAGE_EXTRA_INSTALL:pn-core-image-weston += "rpm"
157# matchbox-terminal depends on vte, which is gpl3
158CORE_IMAGE_BASE_INSTALL:remove:pn-core-image-weston = "matchbox-terminal"
159""")
160        bitbake('core-image-full-cmdline core-image-weston')
161        bitbake('-c testimage core-image-full-cmdline core-image-weston')
162
163