blob: 4edf60fc55f7631c714b2d4ba773ed1e59edc0e1 [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
Brad Bishop15ae2502019-06-18 21:44:24 -04006from oeqa.selftest.case import OESelftestTestCase
7from oeqa.utils.commands import bitbake
8
Andrew Geissler9aee5002022-03-30 16:27:02 +00009class 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
Brad Bishop15ae2502019-06-18 21:44:24 -040062class IncompatibleLicenseTests(OESelftestTestCase):
63
64 def lic_test(self, pn, pn_lic, lic):
Andrew Geissler82c905d2020-04-13 13:39:40 -050065 error_msg = 'ERROR: Nothing PROVIDES \'%s\'\n%s was skipped: it has incompatible license(s): %s' % (pn, pn, pn_lic)
Brad Bishop15ae2502019-06-18 21:44:24 -040066
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
Andrew Geissler9aee5002022-03-30 16:27:02 +000073 # Verify that a package with an SPDX license cannot be built when
74 # INCOMPATIBLE_LICENSE contains this SPDX license
Brad Bishop15ae2502019-06-18 21:44:24 -040075 def test_incompatible_spdx_license(self):
Andrew Geissler90fd73c2021-03-05 15:25:55 -060076 self.lic_test('incompatible-license', 'GPL-3.0-only', 'GPL-3.0-only')
Brad Bishop15ae2502019-06-18 21:44:24 -040077
Andrew Geissler9aee5002022-03-30 16:27:02 +000078 # Verify that a package with an SPDX license cannot be built when
79 # INCOMPATIBLE_LICENSE contains a wildcarded license matching this SPDX
80 # license
Andrew Geissler82c905d2020-04-13 13:39:40 -050081 def test_incompatible_spdx_license_wildcard(self):
Andrew Geissler9aee5002022-03-30 16:27:02 +000082 self.lic_test('incompatible-license', 'GPL-3.0-only', 'GPL-3.0*')
Andrew Geissler82c905d2020-04-13 13:39:40 -050083
Brad Bishop15ae2502019-06-18 21:44:24 -040084 # 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):
Andrew Geissler90fd73c2021-03-05 15:25:55 -060088 self.lic_test('incompatible-license-alias', 'GPL-3.0-only', 'GPL-3.0-only')
Brad Bishop15ae2502019-06-18 21:44:24 -040089
Andrew Geissler9aee5002022-03-30 16:27:02 +000090 # Verify that a package with multiple SPDX licenses cannot be built when
91 # INCOMPATIBLE_LICENSE contains some of them
Andrew Geissler82c905d2020-04-13 13:39:40 -050092 def test_incompatible_spdx_licenses(self):
Andrew Geissler90fd73c2021-03-05 15:25:55 -060093 self.lic_test('incompatible-licenses', 'GPL-3.0-only LGPL-3.0-only', 'GPL-3.0-only LGPL-3.0-only')
Andrew Geissler82c905d2020-04-13 13:39:40 -050094
Andrew Geissler9aee5002022-03-30 16:27:02 +000095 # Verify that a package with a non-SPDX license cannot be built when
Brad Bishop15ae2502019-06-18 21:44:24 -040096 # INCOMPATIBLE_LICENSE contains this license
97 def test_incompatible_nonspdx_license(self):
98 self.lic_test('incompatible-nonspdx-license', 'FooLicense', 'FooLicense')
Brad Bishopf3f93bb2019-10-16 14:33:32 -040099
100class IncompatibleLicensePerImageTests(OESelftestTestCase):
101 def default_config(self):
102 return """
Patrick Williams213cb262021-08-07 19:21:33 -0500103IMAGE_INSTALL:append = " bash"
Andrew Geissler9aee5002022-03-30 16:27:02 +0000104INCOMPATIBLE_LICENSE:pn-core-image-minimal = "GPL-3.0* LGPL-3.0*"
Brad Bishopf3f93bb2019-10-16 14:33:32 -0400105"""
106
107 def test_bash_default(self):
108 self.write_config(self.default_config())
Andrew Geissler90fd73c2021-03-05 15:25:55 -0600109 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"
Brad Bishopf3f93bb2019-10-16 14:33:32 -0400110
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):
Patrick Williams213cb262021-08-07 19:21:33 -0500116 self.write_config(self.default_config() + '\nLICENSE:append:pn-bash = " & SomeLicense"')
Andrew Geissler90fd73c2021-03-05 15:25:55 -0600117 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"
Brad Bishopf3f93bb2019-10-16 14:33:32 -0400118
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):
Patrick Williams213cb262021-08-07 19:21:33 -0500124 self.write_config(self.default_config() + '\nLICENSE:append:pn-bash = " | SomeLicense"')
Brad Bishopf3f93bb2019-10-16 14:33:32 -0400125
126 bitbake('core-image-minimal')
127
Andrew Geissler9aee5002022-03-30 16:27:02 +0000128 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"')
Brad Bishopf3f93bb2019-10-16 14:33:32 -0400130
131 bitbake('core-image-minimal')
132
Brad Bishop64c979e2019-11-04 13:55:29 -0500133class NoGPL3InImagesTests(OESelftestTestCase):
134 def test_core_image_minimal(self):
135 self.write_config("""
Andrew Geissler9aee5002022-03-30 16:27:02 +0000136INCOMPATIBLE_LICENSE:pn-core-image-minimal = "GPL-3.0* LGPL-3.0*"
Brad Bishop64c979e2019-11-04 13:55:29 -0500137""")
138 bitbake('core-image-minimal')
139
Patrick Williams213cb262021-08-07 19:21:33 -0500140 def test_core_image_full_cmdline_weston(self):
Brad Bishop64c979e2019-11-04 13:55:29 -0500141 self.write_config("""
Patrick Williams92b42cb2022-09-03 06:53:57 -0500142IMAGE_CLASSES += "testimage"
Andrew Geissler9aee5002022-03-30 16:27:02 +0000143INCOMPATIBLE_LICENSE:pn-core-image-full-cmdline = "GPL-3.0* LGPL-3.0*"
144INCOMPATIBLE_LICENSE:pn-core-image-weston = "GPL-3.0* LGPL-3.0*"
Patrick Williams213cb262021-08-07 19:21:33 -0500145# 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"
Brad Bishop64c979e2019-11-04 13:55:29 -0500159""")
Patrick Williams213cb262021-08-07 19:21:33 -0500160 bitbake('core-image-full-cmdline core-image-weston')
161 bitbake('-c testimage core-image-full-cmdline core-image-weston')
Brad Bishop64c979e2019-11-04 13:55:29 -0500162