Skip to contentSkip to conversation

bitbake: enforce variables to be defined?

DISCUSSION Jocelyn Meyron 4 participants 7 messages Oct 24, 2024 – Oct 28, 2024

lore
Share & tools
lore
#0 lore raw

Hello everyone,

I'm wondering if there is an easy way (or a not so hard one :D) to enforce that the variables used in BitBake tasks are defined, something akin to "set -u" in sh/bash. I had an issue recently where I removed one bbclass from one recipe and one of my tasks was using a variable defined in the class and it took me some time to figure out the problem...

Thank you in advance.

#1 lore raw

Hi Jocelyn,

Quoted 6 lines · Jocelyn Meyron via lists.yoctoproject.org

You don't often get email from [email protected]. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification> Hello everyone,

I'm wondering if there is an easy way (or a not so hard one :D) to enforce that the variables used in BitBake tasks are defined, something akin to "set -u" in sh/bash. I had an issue recently where I removed one bbclass from one recipe and one of my tasks was using a variable defined in the class and it took me some time to figure out the problem...

For shell tasks/functions, you can add set -u as the first command to run in the task/function.

I believe that should work since we have some recipes with set -e

Cheers,
Quentin

#2 lore raw

Thanks Quentin for your answer.

I know that I can do that but my question was more to know if there were systematic way to tell BitBake to insert "set -u" in all do_* tasks in my layer.

#3 lore raw
Quoted 6 lines · Jocelyn Meyron via lists.yoctoproject.org

Thanks Quentin for your answer.
I know that I can do that but my question was more to know if there were systematic way to tell BitBake to insert "set -u" in all do_* tasks in my layer.

For that exact question: no.

There’s an argument to be made that maybe our tasks should be stronger and do that automatically. I’m curious how much explodes right now if you did it globally…

Ross

#4 lore raw
In reply to Jocelyn Meyron

Hi,

If you need to add something to several recipes, you can create a bbclass and make the recipes inherit it.

Ex:

SUMMARY = "Enables/disables compile flags for builds"

TARGET_CFLAGS:append = "${@ ' -DTEST_ENV' if not d.getVar('RELEASE') else ''}"

The else is empty, maybe it is not entirely clear in the example. This kind of approach can be made for any you want. You can make an append of a task and things like that.

Then the recipes would only need to have the line:

inherit <bbclass_name>

Sincerely,

Jairo R. Mejia Aponte

________________________________
From: [email protected] <[email protected]> on behalf of Jocelyn Meyron <[email protected]>
Sent: 24 October 2024 11:52 AM
To: Quentin Schulz <[email protected]>; [email protected] <[email protected]>
Subject: [EXTERNAL] Re: [yocto] bitbake: enforce variables to be defined?

External Message:Use caution before opening links or attachments

Thanks Quentin for your answer.

I know that I can do that but my question was more to know if there were systematic way to tell BitBake to insert "set -u" in all do_* tasks in my layer.

**********************************************************************
DISCLAIMER:
Privileged and/or Confidential information may be contained in this message. If you are not the addressee of this message, you may not copy, use or deliver this message to anyone. In such event, you should destroy the message and kindly notify the sender by reply e-mail. It is understood that opinions or conclusions that do not relate to the official business of the company are neither given nor endorsed by the company. Thank You.

#5 lore raw
Quoted 9 lines · Jairo Mejia Aponte via lists.yoctoproject.org

You don't often get email from [email protected]. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification> Hi,

If you need to add something to several recipes, you can create a bbclass and make the recipes inherit it.

Ex:

SUMMARY = "Enables/disables compile flags for builds"

Quoted 8 lines

TARGET_CFLAGS:append = "${@ ' -DTEST_ENV' if not d.getVar('RELEASE') else ''}"

The else is empty, maybe it is not entirely clear in the example. This kind of approach can be made for any you want. You can make an append of a task and things like that.

Then the recipes would only need to have the line:

inherit <bbclass_name>

Additionally, you could dynamically add a prefunc and postfunc for each task, provided you can detect which one is a shell task and not a python task (though maybe having set -e in a python's task's prefunc would be fine as well?), from anonymous python I guess?

Just throwing ideas right now.

Cheers,
Quentin

#6 lore raw

I had a look and in fact, it should be possible to do what you proposed (the relevant properties are not documented but are present in the bitbake datastore).

For the moment, I patched poky to add this "set -u" option when a certain variable is set but it has the disadvantage of being global to my whole build. I will investigate the other option to create a dedicated class for that, and will let you know about my progress.