Skip to contentSkip to conversation

Environmental variable present in do_compile() {}, bitbake recipe -e, but is missing from do_configure() {} #bitbake

DISCUSSION [email protected] 4 participants 13 messages Jul 16, 2025 – Jul 18, 2025

lore
Share & tools
lore
#0 lore raw

So to be clear, when I execute bitbake my-recipe -e | grep "MY_VAR'", it is present.

If I make it as far as the do_compile() step, I can also capture the 'export' command and see that it is present.

However, at the do_configure() step, it, as well as a bunch of other stuff is missing.

Is this intentional? A bug? Documented somewhere?

Thanks,
Joe

#1 lore raw

You are not showing anything useful about your configuration and environment and recipe that needs the variable. What is the variable? Where is it being set? Where is it being exported? How did you determine that it is present in one task but absent in another? What is the 'bunch of other stuff'?

The answer to your question is that it is almost certainly a mis-configuration in your local build.

Alex

Quoted 21 lines · joseph.maniaci via lists.yoctoproject.org

So to be clear, when I execute bitbake my-recipe -e | grep "MY_VAR'", it is present.

If I make it as far as the do_compile() step, I can also capture the 'export' command and see that it is present.

However, at the do_configure() step, it, as well as a bunch of other stuff is missing.

Is this intentional? A bug? Documented somewhere?

Thanks,
Joe

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#65669): https://lists.yoctoproject.org/g/yocto/message/65669
Mute This Topic: https://lists.yoctoproject.org/mt/114193163/1686489
Mute #bitbake:https://lists.yoctoproject.org/g/yocto/mutehashtag/bitbake Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/yocto/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#2 lore raw

So in experimenting, I learned that if I did a 'export ABC=3' in my environment followed by a 'bitbake whatever', the ABC environment variable would persist all the way to the do_compile(). However, what I found weird is that it is not present in the do_configure() step.

#3 lore raw

Hi Joseph,

Quoted 2 lines · joseph.maniaci via lists.yoctoproject.org

So in experimenting, I learned that if I did a 'export ABC=3' in my environment followed by a 'bitbake whatever', the ABC environment variable would persist all the way to the do_compile(). However, what I found weird is that it is not present in the do_configure() step.

You need to allow environment variables to be passed through to bitbake. This is done via BB_ENV_PASSTHROUGH/BB_ENV_PASSTHROUGH_ADDITIONS variable in your local.conf for example.

So you would have something like

BB_ENV_PASSTHROUGH_ADDITIONS="ABC"

I believe.

I'm surprised though that the variable is found by bitbake at all.

Cheers,
Quentin

#4 lore raw

Ah, I'm using a script to do this in a repeatable fashion, so I forgot that the last thing it does is

export BB_ENV_PASSTHROUGH_ADDITIONS="$BB_ENV_PASSTHROUGH_ADDITIONS ABC"

#5 lore raw
Quoted 6 lines · joseph.maniaci via lists.yoctoproject.org

Ah, I'm using a script to do this in a repeatable fashion, so I forgot that the last thing it does is

export BB_ENV_PASSTHROUGH_ADDITIONS="$BB_ENV_PASSTHROUGH_ADDITIONS ABC"

This makes the variable available in the bitbake datastore (e.g. you can reference it in recipes, or you can use d.getVar("ABC") in python), but it won't make it available automatically as an environment variable. To have it as an env var you are expected to export it, with "export ABC" in the recipe, either in a task to make it available in that specific task, or outside of tasks, to make it available in all tasks. (Or in a global config file, like local.conf for example, to make  it available for all tasks globally as env var)

Since you mention that it is available in the compile step, I wonder if you have an explicit "export ABC" in the do_compile task.

#6 lore raw

I must have at some point because after double checking the output of 'export' of do_compile, I no longer see it there as well....sorry for wasting your guys' time on this one.

#7 lore raw

Okay, maybe one more question for the next poor soul that has the same-ish issue

Why does this work:

*** Prior to bitbake ***

export ABC="AAAAAAAAAAAAAAAHHHHHHHHHHHHHHH"
export BB_ENV_PASSTHROUGH_ADDITIONS="$BB_ENV_PASSTHROUGH_ADDITIONS ABC"

*** bitbake recipe ***
....
do_configure () {
export ABC=${ABC} && cmake_do_configure } <<<--- Obviously referencing and seeing ${ABC}
....

CMAKE configures and compiles successfully

but this doesn't

