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>
This commit is contained in:
Dan McGregor 2024-09-09 09:41:51 -06:00 committed by Richard Purdie
parent d016d18a9f
commit de29354e84
2 changed files with 3 additions and 1 deletions

View File

@ -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

View File

@ -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, "")