incompatible_lic.py 7.4 KB

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