diff mbox series

[bitbake-devel,V3,2/2] lib/bb/parse/ast.py: error out for internal fragment in case of a previous value

Message ID 20251119090045.107642-2-Qi.Chen@windriver.com
State New
Headers show
Series [bitbake-devel,V3,1/2] bitbake: add SKIP_FRAGMENTS CookerFeature | expand

Commit Message

ChenQi Nov. 19, 2025, 9 a.m. UTC
From: Chen Qi <Qi.Chen@windriver.com>

When an internal fragment is enabled, and there's already a value
for the corresponding variable, we should error out to avoid any
confusion.

For example, when 'machine/qemux86-64' fragement is enabled, and
we get some "MACHINE = xxx" in local.conf or env, we should error
out and recomment users to use 'bitbake-config-build disable-fragment'.

We should be tolerating '??=' assignments. For example, DISTRO defaults
to "nodistro" in oe-core layer, and when 'distro/poky" fragment is enabled,
there should be no confusion.

Fixes [YOCTO #16060]

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
 lib/bb/parse/ast.py | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Alexander Kanavin Nov. 19, 2025, 9:32 a.m. UTC | #1
Thanks, this looks much more elegant!

Now I just need to finish up the shorter setup dir name feature (and a
couple minor tweaks), and we're good to release.

Alex

On Wed, 19 Nov 2025 at 10:01, <Qi.Chen@windriver.com> wrote:
>
> From: Chen Qi <Qi.Chen@windriver.com>
>
> When an internal fragment is enabled, and there's already a value
> for the corresponding variable, we should error out to avoid any
> confusion.
>
> For example, when 'machine/qemux86-64' fragement is enabled, and
> we get some "MACHINE = xxx" in local.conf or env, we should error
> out and recomment users to use 'bitbake-config-build disable-fragment'.
>
> We should be tolerating '??=' assignments. For example, DISTRO defaults
> to "nodistro" in oe-core layer, and when 'distro/poky" fragment is enabled,
> there should be no confusion.
>
> Fixes [YOCTO #16060]
>
> Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
> ---
>  lib/bb/parse/ast.py | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/lib/bb/parse/ast.py b/lib/bb/parse/ast.py
> index bf9bd4f55..00e3615e6 100644
> --- a/lib/bb/parse/ast.py
> +++ b/lib/bb/parse/ast.py
> @@ -367,6 +367,12 @@ class AddFragmentsNode(AstNode):
>          def check_and_set_builtin_fragment(fragment, data, builtin_fragments):
>              prefix, value = fragment.split('/', 1)
>              if prefix in builtin_fragments.keys():
> +                if data.getVar(builtin_fragments[prefix], noweakdefault=True) != None:
> +                    bb.fatal(
> +                        ("A builtin fragment '%s' is used while %s has already got an assignment.\n"
> +                         "Please either disable the fragment or remove the value assignment.\n"
> +                         "To disable the fragment, use 'bitbake-config-build disable-fragment %s'."
> +                         ) % (fragment, builtin_fragments[prefix], fragment))
>                  fragment_history = data.varhistory.variable(self.fragments_variable)
>                  loginfo={}
>                  for fh in fragment_history[::-1]:
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/lib/bb/parse/ast.py b/lib/bb/parse/ast.py
index bf9bd4f55..00e3615e6 100644
--- a/lib/bb/parse/ast.py
+++ b/lib/bb/parse/ast.py
@@ -367,6 +367,12 @@  class AddFragmentsNode(AstNode):
         def check_and_set_builtin_fragment(fragment, data, builtin_fragments):
             prefix, value = fragment.split('/', 1)
             if prefix in builtin_fragments.keys():
+                if data.getVar(builtin_fragments[prefix], noweakdefault=True) != None:
+                    bb.fatal(
+                        ("A builtin fragment '%s' is used while %s has already got an assignment.\n"
+                         "Please either disable the fragment or remove the value assignment.\n"
+                         "To disable the fragment, use 'bitbake-config-build disable-fragment %s'."
+                         ) % (fragment, builtin_fragments[prefix], fragment))
                 fragment_history = data.varhistory.variable(self.fragments_variable)
                 loginfo={}
                 for fh in fragment_history[::-1]: