diff mbox series

package/classextend: Extend package variables for a multilib variant

Message ID 20260427092912.960716-1-jaeyoon.jung@lge.com
State Changes Requested
Headers show
Series package/classextend: Extend package variables for a multilib variant | expand

Commit Message

From: Jaeyoon Jung <jaeyoon.jung@lge.com>

It extends package variables in case missing for a dynamic package added
during do_split_packages. It's needed for a multilib build where some
per-package variables should be treated as multilib variants.

Signed-off-by: Jaeyoon Jung <jaeyoon.jung@lge.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
---
 meta/classes-global/package.bbclass | 11 +++++++++++
 meta/lib/oe/classextend.py          |  5 +++--
 2 files changed, 14 insertions(+), 2 deletions(-)

Comments

Richard Purdie April 28, 2026, 8:50 a.m. UTC | #1
On Mon, 2026-04-27 at 18:29 +0900, Jaeyoon Jung (LGE) via lists.openembedded.org wrote:
> From: Jaeyoon Jung <jaeyoon.jung@lge.com>
> 
> It extends package variables in case missing for a dynamic package added
> during do_split_packages. It's needed for a multilib build where some
> per-package variables should be treated as multilib variants.
> 
> Signed-off-by: Jaeyoon Jung <jaeyoon.jung@lge.com>
> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
> ---
>  meta/classes-global/package.bbclass | 11 +++++++++++
>  meta/lib/oe/classextend.py          |  5 +++--
>  2 files changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/meta/classes-global/package.bbclass b/meta/classes-global/package.bbclass
> index 67148fc1ac..cfadd36c16 100644
> --- a/meta/classes-global/package.bbclass
> +++ b/meta/classes-global/package.bbclass
> @@ -169,6 +169,7 @@ def do_split_packages(d, root, file_regex, output_pattern, description, postinst
>  
>      for o in sorted(objs):
>          import re, stat
> +        import oe.package
>          if match_path:
>              m = re.match(file_regex, o)
>          else:
> @@ -225,6 +226,16 @@ def do_split_packages(d, root, file_regex, output_pattern, description, postinst
>              hook(f, pkg, file_regex, output_pattern, m.group(1))
>  
>      d.setVar('PACKAGES', ' '.join(packages))
> +
> +    variant = d.getVar("BBEXTENDVARIANT")
> +    prefixes = (d.getVar("MULTILIB_VARIANTS") or "").split()
> +    if variant and prefixes:
> +        import oe.classextend
> +
> +        # Extend package variables for the given variant if unset
> +        clsextend = oe.classextend.ClassExtender(variant, prefixes, d)
> +        clsextend.rename_package_variables((d.getVar("PACKAGEVARS") or "").split(), overwrite=False)
> +
>      return list(split_packages)
>  
>  PACKAGE_DEPENDS += "file-native"
> diff --git a/meta/lib/oe/classextend.py b/meta/lib/oe/classextend.py
> index ddca10dee5..8b9602e316 100644
> --- a/meta/lib/oe/classextend.py
> +++ b/meta/lib/oe/classextend.py
> @@ -128,7 +128,7 @@ class ClassExtender(object):
>          self.set_filter("RCONFLICTS", deps=True)
>          self.set_filter("PKG", deps=True)
>  
> -    def rename_package_variables(self, variables):
> +    def rename_package_variables(self, variables, overwrite=True):
>          pkgs_mapping = get_package_mappings(self.d.getVar('PACKAGES'), self.extname)
>          self.d.setVarFilter('PACKAGES', "package_suffix_filter(val, '" + self.extname + "')")
>          self.d.setVarFilter('PACKAGES_DYNAMIC', "suffix_filter_regex(val, '" + self.extname + "', " + str(self.prefixes) + ")")
> @@ -137,4 +137,5 @@ class ClassExtender(object):
>              if pkg_mapping[0].startswith("${") and pkg_mapping[0].endswith("}"):
>                  continue
>              for subs in variables:
> -                self.d.renameVar("%s:%s" % (subs, pkg_mapping[0]), "%s:%s" % (subs, pkg_mapping[1]))
> +                if overwrite or not self.d.getVar("%s:%s" % (subs, pkg_mapping[1])):
> +                    self.d.renameVar("%s:%s" % (subs, pkg_mapping[0]), "%s:%s" % (subs, pkg_mapping[1]))
> 

Sorry about the delay in responding to this one. I'm very very nervous
about adding this level of complexity to the code and I'm not convinced
this is the right direction.

The original issue was something around:

-LICENSE:libsystemd = "LGPL-2.1-or-later"
+LICENSE:${MLPREFIX}libsystemd = "LGPL-2.1-or-later"

Qi then commented:

> I checked the related codes with PACKAGES_DYNAMIC in multilib.bbclass and package.bbclass.
> I suspect that it's the do_split_packages function in package.bbclass that needs to be fixed.
> This function may also need to use rename_package_variables on the dynamically generated packages.
> You can refer to the multilib_virtclass_handler_postkeyexp function in multilib.bbclass. Note that LICENSE is already in "PACKAGEVARS".
> Could you please check if the above method works?

then you mentioned a second problem with FILES.

I think Qi meant that the function may be needed *only* on the
dynamically generated packages. By calling it unconditionally, you have
the overwrite problem and we really need to avoid doing things twice.

I therefore don't think this is right yet. It would help to have some
clear test cases about the corner cases which aren't working so we can
see this in public code, rather than whatever your layer is doing too.

Cheers,

Richard
> From: Richard Purdie <richard.purdie@linuxfoundation.org>
> Sent: Tuesday, April 28, 2026 17:50
> To: Jaeyoon Jung <jaeyoon.jung@lge.com>; openembedded-core@lists.openembedded.org <openembedded-core@lists.openembedded.org>
> Cc: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
> Subject: Re: [OE-core] [PATCH] package/classextend: Extend package variables for a multilib variant
>  
> On Mon, 2026-04-27 at 18:29 +0900, Jaeyoon Jung (LGE) via lists.openembedded.org wrote:
> > From: Jaeyoon Jung <jaeyoon.jung@lge.com>
> >
> > It extends package variables in case missing for a dynamic package added
> > during do_split_packages. It's needed for a multilib build where some
> > per-package variables should be treated as multilib variants.
> >
> > Signed-off-by: Jaeyoon Jung <jaeyoon.jung@lge.com>
> > Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
> > ---
> >  meta/classes-global/package.bbclass | 11 +++++++++++
> >  meta/lib/oe/classextend.py          |  5 +++--
> >  2 files changed, 14 insertions(+), 2 deletions(-)
> >
> > diff --git a/meta/classes-global/package.bbclass b/meta/classes-global/package.bbclass
> > index 67148fc1ac..cfadd36c16 100644
> > --- a/meta/classes-global/package.bbclass
> > +++ b/meta/classes-global/package.bbclass
> > @@ -169,6 +169,7 @@ def do_split_packages(d, root, file_regex, output_pattern, description, postinst
> >  
> >      for o in sorted(objs):
> >          import re, stat
> > +        import oe.package
> >          if match_path:
> >              m = re.match(file_regex, o)
> >          else:
> > @@ -225,6 +226,16 @@ def do_split_packages(d, root, file_regex, output_pattern, description, postinst
> >              hook(f, pkg, file_regex, output_pattern, m.group(1))
> >  
> >      d.setVar('PACKAGES', ' '.join(packages))
> > +
> > +    variant = d.getVar("BBEXTENDVARIANT")
> > +    prefixes = (d.getVar("MULTILIB_VARIANTS") or "").split()
> > +    if variant and prefixes:
> > +        import oe.classextend
> > +
> > +        # Extend package variables for the given variant if unset
> > +        clsextend = oe.classextend.ClassExtender(variant, prefixes, d)
> > +        clsextend.rename_package_variables((d.getVar("PACKAGEVARS") or "").split(), overwrite=False)
> > +
> >      return list(split_packages)
> >  
> >  PACKAGE_DEPENDS += "file-native"
> > diff --git a/meta/lib/oe/classextend.py b/meta/lib/oe/classextend.py
> > index ddca10dee5..8b9602e316 100644
> > --- a/meta/lib/oe/classextend.py
> > +++ b/meta/lib/oe/classextend.py
> > @@ -128,7 +128,7 @@ class ClassExtender(object):
> >          self.set_filter("RCONFLICTS", deps=True)
> >          self.set_filter("PKG", deps=True)
> >  
> > -    def rename_package_variables(self, variables):
> > +    def rename_package_variables(self, variables, overwrite=True):
> >          pkgs_mapping = get_package_mappings(self.d.getVar('PACKAGES'), self.extname)
> >          self.d.setVarFilter('PACKAGES', "package_suffix_filter(val, '" + self.extname + "')")
> >          self.d.setVarFilter('PACKAGES_DYNAMIC', "suffix_filter_regex(val, '" + self.extname + "', " + str(self.prefixes) + ")")
> > @@ -137,4 +137,5 @@ class ClassExtender(object):
> >              if pkg_mapping[0].startswith("${") and pkg_mapping[0].endswith("}"):
> >                  continue
> >              for subs in variables:
> > -                self.d.renameVar("%s:%s" % (subs, pkg_mapping[0]), "%s:%s" % (subs, pkg_mapping[1]))
> > +                if overwrite or not self.d.getVar("%s:%s" % (subs, pkg_mapping[1])):
> > +                    self.d.renameVar("%s:%s" % (subs, pkg_mapping[0]), "%s:%s" % (subs, pkg_mapping[1]))
> >
> 
> Sorry about the delay in responding to this one. I'm very very nervous
> about adding this level of complexity to the code and I'm not convinced
> this is the right direction.
> 
> The original issue was something around:
> 
> -LICENSE:libsystemd = "LGPL-2.1-or-later"
> +LICENSE:${MLPREFIX}libsystemd = "LGPL-2.1-or-later"
> 
> Qi then commented:
> 
> > I checked the related codes with PACKAGES_DYNAMIC in multilib.bbclass and package.bbclass.
> > I suspect that it's the do_split_packages function in package.bbclass that needs to be fixed.
> > This function may also need to use rename_package_variables on the dynamically generated packages.
> > You can refer to the multilib_virtclass_handler_postkeyexp function in multilib.bbclass. Note that LICENSE is already in "PACKAGEVARS".
> > Could you please check if the above method works?
> 
> then you mentioned a second problem with FILES.
> 
> I think Qi meant that the function may be needed *only* on the
> dynamically generated packages. By calling it unconditionally, you have
> the overwrite problem and we really need to avoid doing things twice.
> 
> I therefore don't think this is right yet. It would help to have some
> clear test cases about the corner cases which aren't working so we can
> see this in public code, rather than whatever your layer is doing too.
> 

Hi Richard,

Thank you for your review.
I understand your concern, and I'd like to suggest a slightly different
approach - using 'rename_package_variables' as is in 'do_split_packages',
rather than adding a level of complexity to 'classextend'.
Regarding the FILES issue I mentioned earlier, I think 'libpam' recipe
should be fixed to include 'MLPREFIX' for the consistency in its recipe.
Also I prepared another patch for selftest which verifies the issue case
concerned. I will send them in a series shortly.


Best regards,
---
Jaeyoon Jung
Software Platform Lab. / Corporate R&D / LG Electronics Inc.
diff mbox series

Patch

diff --git a/meta/classes-global/package.bbclass b/meta/classes-global/package.bbclass
index 67148fc1ac..cfadd36c16 100644
--- a/meta/classes-global/package.bbclass
+++ b/meta/classes-global/package.bbclass
@@ -169,6 +169,7 @@  def do_split_packages(d, root, file_regex, output_pattern, description, postinst
 
     for o in sorted(objs):
         import re, stat
+        import oe.package
         if match_path:
             m = re.match(file_regex, o)
         else:
@@ -225,6 +226,16 @@  def do_split_packages(d, root, file_regex, output_pattern, description, postinst
             hook(f, pkg, file_regex, output_pattern, m.group(1))
 
     d.setVar('PACKAGES', ' '.join(packages))
+
+    variant = d.getVar("BBEXTENDVARIANT")
+    prefixes = (d.getVar("MULTILIB_VARIANTS") or "").split()
+    if variant and prefixes:
+        import oe.classextend
+
+        # Extend package variables for the given variant if unset
+        clsextend = oe.classextend.ClassExtender(variant, prefixes, d)
+        clsextend.rename_package_variables((d.getVar("PACKAGEVARS") or "").split(), overwrite=False)
+
     return list(split_packages)
 
 PACKAGE_DEPENDS += "file-native"
diff --git a/meta/lib/oe/classextend.py b/meta/lib/oe/classextend.py
index ddca10dee5..8b9602e316 100644
--- a/meta/lib/oe/classextend.py
+++ b/meta/lib/oe/classextend.py
@@ -128,7 +128,7 @@  class ClassExtender(object):
         self.set_filter("RCONFLICTS", deps=True)
         self.set_filter("PKG", deps=True)
 
-    def rename_package_variables(self, variables):
+    def rename_package_variables(self, variables, overwrite=True):
         pkgs_mapping = get_package_mappings(self.d.getVar('PACKAGES'), self.extname)
         self.d.setVarFilter('PACKAGES', "package_suffix_filter(val, '" + self.extname + "')")
         self.d.setVarFilter('PACKAGES_DYNAMIC', "suffix_filter_regex(val, '" + self.extname + "', " + str(self.prefixes) + ")")
@@ -137,4 +137,5 @@  class ClassExtender(object):
             if pkg_mapping[0].startswith("${") and pkg_mapping[0].endswith("}"):
                 continue
             for subs in variables:
-                self.d.renameVar("%s:%s" % (subs, pkg_mapping[0]), "%s:%s" % (subs, pkg_mapping[1]))
+                if overwrite or not self.d.getVar("%s:%s" % (subs, pkg_mapping[1])):
+                    self.d.renameVar("%s:%s" % (subs, pkg_mapping[0]), "%s:%s" % (subs, pkg_mapping[1]))