[bitbake-devel,1.40] bitbake: fix version comparison when one of the versions ends in .

Submitted by Martin Jansa on June 15, 2019, 7:17 a.m. | Patch ID: 162225

Details

Message ID 20190615071743.9494-1-Martin.Jansa@gmail.com
State New
Headers show

Commit Message

Martin Jansa June 15, 2019, 7:17 a.m.
From: Alexander Kanavin <alex.kanavin@gmail.com>

Previously, this would happen:

Patch hide | download patch | download mbox

======================================================================
ERROR: test_vercmpstring (bb.tests.utils.VerCmpString)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/alexander/development/poky/bitbake/lib/bb/tests/utils.py", line 45, in test_vercmpstring
    result = bb.utils.vercmp_string('1.', '1.1')
  File "/home/alexander/development/poky/bitbake/lib/bb/utils.py", line 143, in vercmp_string
    return vercmp(ta, tb)
  File "/home/alexander/development/poky/bitbake/lib/bb/utils.py", line 135, in vercmp
    r = vercmp_part(va, vb)
  File "/home/alexander/development/poky/bitbake/lib/bb/utils.py", line 124, in vercmp_part
    elif ca < cb:
TypeError: '<' not supported between instances of 'NoneType' and 'int'

----------------------------------------------------------------------

Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/tests/utils.py | 4 ++++
 lib/bb/utils.py       | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/lib/bb/tests/utils.py b/lib/bb/tests/utils.py
index 2f4ccf3c..f1cd83a4 100644
--- a/lib/bb/tests/utils.py
+++ b/lib/bb/tests/utils.py
@@ -42,6 +42,10 @@  class VerCmpString(unittest.TestCase):
         self.assertTrue(result < 0)
         result = bb.utils.vercmp_string('1.1', '1.0+1.1-beta1')
         self.assertTrue(result > 0)
+        result = bb.utils.vercmp_string('1.', '1.1')
+        self.assertTrue(result < 0)
+        result = bb.utils.vercmp_string('1.1', '1.')
+        self.assertTrue(result > 0)
 
     def test_explode_dep_versions(self):
         correctresult = {"foo" : ["= 1.10"]}
diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 73b6cb42..215c18cf 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -120,6 +120,10 @@  def vercmp_part(a, b):
             return -1
         elif oa > ob:
             return 1
+        elif ca is None:
+            return -1
+        elif cb is None:
+            return 1
         elif ca < cb:
             return -1
         elif ca > cb:

Comments

Martin Jansa June 15, 2019, 7:24 a.m.
On Sat, Jun 15, 2019 at 07:17:43AM +0000, Martin Jansa wrote:
> From: Alexander Kanavin <alex.kanavin@gmail.com>
> 
> Previously, this would happen:
> 
> ======================================================================
> ERROR: test_vercmpstring (bb.tests.utils.VerCmpString)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "/home/alexander/development/poky/bitbake/lib/bb/tests/utils.py", line 45, in test_vercmpstring
>     result = bb.utils.vercmp_string('1.', '1.1')
>   File "/home/alexander/development/poky/bitbake/lib/bb/utils.py", line 143, in vercmp_string
>     return vercmp(ta, tb)
>   File "/home/alexander/development/poky/bitbake/lib/bb/utils.py", line 135, in vercmp
>     r = vercmp_part(va, vb)
>   File "/home/alexander/development/poky/bitbake/lib/bb/utils.py", line 124, in vercmp_part
>     elif ca < cb:
> TypeError: '<' not supported between instances of 'NoneType' and 'int'

