Skip to contentSkip to conversation

Set global variable based on recipes versions

DISCUSSION Sid-Ali 4 participants 8 messages Nov 4, 2024

lore
Share & tools
lore

Sid-Ali

author
#0 lore raw

Hello

I am struggling with a simple case but I cannot find a simple solution.

I want to set a global variable from a bbclass or from recipes (impossible right?).
My usecase is that I am installing multiple version of the same package into my image and I need *at my build time* to get access to a variable with the list of versions installed.

For example, my package is named pkg. I created the following recipes:

pkg-1.1_1.1.12.bb
pkg-1.2_1.2.4.bb
pkg-1.3_1.3.9.bb

That way I installed the versions 1.1, 1.2 and 1.3.

I tried having a global inherit of a bbclass that addhandler on a specific event (ParseRecipe) but I cannot set a global variable that will be used from recipes.

is there a way to get the list of packages that are going to be installed in the image from an event or variable? I could do the parsing afterwards.

Thanks

#1 lore raw

Presumably you list these somewhere in an image recipe (so that they're installed) - this could be moved into a variable in your distro definition where it would be global?

Alex

Quoted 30 lines · Sid-Ali via lists.yoctoproject.org

Hello

I am struggling with a simple case but I cannot find a simple solution.

I want to set a global variable from a bbclass or from recipes (impossible right?).
My usecase is that I am installing multiple version of the same package into my image and I need at my build time to get access to a variable with the list of versions installed.

For example, my package is named pkg. I created the following recipes:

pkg-1.1_1.1.12.bb
pkg-1.2_1.2.4.bb
pkg-1.3_1.3.9.bb

That way I installed the versions 1.1, 1.2 and 1.3.

I tried having a global inherit of a bbclass that addhandler on a specific event (ParseRecipe) but I cannot set a global variable that will be used from recipes.

is there a way to get the list of packages that are going to be installed in the image from an event or variable? I could do the parsing afterwards.

Thanks

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

author
#2 lore raw

This would not be dynamic, I wanted to do that during parsing time so that even if I add another recipe, I would have the variable updated automatically without the need to re-define it

#3 lore raw

But adding a recipe to a layer will not add it to any image. You still need to place it explicitly in a list somewhere.

Alex

Quoted 4 lines · Sid-Ali via Lists.Yoctoproject.Org

This would not be dynamic, I wanted to do that during parsing time so that even if I add another recipe, I would have the variable updated automatically without the need to re-define it

author
#4 lore raw
Quoted 4 lines

But adding a recipe to a layer will not add it to any image. You still need to place it explicitly in a list somewhere.

Yes you are absolutely right, I would need the variable that contains list of the versions (in my example: VAR = "1.1 1.2 1.3") for the installed packages and not for the included recipes. If I understood correctly, you are suggesting this:

in distro or config file:
PKGS_INSTALL = "pkg-1.1 pkg-1.2 pkg-1.3"
PKGS_VER = "${@some python code to get the versions in a list for PKGS_INSTALL variable}"

in my image recipe:
IMAGE_INSTALL:append = " ${PKGS_INSTALL}"

Quoted 6 lines

perhaps you can explain a bit more what you really want to achieve. You wrote you want to have it in a global variable, but to what purpose:
Do you need to use it one recipe?

Yes the purpose is to use it in another recipe.
I am installing multiple version of the package and I have an update recipe based on swupdate that will have these versions listed in a file so that I can ONLY trigger updates based on some logics that are linked to these versions.

Quoted 3 lines

My guess is that you don't know how many versions of pkg-*

Right

Quoted 3 lines

IMAGE_INSTALL:append = " ${variable_containing_all_my_pkg}"

This is the same suggestion as above right?

Quoted 5 lines

If you just need to have the number of installed packages pkg-* you could just parse the build folder *after* you finished the Yocto build, but that would be outside the bitbake process...

Unfortunately I would not be able to do that because the update is generated during build so I would need this information before.

Of course I can simply write the versions in a specfic variable and update it when I add/remove a new version but I was hoping to find a more generic and specific way of doing that.

#5 lore raw
Quoted 9 lines · Sid-Ali via Lists.Yoctoproject.Org

Yes you are absolutely right, I would need the variable that contains list of the versions (in my example: VAR = "1.1 1.2 1.3") for the installed packages and not for the included recipes. If I understood correctly, you are suggesting this:

in distro or config file:
PKGS_INSTALL = "pkg-1.1 pkg-1.2 pkg-1.3"
PKGS_VER = "${@some python code to get the versions in a list for PKGS_INSTALL variable}"

in my image recipe:
IMAGE_INSTALL:append = " ${PKGS_INSTALL}"

I'm not sure what PKGS_VER is for, but anyway, no not quite. I wasn't proposing python code at all, just a static list that gets updated through an external script (that goes over filenames in a layer tree and forms a list).

You might be able to write a python function that does the same, and call it in SOME_VAR = "${@...}" but I'm not sure it'll work.

Alex

#6 lore raw
In reply to Sid-Ali
Quoted 1 line

I am installing multiple version of the package and I have an update recipe based on swupdate that will have these versions listed in a file so that I can ONLY trigger updates based on some logics that are linked to these versions.

You can create this file with package version in your rootfs after rootfs is created.
See e.g. write_image_manifest which is executed as ROOTFS_POSTUNINSTALL_COMMAND which uses the same data you're asking for.

Peter

#7 lore raw
In reply to Sid-Ali

Hi,

perhaps you can explain a bit more what you really want to achieve. You wrote you want to have it in a global variable, but to what purpose:

Do you need to use it one recipe?
My guess is that you don't know how many versions of pkg-* you have (three in your example) and you maybe want to do something like

IMAGE_INSTALL:append = " ${variable_containing_all_my_pkg}"

(Not sure if that would work, but you also wrote you are installing already).

If you just need to have the number of installed packages pkg-* you could just parse the build folder *after* you finished the Yocto build, but that would be outside the bitbake process...