diff mbox series

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

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

Commit Message

Fawzi KHABER March 23, 2023, 9:56 a.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         | 10 ++++++++++
 meta/classes-global/package.bbclass                    |  3 +--
 meta/lib/oeqa/selftest/cases/package.py                |  7 +++++++
 3 files changed, 18 insertions(+), 2 deletions(-)
 create mode 100644 meta-selftest/recipes-test/packagenameconflict/packagenameconflict.bb

Comments

Yoann Congal March 27, 2023, 9:53 p.m. UTC | #1
Hi Fawzi and list,

While looking at master-next, I found some mistakes in this series.
@maintainers, maybe wait for the v3 before merging into master?

Sorry for this, my internal review was not thorough enough :(

@Fawzi, please see the inline comments :
On 3/23/23 10:56, Fawzi KHABER wrote:
> 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         | 10 ++++++++++
>  meta/classes-global/package.bbclass                    |  3 +--
>  meta/lib/oeqa/selftest/cases/package.py                |  7 +++++++
>  3 files changed, 18 insertions(+), 2 deletions(-)
>  create mode 100644 meta-selftest/recipes-test/packagenameconflict/packagenameconflict.bb
> 
> diff --git a/meta-selftest/recipes-test/packagenameconflict/packagenameconflict.bb b/meta-selftest/recipes-test/packagenameconflict/packagenameconflict.bb
> new file mode 100644
> index 0000000000..5d19a4dd25
> --- /dev/null
> +++ b/meta-selftest/recipes-test/packagenameconflict/packagenameconflict.bb
> @@ -0,0 +1,10 @@
> +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"
> +
> +EXCLUDE_FROM_WORLD = "1"
> 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
> -
This line ...
>      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))
... and this line should be squashed with the patch 1/2 instead of the 2/2 of your series.

>
>      ###########################################################################
>      # 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):

Regards,
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..5d19a4dd25
--- /dev/null
+++ b/meta-selftest/recipes-test/packagenameconflict/packagenameconflict.bb
@@ -0,0 +1,10 @@ 
+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"
+
+EXCLUDE_FROM_WORLD = "1"
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):