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

Aaron Biver aaron.biver at gmail.com
Mon Jul 1 06:14:47 PDT 2019


 [Sending again because I initially replied to Claudius only, and not
mailing list]

I found using back-ticks with printf also works in a recipe:

NUMBER = "1"
NUMBER_PADDED="FOO_`printf "02d" ${NUMBER}`_MOARFOO"

On Fri, Jun 28, 2019 at 4:48 PM Claudius Heine <ch at denx.de> wrote:

> 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 --------------
An HTML attachment was scrubbed...
URL: <http://lists.yoctoproject.org/pipermail/yocto/attachments/20190701/46e61417/attachment.html>


More information about the yocto mailing list