*** bitbake recipe ***
....
do_configure () {
cmake_do_configure <<<---  ${ABC} doesn't make it to cmake }
....

*** cmakelists.txt ***

if ( NOT DEFINED ENV{ABC})
message (FATAL_ERROR "Undefined environmental variable: ABC \n " ) endif ()

*** bitbake output ***
....
| DEBUG: Executing shell function do_configure
....

*** cmake output ***
| CMake Error at CMakeLists.txt:12 (message):
|   Undefined environmental variable: ABC

Even doing something like the following makes it visible to CMAKE

SOME_VAR = "${ABC}"
do_configure () {
export ABC=${SOME_VAR} && cmake_do_configure
}

#8 lore raw
Quoted 12 lines · joseph.maniaci via lists.yoctoproject.org

Okay, maybe one more question for the next poor soul that has the same-ish issue

Why does this work:

*** Prior to bitbake ***

export ABC="AAAAAAAAAAAAAAAHHHHHHHHHHHHHHH"
export BB_ENV_PASSTHROUGH_ADDITIONS="$BB_ENV_PASSTHROUGH_ADDITIONS ABC"
*** bitbake recipe ***
....

Quoted 8 lines

do_configure () {
    export ABC=${ABC} && cmake_do_configure } <<<--- Obviously referencing and seeing ${ABC}
....

CMAKE configures and compiles successfully

but this doesn't

Because of the extra export you added.

Adding ABC to BB_ENV_PASSTHROUGH_ADDITIONS will make the ${ABC} variable available in the recipes - but only in the recipes, and not as an environment variable.

When you write inside a task 'export ABC="${ABC}"' - this looks like pure shell, a self-referencing tautological assignment: seems like it says "create an env var called ABC and set it to the value of the ABC env var"

But it's something else.

It goes through the bitbake parser first, and by the time it is executed, it becomes 'export ABC="AAAAAAAAAAAAAAAHHHHHHHHHHHHHHH"' - the original ${ABC} is nowhere to be found, because it's a bitbake variable (just like SRC_URI, for example), not an env var, it was substituted with the literal value of ${ABC}. And before executing that export statement, the ABC env var doesn't exist in the build environment at all.

Quoted 41 lines


*** bitbake recipe ***
....
do_configure () {
    cmake_do_configure <<<---  ${ABC} doesn't make it to cmake }
....

*** cmakelists.txt ***

if( NOTDEFINEDENV{ABC})
    message(FATAL_ERROR "Undefined environmental variable: ABC\n") endif()

*** bitbake output ***
....
| DEBUG: Executing shell function do_configure
....

*** cmake output ***
| CMake Error at CMakeLists.txt:12 (message): |   Undefined environmental variable: ABC



Even doing something like the following makes it visible to CMAKE
SOME_VAR = "${ABC}" do_configure () {   export ABC=${SOME_VAR} && cmake_do_configure }

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#65679): https://lists.yoctoproject.org/g/yocto/message/65679
Mute This Topic: https://lists.yoctoproject.org/mt/114193163/6084445
Mute #bitbake:https://lists.yoctoproject.org/g/yocto/mutehashtag/bitbake Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/yocto/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#9 lore raw
Quoted 7 lines · Gyorgy Sarvari

It goes through the bitbake parser first, and by the time it is executed, it becomes 'export ABC="AAAAAAAAAAAAAAAHHHHHHHHHHHHHHH"' - the original ${ABC} is nowhere to be found, because it's a bitbake variable (just like SRC_URI, for example), not an env var, it was substituted with the literal value of ${ABC}. And before executing that export statement, the ABC env var doesn't exist in the build environment at all.

Man, considering the quantity of search results telling users to use BB_ENV_PASSTHROUGH_ADDITIONS to accomplish what I'm doing, that really feels like something that should be highlighted in red, and bolded, in the documentation ( https://docs.yoctoproject.org/bitbake/bitbake-user-manual/bitbake-user-manual-ref-variables.html#term-BB_ENV_PASSTHROUGH_ADDITIONS ). Not to mention all of the CMAKE gotchas I've come across.

#10 lore raw

Thank you so much though for that clarification, I'll definitely never forget that one.

#11 lore raw
In reply to [email protected]

Hi Joseph,

Quoted 12 lines · joseph.maniaci via lists.yoctoproject.org
Quoted 7 lines · Gyorgy Sarvari

It goes through the bitbake parser first, and by the time it is executed, it becomes 'export ABC="AAAAAAAAAAAAAAAHHHHHHHHHHHHHHH"' - the original ${ABC} is nowhere to be found, because it's a bitbake variable (just like SRC_URI, for example), not an env var, it was substituted with the literal value of ${ABC}. And before executing that export statement, the ABC env var doesn't exist in the build environment at all.

Man, considering the quantity of search results telling users to use BB_ENV_PASSTHROUGH_ADDITIONS to accomplish what I'm doing, that really feels like something that should be highlighted in red, and bolded, in the documentation ( https://docs.yoctoproject.org/bitbake/bitbake-user-manual/bitbake-user-manual-ref-variables.html#term-BB_ENV_PASSTHROUGH_ADDITIONS ). Not to mention all of the CMAKE gotchas I've come across.

Don't hesitate to send patches for the docs :)

The more time one spends working with BitBake the more difficult it is to write documentation with the "beginner" eye, so this kind of feedback and contribution is very much welcome!

Cheers,
Quentin

#12 lore raw
In reply to Alexander Kanavin

So in experimenting, I learned that if I did a 'export ABC=3' in my environment followed by a 'bitbake whatever', the ABC environment variable would persist all the way to the do_compile(). However, what I found weird is that it is not present in the do_configure() step.

To confirm it was present, period, I can see it in 'bitbake whatever -e'. I can, in the do_compile() step, execute 'export > do_compile.out', examine the file and see 'export ABC=3'. I can, in the do_configure() step, execute 'export > do_configure.out', examine the file and see that it isn't there.