1from oeqa.selftest.case import OESelftestTestCase
2from oeqa.utils.commands import bitbake
3
4class IncompatibleLicenseTests(OESelftestTestCase):
5
6    def lic_test(self, pn, pn_lic, lic):
7        error_msg = 'ERROR: Nothing PROVIDES \'%s\'\n%s was skipped: it has incompatible license(s): %s' % (pn, pn, pn_lic)
8
9        self.write_config("INCOMPATIBLE_LICENSE += \"%s\"" % (lic))
10
11        result = bitbake('%s --dry-run' % (pn), ignore_status=True)
12        if error_msg not in result.output:
13            raise AssertionError(result.output)
14
15    # Verify that a package with an SPDX license (from AVAILABLE_LICENSES)
16    # cannot be built when INCOMPATIBLE_LICENSE contains this SPDX license
17    def test_incompatible_spdx_license(self):
18        self.lic_test('incompatible-license', 'GPL-3.0', 'GPL-3.0')
19
20    # Verify that a package with an SPDX license (from AVAILABLE_LICENSES)
21    # cannot be built when INCOMPATIBLE_LICENSE contains an alias (in
22    # SPDXLICENSEMAP) of this SPDX license
23    def test_incompatible_alias_spdx_license(self):
24        self.lic_test('incompatible-license', 'GPL-3.0', 'GPLv3')
25
26    # Verify that a package with an SPDX license (from AVAILABLE_LICENSES)
27    # cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded license
28    # matching this SPDX license
29    def test_incompatible_spdx_license_wildcard(self):
30        self.lic_test('incompatible-license', 'GPL-3.0', '*GPL-3.0')
31
32    # Verify that a package with an SPDX license (from AVAILABLE_LICENSES)
33    # cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded alias
34    # license matching this SPDX license
35    def test_incompatible_alias_spdx_license_wildcard(self):
36        self.lic_test('incompatible-license', 'GPL-3.0', '*GPLv3')
37
38    # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
39    # license cannot be built when INCOMPATIBLE_LICENSE contains this SPDX
40    # license
41    def test_incompatible_spdx_license_alias(self):
42        self.lic_test('incompatible-license-alias', 'GPL-3.0', 'GPL-3.0')
43
44    # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
45    # license cannot be built when INCOMPATIBLE_LICENSE contains this alias
46    def test_incompatible_alias_spdx_license_alias(self):
47        self.lic_test('incompatible-license-alias', 'GPL-3.0', 'GPLv3')
48
49    # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
50    # license cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded
51    # license matching this SPDX license
52    def test_incompatible_spdx_license_alias_wildcard(self):
53        self.lic_test('incompatible-license-alias', 'GPL-3.0', '*GPL-3.0')
54
55    # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
56    # license cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded
57    # alias license matching the SPDX license
58    def test_incompatible_alias_spdx_license_alias_wildcard(self):
59        self.lic_test('incompatible-license-alias', 'GPL-3.0', '*GPLv3')
60
61    # Verify that a package with multiple SPDX licenses (from
62    # AVAILABLE_LICENSES) cannot be built when INCOMPATIBLE_LICENSE contains
63    # some of them
64    def test_incompatible_spdx_licenses(self):
65        self.lic_test('incompatible-licenses', 'GPL-3.0 LGPL-3.0', 'GPL-3.0 LGPL-3.0')
66
67    # Verify that a package with multiple SPDX licenses (from
68    # AVAILABLE_LICENSES) cannot be built when INCOMPATIBLE_LICENSE contains a
69    # wildcard to some of them
70    def test_incompatible_spdx_licenses_wildcard(self):
71        self.lic_test('incompatible-licenses', 'GPL-3.0 LGPL-3.0', '*GPL-3.0')
72
73    # Verify that a package with multiple SPDX licenses (from
74    # AVAILABLE_LICENSES) cannot be built when INCOMPATIBLE_LICENSE contains a
75    # wildcard matching all licenses
76    def test_incompatible_all_licenses_wildcard(self):
77        self.lic_test('incompatible-licenses', 'GPL-2.0 GPL-3.0 LGPL-3.0', '*')
78
79    # Verify that a package with a non-SPDX license (neither in
80    # AVAILABLE_LICENSES nor in SPDXLICENSEMAP) cannot be built when
81    # INCOMPATIBLE_LICENSE contains this license
82    def test_incompatible_nonspdx_license(self):
83        self.lic_test('incompatible-nonspdx-license', 'FooLicense', 'FooLicense')
84
85class IncompatibleLicensePerImageTests(OESelftestTestCase):
86    def default_config(self):
87        return """
88IMAGE_INSTALL_append = " bash"
89INCOMPATIBLE_LICENSE_pn-core-image-minimal = "GPL-3.0 LGPL-3.0"
90"""
91
92    def test_bash_default(self):
93        self.write_config(self.default_config())
94        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+"
95
96        result = bitbake('core-image-minimal', ignore_status=True)
97        if error_msg not in result.output:
98            raise AssertionError(result.output)
99
100    def test_bash_and_license(self):
101        self.write_config(self.default_config() + '\nLICENSE_append_pn-bash = " & SomeLicense"')
102        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+"
103
104        result = bitbake('core-image-minimal', ignore_status=True)
105        if error_msg not in result.output:
106            raise AssertionError(result.output)
107
108    def test_bash_or_license(self):
109        self.write_config(self.default_config() + '\nLICENSE_append_pn-bash = " | SomeLicense"')
110
111        bitbake('core-image-minimal')
112
113    def test_bash_whitelist(self):
114        self.write_config(self.default_config() + '\nWHITELIST_GPL-3.0_pn-core-image-minimal = "bash"')
115
116        bitbake('core-image-minimal')
117
118class NoGPL3InImagesTests(OESelftestTestCase):
119    def test_core_image_minimal(self):
120        self.write_config("""
121INCOMPATIBLE_LICENSE_pn-core-image-minimal = "GPL-3.0 LGPL-3.0"
122""")
123        bitbake('core-image-minimal')
124
125    def test_core_image_full_cmdline(self):
126        self.write_config("""
127INHERIT += "testimage"\n
128INCOMPATIBLE_LICENSE_pn-core-image-full-cmdline = "GPL-3.0 LGPL-3.0"\n
129RDEPENDS_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"\n
130RDEPENDS_packagegroup-core-full-cmdline-dev-utils_remove = "diffutils m4 make patch"\n
131RDEPENDS_packagegroup-core-full-cmdline-multiuser_remove = "gzip"\n
132""")
133        bitbake('core-image-full-cmdline')
134        bitbake('-c testimage core-image-full-cmdline')
135
136