diff mbox series

ast: Warn on multiple builtin config fragments for the same variable

Message ID 20251009223552.2648331-1-yoann.congal@smile.fr
State New
Headers show
Series ast: Warn on multiple builtin config fragments for the same variable | expand

Commit Message

Yoann Congal Oct. 9, 2025, 10:35 p.m. UTC
From: Yoann Congal <yoann.congal@smile.fr>

Having multiple builtin config fragments for the same variable
(eg OE_FRAGMENTS = "... machine/A ... machine/B") is not supported.
Warn the user to make them fix this but continue with the normal
variable evaluation : the last affectation "wins".

Added warning looks like:
WARNING: OE_FRAGMENTS has multiple builtin fragments for machine: machine/qemux86-64 machine/test machine/qemux86-64. This is not supported but build will continue using the last value.

Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
---
 lib/bb/parse/ast.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Alexander Kanavin Oct. 10, 2025, 6:40 a.m. UTC | #1
On Fri, 10 Oct 2025 at 00:36, Yoann Congal via lists.openembedded.org
<yoann.congal=smile.fr@lists.openembedded.org> wrote:
> +            if len(builtin_fragments_list) > 1:
> +                bb.warn(
> +                    ("%s has multiple builtin fragments for %s: %s. "
> +                     "This is not supported but build will continue using the last value.")

I think the message should be:

"Multiple builtin fragments are enabled for %s via variable %s: %s. "
"This likely points to a mis-configuration in the metadata, as only
one of them should be set. The build will use the last value."

Alex
Yoann Congal Oct. 10, 2025, 8:08 a.m. UTC | #2
Le ven. 10 oct. 2025 à 08:40, Alexander Kanavin <alex.kanavin@gmail.com> a
écrit :

> On Fri, 10 Oct 2025 at 00:36, Yoann Congal via lists.openembedded.org
> <yoann.congal=smile.fr@lists.openembedded.org> wrote:
> > +            if len(builtin_fragments_list) > 1:
> > +                bb.warn(
> > +                    ("%s has multiple builtin fragments for %s: %s. "
> > +                     "This is not supported but build will continue
> using the last value.")
>
> I think the message should be:
>
> "Multiple builtin fragments are enabled for %s via variable %s: %s. "
> "This likely points to a mis-configuration in the metadata, as only
> one of them should be set. The build will use the last value."
>

v2 sent. Thanks!


> Alex
>
diff mbox series

Patch

diff --git a/lib/bb/parse/ast.py b/lib/bb/parse/ast.py
index cb06e8917..6262d9ca1 100644
--- a/lib/bb/parse/ast.py
+++ b/lib/bb/parse/ast.py
@@ -376,6 +376,26 @@  class AddFragmentsNode(AstNode):
 
         if not fragments:
             return
+
+        # Check for multiple builtin fragments setting the same variable
+        for builtin_fragment_key in builtin_fragments.keys():
+            builtin_fragments_list = list(
+                filter(
+                    lambda f: f.startswith(builtin_fragment_key + "/"),
+                    fragments.split(),
+                )
+            )
+            if len(builtin_fragments_list) > 1:
+                bb.warn(
+                    ("%s has multiple builtin fragments for %s: %s. "
+                     "This is not supported but build will continue using the last value.")
+                    % (
+                        self.fragments_variable,
+                        builtin_fragment_key,
+                        " ".join(builtin_fragments_list),
+                    )
+                )
+
         for f in fragments.split():
             if check_and_set_builtin_fragment(f, data, builtin_fragments):
                 continue