license: add 'any_incompatible' function
PATCH v2 1/1 license: add 'any_incompatible' function
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 ''}"--- 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.
meta/classes/license.bbclass +38 -0
@@ -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
meta/recipes-core/packagegroups/packagegroup-base.bb +2 -0
@@ -14,6 +14,8 @@ PACKAGES = ' \ packagegroup-distro-base \ packagegroup-machine-base \ \ + ${@"dbench" if not any_incompatible(d, "dbench", "GPL-3.0-only") else ""} \ + \ ${@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)} \
Signature · 1 line
2.34.1
PATCH 1/1 license: add 'any_incompatible' function
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 ''}"--- meta/classes/license.bbclass | 38 +++++++++++++++++++ .../packagegroups/packagegroup-base.bb | 2 + 2 files changed, 40 insertions(+)
meta/classes/license.bbclass +38 -0
@@ -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
meta/recipes-core/packagegroups/packagegroup-base.bb +2 -0
@@ -14,6 +14,8 @@ PACKAGES = ' \ packagegroup-distro-base \ packagegroup-machine-base \ \ + ${@"dbench" if not any_incompatible(d, "dbench", "GPL-3.0-only") else ""} \ + \ ${@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)} \
Signature · 1 line
2.34.1
Quoted 75 lines · Christopher Larson
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.meta/classes/license.bbclass +38
-0@@ -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 thatmeta/recipes-core/packagegroups/packagegroup-base.bb +0
-0
meta/recipes-core/packagegroups/packagegroup-base.bb PACKAGES = ' \ · line 21
Quoted 8 lines
meta/recipes-core/packagegroups/packagegroup-base.bb +2
-0@@ -14,6 +14,8 @@ PACKAGES = ' \ packagegroup-distro-base \ packagegroup-machine-base \ \ + ${@"dbench" if not any_incompatible(d, "dbench", "GPL-3.0-only") else ""} \ + \ ${@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
It’s just an example, but you’re right, I’ll change to a better one. Thanks!
--
Christopher Larson
[email protected], [email protected], [email protected] Principal Software Engineer, Embedded Linux Solutions, Siemens Digital Industries Software
Quoted 91 lines · On Apr 13, 2022, 10:44 AM -0700, Richard Purdie…
Quoted 75 lines · Christopher Larson
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.meta/classes/license.bbclass +38
-0@@ -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 anyLICENSE_FLAGSthatmeta/recipes-core/packagegroups/packagegroup-base.bb +0
-0meta/recipes-core/packagegroups/packagegroup-base.bb PACKAGES = ' \ · line 21
Quoted 8 lines
meta/recipes-core/packagegroups/packagegroup-base.bb +2
-0@@ -14,6 +14,8 @@ PACKAGES = ' \ packagegroup-distro-base \ packagegroup-machine-base \ \ + ${@"dbench" if not any_incompatible(d, "dbench", "GPL-3.0-only") else ""} \ + \ ${@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
Quoted 79 lines
-----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' functionQuoted 71 lines · Christopher Larson
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.meta/classes/license.bbclass +38
-0@@ -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 thatmeta/recipes-core/packagegroups/packagegroup-base.bb +0
-0
Quoted 8 lines
meta/recipes-core/packagegroups/packagegroup-base.bb PACKAGES = ' \ · line 17
Quoted 8 lines
index
7489ef61b0..1c97d03c21100644meta/recipes-core/packagegroups/packagegroup-base.bb +1
-0@@ -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. :(
Quoted 11 lines
meta/recipes-core/packagegroups/packagegroup-base.bb PACKAGES = ' \ · line 21
Quoted 4 lines
meta/recipes-core/packagegroups/packagegroup-base.bb +1
-0+ \ ${@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
Quoted 107 lines · Peter Kjellerstedt
Quoted 2 lines
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Richard Purdie
Quoted 2 lines
Sent: den 13 april 2022 19:45
To: Christopher Larson <[email protected]>;Quoted 2 lines
Cc: Christopher Larson <[email protected]>
Subject: Re: [OE-core] [PATCH v2] license: add 'any_incompatible'function
Quoted 3 lines · Christopher Larson
Quoted 1 line
This function returns True if any of the specified packages are
skipped due to
Quoted 3 lines
Quoted 3 lines
incompatible license.
License exceptions are obeyed. The user may specify the package's
license for
Quoted 3 lines
Quoted 3 lines
cross-recipe checks.
This allows for additions to packagegroups only for non-incompatible
builds. For
Quoted 3 lines
Quoted 3 lines
example:
RDEPENDS_${PN} += "${@'dbench' if not any_incompatible(d,'dbench', 'GPL-3.0-only') else ''}"
Quoted 9 lines
Quoted 9 lines
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 functiondocstring
Quoted 3 lines
Review
Quoted 3 lines
to avoid bitbake expanding it and recursing.
(quoted diff) +0
-0b/meta/classes/license.bbclass
Quoted 4 lines
meta/classes/license.bbclass def incompatible_license(d, dont_want_licenses,
Quoted 4 lines
index
0c637e966e..41993b7227100644meta/classes/license.bbclass +0
-0@@ -320,6 +320,44 @@ def incompatible_license(d, dont_want_licenses,package=None):
Quoted 5 lines
meta/classes/license.bbclass def incompatible_license(d, dont_want_licenses, package=None):
Quoted 5 lines
meta/classes/license.bbclass +2
-0return 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 toincompatible license.
Quoted 2 lines
meta/classes/license.bbclass def incompatible_license(d, dont_want_licenses, · line 325
Quoted 2 lines
meta/classes/license.bbclass +2
-0+ + License exceptions are obeyed. The user may specify the package'slicense
Quoted 3 lines
meta/classes/license.bbclass def incompatible_license(d, dont_want_licenses, package=None):
Quoted 3 lines
meta/classes/license.bbclass +3
-0+ for cross-recipe checks. + + This allows for additions to packagegroups only fornon-incompatible builds.
Quoted 2 lines
meta/classes/license.bbclass def incompatible_license(d, dont_want_licenses, · line 330
Quoted 2 lines
meta/classes/license.bbclass +2
-0+ + For example: 'dbench' if not any_incompatible(d, 'dbench','GPL-3.0-only') else ''
Quoted 5 lines
Quoted 5 lines
meta/classes/license.bbclass +5
-0+ """ + import oe.license + + if isinstance(packages, str): + packages = packages.split()Quoted 8 lines
meta/classes/license.bbclass def incompatible_license(d, dont_want_licenses, package=None):
Quoted 8 lines
meta/classes/license.bbclass +8
-0+ + 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 packageelse None
Quoted 4 lines
meta/classes/license.bbclass def incompatible_license(d, dont_want_licenses, package=None):
Quoted 4 lines
meta/classes/license.bbclass +4
-0+ if not licensestring: + licensestring = d.getVar("LICENSE") + + exceptions = (d.getVar("INCOMPATIBLE_LICENSE_EXCEPTIONS") or"").split()
Quoted 2 lines
meta/classes/license.bbclass def incompatible_license(d, dont_want_licenses, · line 349
Quoted 2 lines
meta/classes/license.bbclass +2
-0+ for pkg in packages: + remaining_bad_licenses =oe.license.apply_pkg_license_exception(
Quoted 6 lines
Quoted 6 lines
meta/classes/license.bbclass +6
-0+ pkg, bad_licenses, exceptions + ) + + incompatible_lic = incompatible_pkg_license( + d, remaining_bad_licenses, licensestring + )Quoted 8 lines
Review
Quoted 8 lines
meta/classes/license.bbclass +4
-0+ if incompatible_lic: + return True + return False + def check_license_flags(d): """ This function checks if a recipe has any LICENSE_FLAGS that(quoted diff) +0
-0b/meta/recipes-core/packagegroups/packagegroup-base.bb
Quoted 8 lines
meta/recipes-core/packagegroups/packagegroup-base.bb PACKAGES = ' \ · line 17
Quoted 8 lines
index
7489ef61b0..1c97d03c21100644meta/recipes-core/packagegroups/packagegroup-base.bb +1
-0@@ -14,6 +14,8 @@ PACKAGES = ' \ packagegroup-distro-base \ packagegroup-machine-base \ \ + ${@"dbench" if not any_incompatible(d, "dbench","GPL-3.0-only") else ""} \
Quoted 3 lines
This usage seems error prone at best. What if the license for dbench is changed?
It is, but we can't know other recipes licenses, so the options are limited. It's also not the only similar thing we do along these lines. More than once we've had to exclude something from a packagegroup based on the current context and our knowledge that it's not buildable in this context, such as knowing the required distro features of the recipe or its unsupported architectures or COMPATIBLE_MACHINE.
I don't love it, but I don't see a lot of alternatives. RRECOMMENDS is an interesting idea, but I don't believe it works as you'd hope today, and would presumably require use of BAD_RECOMMENDATIONS for pickier images. I'm certainly open to the alternatives on this, but in the meantime some images/packagegroups just aren't buildable at all for incompatible_license builds right now without risking layer-inclusion-based tweaks in meta-gplv2.
Quoted 3 lines
I suspect you didn't mean to include this piece since dbench isn't in
Quoted 1 line
core?
Indeed, v3 forthcoming. Thanks!
Signature · 4 lines
Christopher Larson [email protected], [email protected], [email protected] Principal Software Engineer, Embedded Linux Solutions, Siemens Digital Industries Software
Quoted 6 lines · Peter Kjellerstedt
Quoted 1 line
Quoted 1 line
+ ${@"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?
Quoted 7 lines
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.
The issue is, a missing RRECOMMENDS will currently abort the build. Bitbake doesn't treat RRECOMMENDS as optional to build, only optional to install, so this approach is not viable. I'm still submitting v3 of this to get the job done for now. Thanks for your thoughts, though, I actually agree that your idea is a better method, it just doesn't work with bitbake as it stands today!
Signature · 4 lines
Christopher Larson [email protected], [email protected], [email protected] Principal Software Engineer, Embedded Linux Solutions, Siemens Digital Industries Software