xref: /OK3568_Linux_fs/yocto/poky/meta/lib/oeqa/selftest/cases/incompatible_lic.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1from oeqa.selftest.case import OESelftestTestCase
2from oeqa.utils.commands import bitbake
3
4class IncompatibleLicenseTestObsolete(OESelftestTestCase):
5
6    def lic_test(self, pn, pn_lic, lic, error_msg=None):
7        if not error_msg:
8            error_msg = 'ERROR: Nothing PROVIDES \'%s\'\n%s was skipped: it has incompatible license(s): %s' % (pn, pn, pn_lic)
9
10        self.write_config("INCOMPATIBLE_LICENSE += \"%s\"" % (lic))
11
12        result = bitbake('%s --dry-run' % (pn), ignore_status=True)
13        if error_msg not in result.output:
14            raise AssertionError(result.output)
15
16    # Verify that a package with an SPDX license cannot be built when
17    # INCOMPATIBLE_LICENSE contains an alias (in SPDXLICENSEMAP) of this SPDX
18    # license
19    def test_incompatible_alias_spdx_license(self):
20        self.lic_test('incompatible-license', 'GPL-3.0-only', 'GPLv3', "is an obsolete license, please use an SPDX reference in INCOMPATIBLE_LICENSE")
21
22    # Verify that a package with an SPDX license cannot be built when
23    # INCOMPATIBLE_LICENSE contains a wildcarded alias license matching this
24    # SPDX license
25    def test_incompatible_alias_spdx_license_wildcard(self):
26        self.lic_test('incompatible-license', 'GPL-3.0-only', '*GPLv3', "*GPLv3 is an invalid license wildcard entry")
27
28    # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
29    # license cannot be built when INCOMPATIBLE_LICENSE contains this alias
30    def test_incompatible_alias_spdx_license_alias(self):
31        self.lic_test('incompatible-license-alias', 'GPL-3.0-only', 'GPLv3', "is an obsolete license, please use an SPDX reference in INCOMPATIBLE_LICENSE")
32
33    # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
34    # license cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded
35    # license matching this SPDX license
36    def test_incompatible_spdx_license_alias_wildcard(self):
37        self.lic_test('incompatible-license-alias', 'GPL-3.0-only', '*GPL-3.0', "*GPL-3.0 is an invalid license wildcard entry")
38
39    # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
40    # license cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded
41    # alias license matching the SPDX license
42    def test_incompatible_alias_spdx_license_alias_wildcard(self):
43        self.lic_test('incompatible-license-alias', 'GPL-3.0-only', '*GPLv3', "*GPLv3 is an invalid license wildcard entry")
44
45
46    # Verify that a package with multiple SPDX licenses cannot be built when
47    # INCOMPATIBLE_LICENSE contains a wildcard to some of them
48    def test_incompatible_spdx_licenses_wildcard(self):
49        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")
50
51
52    # Verify that a package with multiple SPDX licenses cannot be built when
53    # INCOMPATIBLE_LICENSE contains a wildcard matching all licenses
54    def test_incompatible_all_licenses_wildcard(self):
55        self.lic_test('incompatible-licenses', 'GPL-2.0-only GPL-3.0-only LGPL-3.0-only', '*', "* is an invalid license wildcard entry")
56
57class IncompatibleLicenseTests(OESelftestTestCase):
58
59    def lic_test(self, pn, pn_lic, lic):
60        error_msg = 'ERROR: Nothing PROVIDES \'%s\'\n%s was skipped: it has incompatible license(s): %s' % (pn, pn, pn_lic)
61
62        self.write_config("INCOMPATIBLE_LICENSE += \"%s\"" % (lic))
63
64        result = bitbake('%s --dry-run' % (pn), ignore_status=True)
65        if error_msg not in result.output:
66            raise AssertionError(result.output)
67
68    # Verify that a package with an SPDX license cannot be built when
69    # INCOMPATIBLE_LICENSE contains this SPDX license
70    def test_incompatible_spdx_license(self):
71        self.lic_test('incompatible-license', 'GPL-3.0-only', 'GPL-3.0-only')
72
73    # Verify that a package with an SPDX license cannot be built when
74    # INCOMPATIBLE_LICENSE contains a wildcarded license matching this SPDX
75    # license
76    def test_incompatible_spdx_license_wildcard(self):
77        self.lic_test('incompatible-license', 'GPL-3.0-only', 'GPL-3.0*')
78
79    # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
80    # license cannot be built when INCOMPATIBLE_LICENSE contains this SPDX
81    # license
82    def test_incompatible_spdx_license_alias(self):
83        self.lic_test('incompatible-license-alias', 'GPL-3.0-only', 'GPL-3.0-only')
84
85    # Verify that a package with multiple SPDX licenses cannot be built when
86    # INCOMPATIBLE_LICENSE contains some of them
87    def test_incompatible_spdx_licenses(self):
88        self.lic_test('incompatible-licenses', 'GPL-3.0-only LGPL-3.0-only', 'GPL-3.0-only LGPL-3.0-only')
89
90    # Verify that a package with a non-SPDX license cannot be built when
91    # INCOMPATIBLE_LICENSE contains this license
92    def test_incompatible_nonspdx_license(self):
93        self.lic_test('incompatible-nonspdx-license', 'FooLicense', 'FooLicense')
94
95class IncompatibleLicensePerImageTests(OESelftestTestCase):
96    def default_config(self):
97        return """
98IMAGE_INSTALL:append = " bash"
99INCOMPATIBLE_LICENSE:pn-core-image-minimal = "GPL-3.0* LGPL-3.0*"
100"""
101
102    def test_bash_default(self):
103        self.write_config(self.default_config())
104        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"
105
106        result = bitbake('core-image-minimal', ignore_status=True)
107        if error_msg not in result.output:
108            raise AssertionError(result.output)
109
110    def test_bash_and_license(self):
111        self.write_config(self.default_config() + '\nLICENSE:append:pn-bash = " & SomeLicense"')
112        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"
113
114        result = bitbake('core-image-minimal', ignore_status=True)
115        if error_msg not in result.output:
116            raise AssertionError(result.output)
117
118    def test_bash_or_license(self):
119        self.write_config(self.default_config() + '\nLICENSE:append:pn-bash = " | SomeLicense"')
120
121        bitbake('core-image-minimal')
122
123    def test_bash_license_exceptions(self):
124        self.write_config(self.default_config() + '\nINCOMPATIBLE_LICENSE_EXCEPTIONS:pn-core-image-minimal = "bash:GPL-3.0-or-later"')
125
126        bitbake('core-image-minimal')
127
128class NoGPL3InImagesTests(OESelftestTestCase):
129    def test_core_image_minimal(self):
130        self.write_config("""
131INCOMPATIBLE_LICENSE:pn-core-image-minimal = "GPL-3.0* LGPL-3.0*"
132""")
133        bitbake('core-image-minimal')
134
135    def test_core_image_full_cmdline_weston(self):
136        self.write_config("""
137INHERIT += "testimage"
138INCOMPATIBLE_LICENSE:pn-core-image-full-cmdline = "GPL-3.0* LGPL-3.0*"
139INCOMPATIBLE_LICENSE:pn-core-image-weston = "GPL-3.0* LGPL-3.0*"
140# Settings for full-cmdline
141RDEPENDS: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"
142RDEPENDS:packagegroup-core-full-cmdline-dev-utils:remove = "diffutils m4 make patch"
143RDEPENDS:packagegroup-core-full-cmdline-multiuser:remove = "gzip"
144# Settings for weston
145# direct gpl3 dependencies
146RRECOMMENDS:packagegroup-base-vfat:remove = "dosfstools"
147PACKAGECONFIG:remove:pn-bluez5 = "readline"
148# dnf pulls in gpg which is gpl3; it also pulls in python3-rpm which pulls in rpm-build which pulls in bash
149# so install rpm but not dnf
150IMAGE_FEATURES:remove:pn-core-image-weston = "package-management"
151CORE_IMAGE_EXTRA_INSTALL:pn-core-image-weston += "rpm"
152# matchbox-terminal depends on vte, which is gpl3
153CORE_IMAGE_BASE_INSTALL:remove:pn-core-image-weston = "matchbox-terminal"
154""")
155        bitbake('core-image-full-cmdline core-image-weston')
156        bitbake('-c testimage core-image-full-cmdline core-image-weston')
157
158