[1/1] multiarch: inject native variants of preferred providers

Message ID 20251017085344.2647058-1-felix.moessbauer@siemens.com
State Accepted, archived
Headers show
Series [1/1] multiarch: inject native variants of preferred providers | expand

Commit Message

MOESSBAUER, Felix Oct. 17, 2025, 8:53 a.m. UTC
We already create multiarch variants of our recipes in case the host and
target arch are not the same. However, this currently breaks when
combining with PREFERRED_PROVIDERS, as no entries for the -native
variantes are created. By that, bitbake bails out with the following
error:
  Multiple .bb files are due to be built which each provide
  <recipe>-native.

We fix this by injecting the -native variants for all preferred
providers as well (but only in case no explicit one is provided for the
-native variant). This needs to be done after config parsing (hence in
base.bblcass), as the PREFERRED_PROVIDERS are already used at recipe
parsing time (where multiarch.bbclass is loaded).

Fixes: 5a7c2f70 ("handle DPKG_ARCH=all case for transitive deps")
Reported-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
Note, that this can be tested on isar-cip-core, but requires the other
fix in "image: Fix construction of do_image_tools dependencies" as well.

 meta/classes/base.bbclass | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Comments

Jan Kiszka Oct. 17, 2025, 9:09 a.m. UTC | #1
On 17.10.25 10:53, Felix Moessbauer wrote:
> We already create multiarch variants of our recipes in case the host and
> target arch are not the same. However, this currently breaks when
> combining with PREFERRED_PROVIDERS, as no entries for the -native
> variantes are created. By that, bitbake bails out with the following
> error:
>   Multiple .bb files are due to be built which each provide
>   <recipe>-native.
> 
> We fix this by injecting the -native variants for all preferred
> providers as well (but only in case no explicit one is provided for the
> -native variant). This needs to be done after config parsing (hence in
> base.bblcass), as the PREFERRED_PROVIDERS are already used at recipe
> parsing time (where multiarch.bbclass is loaded).
> 
> Fixes: 5a7c2f70 ("handle DPKG_ARCH=all case for transitive deps")
> Reported-by: Jan Kiszka <jan.kiszka@siemens.com>
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
> Note, that this can be tested on isar-cip-core, but requires the other
> fix in "image: Fix construction of do_image_tools dependencies" as well.
> 
>  meta/classes/base.bbclass | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass
> index 90fd570c..471442e5 100644
> --- a/meta/classes/base.bbclass
> +++ b/meta/classes/base.bbclass
> @@ -62,6 +62,30 @@ def get_deb_host_arch():
>  HOST_ARCH ??= "${@get_deb_host_arch()}"
>  HOST_DISTRO ??= "${DISTRO}"
>  
> +# Inject the PREFERRED_PROVIDERs for multiarch variants. This corresponds to
> +# the multiarch_virtclass_handler logic in multiarch.bbclass, but needs to be
> +# done prior to recipe parsing.
> +def inject_preferred_providers(provider, suffix, d):
> +    PP_PREFIX = 'PREFERRED_PROVIDER_'
> +    if provider.endswith(suffix):
> +        return
> +    prefp_value = d.getVar(PP_PREFIX + provider)
> +    if prefp_value and not d.getVar(PP_PREFIX + provider + suffix):
> +        d.setVar(PP_PREFIX + provider + suffix, prefp_value + suffix)
> +
> +python multiarch_preferred_providers_handler() {
> +    if d.getVar('HOST_ARCH') == d.getVar('DISTRO_ARCH'):
> +        return
> +
> +    pref_vars = {var: e.data.getVar(var)
> +                 for var in e.data.keys()
> +                 if var.startswith('PREFERRED_PROVIDER_')}
> +    for p in pref_vars:
> +        inject_preferred_providers(p.replace('PREFERRED_PROVIDER_', ''), '-native', e.data)
> +}
> +addhandler multiarch_preferred_providers_handler
> +multiarch_preferred_providers_handler[eventmask] = "bb.event.ConfigParsed"
> +
>  die() {
>  	bbfatal "$*"
>  }

Works well.

Tested-by: Jan Kiszka <jan.kiszka@siemens.com>

I suppose we should do the same for PREFERRED_VERSION, and also for
-kbuildtarget of self-built kernels.

Jan
Zhihang Wei Oct. 24, 2025, 12:17 p.m. UTC | #2
Applied to next, thanks.

There was an issue with ssh-keygen task blocking oops when booting qemu 
image,
but the same image file can be booted on the same host later without any
problem. It's most likely a one-off issue on the CI server.

