All of lore.kernel.org
 help / color / mirror / Atom feed
* Custom variable value: (OVERRIDES?)
@ 2020-04-02 15:34 Mauro Ziliani
  2020-04-03 11:37 ` Duy
  2020-04-05  7:16 ` [bitbake-devel] " Richard Purdie
  0 siblings, 2 replies; 3+ messages in thread
From: Mauro Ziliani @ 2020-04-02 15:34 UTC (permalink / raw)
  To: bitbake-devel

Hi all.

I don't understand how can I change a the value of a variable inside a 
.bb file

I do this work

if MYVAR is empty I need to install default.txt in /etc

if MYVAR contains "white" i need to install white.txt in /etc


So I extend myreciped.bb with this file


myrecipe.bbappend

MYVAR = "default.txt"

MYVAR_white = "white.txt"


do_install_append() {

     install -m 0755 -d ${D}/etc

     install -m 0644 ${MYVAR}    ${D}/etc/value

}


In conf/local.conf I put

MYVAR_pn-myrecipe = "white"


But nothing works as I expect.

Where is my mistakes?


Best regards,

   MZ


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Custom variable value: (OVERRIDES?)
  2020-04-02 15:34 Custom variable value: (OVERRIDES?) Mauro Ziliani
@ 2020-04-03 11:37 ` Duy
  2020-04-05  7:16 ` [bitbake-devel] " Richard Purdie
  1 sibling, 0 replies; 3+ messages in thread
From: Duy @ 2020-04-03 11:37 UTC (permalink / raw)
  To: bitbake-devel

[-- Attachment #1: Type: text/plain, Size: 793 bytes --]

Hi Mauro,

I assume that you are working with poky/meta layer.
You can use conditional function from oe.utils library like this:

YOUR_VAR = "${@oe.utils.conditional("VAR_NAME", "compare_value", "value_if_true", "value_if_false", d)}"

myrecipe.bbappend:
FILE_NAME = "${@oe.utils.conditional("MY_VAR", "white", "white.txt", "default.txt", d)}"
do_install_append() {
install -m 0644 ${FILE_NAME} ${D}/etc/value
}

local.conf:
MY_VAR = "white"

Another way is using in-line python conditional statement:
FILE_NAME = "${@'white.txt' if 'white' in d.getVar('MY_VAR') else 'default.txt'}"

If you want more than two values, consider using variable flag:
https://www.yoctoproject.org/docs/latest/bitbake-user-manual/bitbake-user-manual.html#variable-flag-syntax

Regards,
DD

[-- Attachment #2: Type: text/html, Size: 1062 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [bitbake-devel] Custom variable value: (OVERRIDES?)
  2020-04-02 15:34 Custom variable value: (OVERRIDES?) Mauro Ziliani
  2020-04-03 11:37 ` Duy
@ 2020-04-05  7:16 ` Richard Purdie
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Purdie @ 2020-04-05  7:16 UTC (permalink / raw)
  To: Mauro Ziliani, bitbake-devel

On Thu, 2020-04-02 at 17:34 +0200, Mauro Ziliani wrote:
> I don't understand how can I change a the value of a variable inside
> a  .bb file
> 
> I do this work
> 
> if MYVAR is empty I need to install default.txt in /etc
> 
> if MYVAR contains "white" i need to install white.txt in /etc
> 
> 
> So I extend myreciped.bb with this file
> 
> 
> myrecipe.bbappend
> 
> MYVAR = "default.txt"
> 
> MYVAR_white = "white.txt"
> 
> 
> do_install_append() {
> 
>      install -m 0755 -d ${D}/etc
> 
>      install -m 0644 ${MYVAR}    ${D}/etc/value
> 
> }
> 
> 
> In conf/local.conf I put
> 
> MYVAR_pn-myrecipe = "white"
> 
> 
> But nothing works as I expect.
> 
> Where is my mistakes?

You're mixing up a couple of concepts. In local.conf you could put:

MYVAR_pn-myrecipe = "white.txt"

which would force the value of MYVAR to be "white.txt" in myrecipe.

- or -

OVERRIDES_append_pn-myrecipe = ":white"

which adds "white" as an extra override for myrecipe, which would then
means:

MYVAR_white = "white.txt"
becomes
MYVAR = "white.txt"

Hope that helps explain things!

Cheers,

Richard


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-05  7:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-02 15:34 Custom variable value: (OVERRIDES?) Mauro Ziliani
2020-04-03 11:37 ` Duy
2020-04-05  7:16 ` [bitbake-devel] " Richard Purdie

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.