package: fix issue converting PR to string
PATCH 1/1 package: fix issue converting PR to string
From: Michael Opdenacker <[email protected]>
The upcoming introduction of "passthrough" PR servers will add non integer PR values, such as '0.3'.
With such a value, the current conversion of this value to a string, to define the package file name, can result in incorrect strings such as "0.30000000000000004"!
Introduce a safe_str() function which, when given a float value, rounds it up to the 6th decimal first, before the conversion to string.
---
Notes: this has been tested successfully on the "master" branch. No obvious regression was found and the package file names look normal.
--- meta/classes-global/package.bbclass | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
meta/classes-global/package.bbclass +10 -3
@@ -250,6 +250,13 @@ package_get_auto_pr[vardeps] += "PRSERV_ACTIVE" python package_get_auto_pr() { import oe.prservice + def safe_str(pr): + # Avoids turning 0.3 to 0.30000000000000004 (for example) + # during the conversion of a float to a string + if type(pr) == float: + pr = round(pr, 6) + return str(pr) + def get_do_package_hash(pn): if d.getVar("BB_RUNTASK") != "do_package": taskdepdata = d.getVar("BB_TASKDEPDATA", False)
@@ -289,7 +296,7 @@ python package_get_auto_pr() { auto_pr = d.getVar('PRAUTO_' + version + '_' + pkgarch) or d.getVar('PRAUTO_' + version) or None if auto_pr is None: bb.fatal("Can NOT get PRAUTO from lockdown exported file") - d.setVar('PRAUTO',str(auto_pr)) + d.setVar('PRAUTO', safe_str(auto_pr)) return try:
@@ -299,7 +306,7 @@ python package_get_auto_pr() { srcpv = bb.fetch2.get_srcrev(d) base_ver = "AUTOINC-%s" % version[:version.find(srcpv)] value = conn.getPR(base_ver, pkgarch, srcpv) - d.setVar("PRSERV_PV_AUTOINC", str(value)) + d.setVar("PRSERV_PV_AUTOINC", safe_str(value)) auto_pr = conn.getPR(version, pkgarch, checksum) conn.close()
@@ -307,7 +314,7 @@ python package_get_auto_pr() { bb.fatal("Can NOT get PRAUTO, exception %s" % str(e)) if auto_pr is None: bb.fatal("Can NOT get PRAUTO from remote PR service") - d.setVar('PRAUTO',str(auto_pr)) + d.setVar('PRAUTO', safe_str(auto_pr)) } #
Signature · 1 line
2.34.1
Quoted 13 lines · Michael Opdenacker via lists.openembedded.org
From: Michael Opdenacker <[email protected]>
The upcoming introduction of "passthrough" PR servers will add non integer PR values, such as '0.3'.
With such a value, the current conversion of this value to a string, to define the package file name, can result in incorrect strings such as "0.30000000000000004"!
Introduce a
safe_str()function which, when given a float value, rounds it up to the 6th decimal first, before the conversion to string.
Quoted 8 lines
Signed-off-by Michael Opdenacker <[email protected]>---
Notes: this has been tested successfully on the "master" branch. No obvious regression was found and the package file names look normal.
Shouldn't this be happening at the bitbake level in the prserv code? I doubt we should be passing float types around in the first place?
Cheers,
Richard