I was seeing the same error on versions not ending with '.', in my case:
bb.utils.vercmp((0,1.0.2r,r0.0webos22), (0,1.0.2r0webos19,r0.0webos21)

Which lead to do_packagedata failure through buildhistory_emit_pkghistory shown bellow.

Alex's fix works for the above versions as well, should I extend
the bb.utils.vercmp selftest with even weirder versions like we're using
or leave it as is?

The stack trace of python calls that resulted in this exception/failure was:
File: 'exec_python_func() autogenerated', lineno: 2, function: <module>
     0001:
 *** 0002:buildhistory_emit_pkghistory(d)
     0003:
File: 'oe-core/meta/classes/buildhistory.bbclass', lineno: 263, function: buildhistory_emit_pkghistory
     0259:            last_pkge = lastversion.pkge
     0260:            last_pkgv = lastversion.pkgv
     0261:            last_pkgr = lastversion.pkgr
     0262:            bb.warn("bb.utils.vercmp((%s,%s,%s), (%s,%s,%s)" % (pkge, pkgv, pkgr, last_pkge, last_pkgv, last_pkgr))
 *** 0263:            r = bb.utils.vercmp((pkge, pkgv, pkgr), (last_pkge, last_pkgv, last_pkgr))
     0264:            if r < 0:
     0265:                msg = "Package version for package %s went backwards which would break package feeds from (%s:%s-%s to %s:%s-%s)" % (pkg, last_pkge, last_pkgv, last_pkgr, pkge, pkgv, pkgr)
     0266:                package_qa_handle_error("version-going-backwards", msg, d)
     0267:
File: 'bitbake/lib/bb/utils.py', lineno: 134, function: vercmp
     0130:    (eb, vb, rb) = tb
     0131:
     0132:    r = int(ea or 0) - int(eb or 0)
     0133:    if (r == 0):
 *** 0134:        r = vercmp_part(va, vb)
     0135:    if (r == 0):
     0136:        r = vercmp_part(ra, rb)
     0137:    return r
     0138:
File: 'bitbake/lib/bb/utils.py', lineno: 123, function: vercmp_part
     0119:        if oa < ob:
     0120:            return -1
     0121:        elif oa > ob:
     0122:            return 1
 *** 0123:        elif ca < cb:
     0124:            return -1
     0125:        elif ca > cb:
     0126:            return 1
     0127:
Exception: TypeError: '<' not supported between instances of 'NoneType' and 'int'

> 
> ----------------------------------------------------------------------
> 
> Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> ---
>  lib/bb/tests/utils.py | 4 ++++
>  lib/bb/utils.py       | 4 ++++
>  2 files changed, 8 insertions(+)
> 
> diff --git a/lib/bb/tests/utils.py b/lib/bb/tests/utils.py
> index 2f4ccf3c..f1cd83a4 100644
> --- a/lib/bb/tests/utils.py
> +++ b/lib/bb/tests/utils.py
> @@ -42,6 +42,10 @@ class VerCmpString(unittest.TestCase):
>          self.assertTrue(result < 0)
>          result = bb.utils.vercmp_string('1.1', '1.0+1.1-beta1')
>          self.assertTrue(result > 0)
> +        result = bb.utils.vercmp_string('1.', '1.1')
> +        self.assertTrue(result < 0)
> +        result = bb.utils.vercmp_string('1.1', '1.')
> +        self.assertTrue(result > 0)
>  
>      def test_explode_dep_versions(self):
>          correctresult = {"foo" : ["= 1.10"]}
> diff --git a/lib/bb/utils.py b/lib/bb/utils.py
> index 73b6cb42..215c18cf 100644
> --- a/lib/bb/utils.py
> +++ b/lib/bb/utils.py
> @@ -120,6 +120,10 @@ def vercmp_part(a, b):
>              return -1
>          elif oa > ob:
>              return 1
> +        elif ca is None:
> +            return -1
> +        elif cb is None:
> +            return 1
>          elif ca < cb:
>              return -1
>          elif ca > cb:
> -- 
> 2.17.1
>
Richard Purdie June 15, 2019, 10:05 a.m.
On Sat, 2019-06-15 at 09:24 +0200, Martin Jansa wrote:
> I was seeing the same error on versions not ending with '.', in my
> case:
> bb.utils.vercmp((0,1.0.2r,r0.0webos22),
> (0,1.0.2r0webos19,r0.0webos21)
> 
> Which lead to do_packagedata failure through
> buildhistory_emit_pkghistory shown bellow.
> 
> Alex's fix works for the above versions as well, should I extend
> the bb.utils.vercmp selftest with even weirder versions like we're
> using
> or leave it as is?

Adding such examples would be good please!

Cheers,

Richard