Best regards,
Zhihang

On 10/17/25 10:53, 'Felix Moessbauer' via isar-users wrote:
> We already create multiarch variants of our recipes in case the host and
> target arch are not the same. However, this currently breaks when
> combining with PREFERRED_PROVIDERS, as no entries for the -native
> variantes are created. By that, bitbake bails out with the following
> error:
>    Multiple .bb files are due to be built which each provide
>    <recipe>-native.
>
> We fix this by injecting the -native variants for all preferred
> providers as well (but only in case no explicit one is provided for the
> -native variant). This needs to be done after config parsing (hence in
> base.bblcass), as the PREFERRED_PROVIDERS are already used at recipe
> parsing time (where multiarch.bbclass is loaded).
>
> Fixes: 5a7c2f70 ("handle DPKG_ARCH=all case for transitive deps")
> Reported-by: Jan Kiszka <jan.kiszka@siemens.com>
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
> Note, that this can be tested on isar-cip-core, but requires the other
> fix in "image: Fix construction of do_image_tools dependencies" as well.
>
>   meta/classes/base.bbclass | 24 ++++++++++++++++++++++++
>   1 file changed, 24 insertions(+)
>
> diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass
> index 90fd570c..471442e5 100644
> --- a/meta/classes/base.bbclass
> +++ b/meta/classes/base.bbclass
> @@ -62,6 +62,30 @@ def get_deb_host_arch():
>   HOST_ARCH ??= "${@get_deb_host_arch()}"
>   HOST_DISTRO ??= "${DISTRO}"
>   
> +# Inject the PREFERRED_PROVIDERs for multiarch variants. This corresponds to
> +# the multiarch_virtclass_handler logic in multiarch.bbclass, but needs to be
> +# done prior to recipe parsing.
> +def inject_preferred_providers(provider, suffix, d):
> +    PP_PREFIX = 'PREFERRED_PROVIDER_'
> +    if provider.endswith(suffix):
> +        return
> +    prefp_value = d.getVar(PP_PREFIX + provider)
> +    if prefp_value and not d.getVar(PP_PREFIX + provider + suffix):
> +        d.setVar(PP_PREFIX + provider + suffix, prefp_value + suffix)
> +
> +python multiarch_preferred_providers_handler() {
> +    if d.getVar('HOST_ARCH') == d.getVar('DISTRO_ARCH'):
> +        return
> +
> +    pref_vars = {var: e.data.getVar(var)
> +                 for var in e.data.keys()
> +                 if var.startswith('PREFERRED_PROVIDER_')}
> +    for p in pref_vars:
> +        inject_preferred_providers(p.replace('PREFERRED_PROVIDER_', ''), '-native', e.data)
> +}
> +addhandler multiarch_preferred_providers_handler
> +multiarch_preferred_providers_handler[eventmask] = "bb.event.ConfigParsed"
> +
>   die() {
>   	bbfatal "$*"
>   }

Patch

diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass
index 90fd570c..471442e5 100644
--- a/meta/classes/base.bbclass
+++ b/meta/classes/base.bbclass
@@ -62,6 +62,30 @@  def get_deb_host_arch():
 HOST_ARCH ??= "${@get_deb_host_arch()}"
 HOST_DISTRO ??= "${DISTRO}"
 
+# Inject the PREFERRED_PROVIDERs for multiarch variants. This corresponds to
+# the multiarch_virtclass_handler logic in multiarch.bbclass, but needs to be
+# done prior to recipe parsing.
+def inject_preferred_providers(provider, suffix, d):
+    PP_PREFIX = 'PREFERRED_PROVIDER_'
+    if provider.endswith(suffix):
+        return
+    prefp_value = d.getVar(PP_PREFIX + provider)
+    if prefp_value and not d.getVar(PP_PREFIX + provider + suffix):
+        d.setVar(PP_PREFIX + provider + suffix, prefp_value + suffix)
+
+python multiarch_preferred_providers_handler() {
+    if d.getVar('HOST_ARCH') == d.getVar('DISTRO_ARCH'):
+        return
+
+    pref_vars = {var: e.data.getVar(var)
+                 for var in e.data.keys()
+                 if var.startswith('PREFERRED_PROVIDER_')}
+    for p in pref_vars:
+        inject_preferred_providers(p.replace('PREFERRED_PROVIDER_', ''), '-native', e.data)
+}
+addhandler multiarch_preferred_providers_handler
+multiarch_preferred_providers_handler[eventmask] = "bb.event.ConfigParsed"
+
 die() {
 	bbfatal "$*"
 }