> -----Original Message-----
> From: [email protected] 
> <[email protected]> On Behalf Of Richard Purdie
> Sent: den 13 april 2022 19:45
> To: Christopher Larson <[email protected]>; 
> [email protected]
> Cc: Christopher Larson <[email protected]>
> Subject: Re: [OE-core] [PATCH v2] license: add 'any_incompatible' function
> 
> On Wed, 2022-04-13 at 16:00 +0000, Christopher Larson wrote:
> > This function returns True if any of the specified packages are skipped due 
> > to
> > incompatible license.
> >
> > License exceptions are obeyed. The user may specify the package's license 
> > for
> > cross-recipe checks.
> >
> > This allows for additions to packagegroups only for non-incompatible 
> > builds. For
> > example:
> >
> >     RDEPENDS_${PN} += "${@'dbench' if not any_incompatible(d, 'dbench', 
> > 'GPL-3.0-only') else ''}"
> >
> > Signed-off-by: Christopher Larson <[email protected]>
> > ---
> >  meta/classes/license.bbclass                  | 38 +++++++++++++++++++
> >  .../packagegroups/packagegroup-base.bb        |  2 +
> >  2 files changed, 40 insertions(+)
> >
> > v2 changes: fixed string packages logic, corrected reference to
> > apply_pkg_license_exception, and avoided use of ${@} in the function 
> > docstring
> > to avoid bitbake expanding it and recursing.
> >
> > diff --git a/meta/classes/license.bbclass b/meta/classes/license.bbclass
> > index 0c637e966e..41993b7227 100644
> > --- a/meta/classes/license.bbclass
> > +++ b/meta/classes/license.bbclass
> > @@ -320,6 +320,44 @@ def incompatible_license(d, dont_want_licenses, 
> > package=None):
> >
> >      return incompatible_pkg_license(d, dont_want_licenses, license)
> >
> > +def any_incompatible(d, packages, licensestring=None):
> > +    """Return True if any of the packages are skipped due to incompatible 
> > license.
> > +
> > +    License exceptions are obeyed. The user may specify the package's 
> > license
> > +    for cross-recipe checks.
> > +
> > +    This allows for additions to packagegroups only for non-incompatible 
> > builds.
> > +
> > +    For example: 'dbench' if not any_incompatible(d, 'dbench', 
> > 'GPL-3.0-only') else ''
> > +    """
> > +    import oe.license
> > +
> > +    if isinstance(packages, str):
> > +        packages = packages.split()
> > +
> > +    bad_licenses = (d.getVar("INCOMPATIBLE_LICENSE") or "").split()
> > +    if not bad_licenses:
> > +        return False
> > +    bad_licenses = expand_wildcard_licenses(d, bad_licenses)
> > +
> > +    if licensestring is None:
> > +        licensestring = d.getVar("LICENSE:%s" % package) if package else 
> > None
> > +        if not licensestring:
> > +            licensestring = d.getVar("LICENSE")
> > +
> > +    exceptions = (d.getVar("INCOMPATIBLE_LICENSE_EXCEPTIONS") or 
> > "").split()
> > +    for pkg in packages:
> > +        remaining_bad_licenses = oe.license.apply_pkg_license_exception(
> > +            pkg, bad_licenses, exceptions
> > +        )
> > +
> > +        incompatible_lic = incompatible_pkg_license(
> > +            d, remaining_bad_licenses, licensestring
> > +        )
> > +        if incompatible_lic:
> > +            return True
> > +    return False
> > +
> >  def check_license_flags(d):
> >      """
> >      This function checks if a recipe has any LICENSE_FLAGS that
> > diff --git a/meta/recipes-core/packagegroups/packagegroup-base.bb 
> > b/meta/recipes-core/packagegroups/packagegroup-base.bb
> > index 7489ef61b0..1c97d03c21 100644
> > --- a/meta/recipes-core/packagegroups/packagegroup-base.bb
> > +++ b/meta/recipes-core/packagegroups/packagegroup-base.bb
> > @@ -14,6 +14,8 @@ PACKAGES = ' \
> >              packagegroup-distro-base \
> >              packagegroup-machine-base \
> >              \
> > +            ${@"dbench" if not any_incompatible(d, "dbench", 
> > "GPL-3.0-only") else ""} \

This usage seems error prone at best. What if the license for dbench 
is changed?

Also, the way I would prefer to do something like the above (assuming you 
meant to include it as a dependency in RDEPENDS:${PN} rather than PACKAGES) 
would be to instead unconditionally add it to RRECOMMENDS:${PN}. Then 
the normal licensing support should skip the package if you have the 
incompatible license globally configured, but since it is only a 
recommendation, that should not be a problem. 

However, one thing I just realized that isn't working is if you have a 
recommendation on a package and then only configure incompatible licenses 
per image. This is normally the preferred way to handle incompatible 
licenses as you can determine per image if a package should be allowed to 
be installed or not. But because the installation of the packages is 
handled by the package manager, and the license compliance is handled 
later by bitbake, there is currently nothing telling the package manager 
to skip the installation of the unwanted package due to its license, and 
instead there is an error because bitbake sees that it was installed. :(

> > +            \
> >              ${@bb.utils.contains("MACHINE_FEATURES", "acpi", 
> > "packagegroup-base-acpi", "",d)} \
> >              ${@bb.utils.contains("MACHINE_FEATURES", "alsa", 
> > "packagegroup-base-alsa", "", d)} \
> >              ${@bb.utils.contains("MACHINE_FEATURES", "apm", 
> > "packagegroup-base-apm", "", d)} \
> 
> I suspect you didn't mean to include this piece since dbench isn't in
> core?
> 
> Cheers,
> 
> Richard

//Peter
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#164365): 
https://lists.openembedded.org/g/openembedded-core/message/164365
Mute This Topic: https://lists.openembedded.org/mt/90443891/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to