diff mbox series

[2/2] oeqa/selftest/cases/package.py: adding unittest for package rename conflicts

Message ID 20230322164224.100884-2-fawzi.khaber@smile.fr
State Accepted, archived
Commit c3fe173d5196506d89aa464ba56aabcf581a60db
Headers show
Series [1/2] package.bbclass: check packages name conflict in do_package | expand

Commit Message

Fawzi KHABER March 22, 2023, 4:42 p.m. UTC
This Unittest tries to rename a package, using an already used name and
fails on do_package.

Reviewed-by: Yoann CONGAL <yoann.congal@smile.fr>
Signed-off-by: Fawzi KHABER <fawzi.khaber@smile.fr>
---
 .../packagenameconflict/packagenameconflict.bb            | 8 ++++++++
 meta/classes-global/package.bbclass                       | 3 +--
 meta/lib/oeqa/selftest/cases/package.py                   | 7 +++++++
 3 files changed, 16 insertions(+), 2 deletions(-)
 create mode 100644 meta-selftest/recipes-test/packagenameconflict/packagenameconflict.bb
diff mbox series

Patch

diff --git a/meta-selftest/recipes-test/packagenameconflict/packagenameconflict.bb b/meta-selftest/recipes-test/packagenameconflict/packagenameconflict.bb
new file mode 100644
index 0000000000..291d37c5f6
--- /dev/null
+++ b/meta-selftest/recipes-test/packagenameconflict/packagenameconflict.bb
@@ -0,0 +1,8 @@ 
+SUMMARY = "Test case that tries to rename a package to an existing one and fails"
+DESCRIPTION = "This generates a packaging error when a package is renamed to a pre-existing name"
+LICENSE = "MIT"
+
+# Add a new package ${PN}-renametest
+PACKAGES += "${PN}-renametest"
+# ... and try to rename the ${PN}-dev to the new ${PN}-renametest (conflict)
+PKG:${PN}-dev = "${PN}-renametest"
diff --git a/meta/classes-global/package.bbclass b/meta/classes-global/package.bbclass
index 30dfd63d4f..21461ff314 100644
--- a/meta/classes-global/package.bbclass
+++ b/meta/classes-global/package.bbclass
@@ -498,13 +498,12 @@  python do_package () {
 
     # Check for conflict between renamed packages and existing ones
     # for each package in PACKAGES, check if it will be renamed to an existing one
-
     for p in packages:
         localdata = bb.data.createCopy(d)
         localdata.setVar('OVERRIDES', p)
         rename = localdata.getVar('PKG')
         if (rename != None) and rename in packages:         
-            bb.fatal('package %s is renamed %s using PKG:%s, but package name already exists'%(p,rename,p))
+            bb.fatal('package "%s" is renamed to "%s" using PKG:%s, but package name already exists'%(p,rename,p))
 
     ###########################################################################
     # Optimisations
diff --git a/meta/lib/oeqa/selftest/cases/package.py b/meta/lib/oeqa/selftest/cases/package.py
index 4f7cd10658..1aa6c03f8a 100644
--- a/meta/lib/oeqa/selftest/cases/package.py
+++ b/meta/lib/oeqa/selftest/cases/package.py
@@ -89,6 +89,13 @@  class VersionOrdering(OESelftestTestCase):
             self.assertEqual(status - 100, sort, "%s %s (%d) failed" % (ver1, ver2, sort))
 
 class PackageTests(OESelftestTestCase):
+    # Verify that a recipe cannot rename a package into an existing one
+    def test_package_name_conflict(self):
+        res = bitbake("packagenameconflict", ignore_status=True)
+        self.assertNotEqual(res.status, 0)
+        err = "package name already exists"
+        self.assertTrue(err in res.output)
+
     # Verify that a recipe which sets up hardlink files has those preserved into split packages
     # Also test file sparseness is preserved
     def test_preserve_sparse_hardlinks(self):