Browse Source

bitbake: prserv: increment 9 to 10 correctly

Previously, incrementing "0.9" would result in "0.1.0", which
generally gets recognised as a lower version number. Even more
surprising, incrementing "0.99" returned "0.1.0.0".

This is due to the behaviour of the list function on a string
object; it adds each character as an element in a new list,
causing the new string '10' to become the list [ '1', '0' ].

Instead of converting a string to a list, add the string to a
new list, and concatenate it with the existing list slice. And
provide test cases for "0.9" -> "0.10" and related edge cases.

(Bitbake rev: 96ddeefa88ff4c37e9ea096726a7cdca5b5b4572)

Signed-off-by: Dan McGregor <dan.mcgregor@usask.ca>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Dan McGregor 8 months ago
parent
commit
de29354e84
2 changed files with 3 additions and 1 deletions
  1. 1 1
      bitbake/lib/prserv/__init__.py
  2. 2 0
      bitbake/lib/prserv/tests.py

+ 1 - 1
bitbake/lib/prserv/__init__.py

@@ -34,7 +34,7 @@ def increase_revision(ver):
          logger.critical("Unable to increase revision value %s: %s" % (ver, e))
          raise e
 
-    return ".".join(fields[0:-1] + list(str(val + 1)))
+    return ".".join(fields[0:-1] + [ str(val + 1) ])
 
 def _revision_greater_or_equal(rev1, rev2):
     """Compares x.y.z revision numbers, using integer comparison

+ 2 - 0
bitbake/lib/prserv/tests.py

@@ -84,6 +84,8 @@ class FunctionTests(unittest.TestCase):
         self.assertEqual(increase_revision("1.0"), "1.1")
         self.assertEqual(increase_revision("1.1.1"), "1.1.2")
         self.assertEqual(increase_revision("1.1.1.3"), "1.1.1.4")
+        self.assertEqual(increase_revision("9"), "10")
+        self.assertEqual(increase_revision("1.9"), "1.10")
         self.assertRaises(ValueError, increase_revision, "1.a")
         self.assertRaises(ValueError, increase_revision, "1.")
         self.assertRaises(ValueError, increase_revision, "")