Message ID | 20240403135706.535976-1-michael.opdenacker@bootlin.com |
---|---|
State | New |
Headers | show |
Series | package: fix issue converting PR to string | expand |
On Wed, 2024-04-03 at 15:57 +0200, Michael Opdenacker via lists.openembedded.org wrote: > From: Michael Opdenacker <michael.opdenacker@bootlin.com> > > 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. > > Signed-off-by: Michael Opdenacker <michael.opdenacker@bootlin.com> > CC: thomas.petazzoni@bootlin.com > > --- > > 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
diff --git a/meta/classes-global/package.bbclass b/meta/classes-global/package.bbclass index aa1eb5e901..82747d5467 100644 --- a/meta/classes-global/package.bbclass +++ b/meta/classes-global/package.bbclass @@ -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)) } #