[yocto] Syntax for zero-padding a number in a recipe?

Claudius Heine ch at denx.de
Fri Jun 28 13:48:06 PDT 2019


Hi,

Quoting Aaron Biver (2019-06-28 18:44:40)
> Is there such a thing as zero padding a number in a recipe (or vice versa?
> I'd be just as happy starting with a zero-padded number, and converting it
> to non-zero-padded.

In bitbake you could do this with inline python:

	NUMBER = "1"
	NUMBER_PADDED = "${@"{:02d}".format(d.getVar("NUMBER", True))}"
	NUMBER_PADDED2 = "0012"
	NUMBER2 = "${@str(int(d.getVar("NUMBER_PADDED2", True)))}"

I have not tested this and it could possible be done more elegant, but
it should work.

regards,
Claudius

> The crux of the dilemma is that I must have zero-padding for file-naming,
> but I CAN'T have zero padding in these numbers when I pass them to the C
> code (or the C code treats them as octal).
> 
> I'd like to start with:
> VERSION_MAJOR="1"
> VERSION_MINOR="19"
> 
> And turn this into "01" and "19" for purposes of naming the output file
> from the recipe.
> 
> I've tried the bash-style printf -v, but the recipe kicks the printf lines
> out with a parse error.
> 
> VERSION_MAJOR="01"
> VERSION_MINOR="19"
> 
> VERSION_MAJOR_STR=""
> VERSION_MINOR_STR=""
> 
> printf -v VERSION_MAJOR_STR "%02d" VERSION_MAJOR
> printf -v VERSION_MINOR_STR "%02d" VERSION_MINOR
> 
> 
> -- 
> _______________________________________________
> yocto mailing list
> yocto at yoctoproject.org
> https://lists.yoctoproject.org/listinfo/yocto

--
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-54 Fax: (+49)-8142-66989-80 Email: ch at denx.de

           PGP key: 6FF2 E59F 00C6 BC28 31D8 64C1 1173 CB19 9808 B153
                             Keyserver: hkp://pool.sks-keyservers.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: signature
URL: <http://lists.yoctoproject.org/pipermail/yocto/attachments/20190628/ead1e77a/attachment.pgp>


More information about the yocto mailing list