license: Allow treating missing license as error
PATCH 1/1 license: Allow treating missing license as error
Use mechanism inspired by insane.bbclass to allow individual recipes or other configuration to determine whether a missing licence should be treated as a warning (as it is now) or as an error. This is controlled by whether the error class is in WARN_LICENSE or ERROR_LICENSE.
Use bb.fatal in the error case to ensure that the task really fails. If only bb.error is used then do_populate_lic isn't re-run on subsequent builds which could lead to the error being missed.
--- meta/classes/license.bbclass | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
meta/classes/license.bbclass +18 -1
@@ -12,6 +12,23 @@ LICENSE_CREATE_PACKAGE ??= "0" LICENSE_PACKAGE_SUFFIX ??= "-lic" LICENSE_FILES_DIRECTORY ??= "${datadir}/licenses/" +# Elect whether a given type of error is a warning or error, they may +# have been set by other files. +WARN_LICENSE ?= "no-license" +ERROR_LICENSE ?= "" +WARN_LICENSE[doc] = "Space-separated list of license problems that should be reported only as warnings" +ERROR_LICENSE[doc] = "Space-separated list of license problems that should be reported as errors" + +def package_license_handle_error(error_class, error_msg, d): + if error_class in (d.getVar("ERROR_LICENSE") or "").split(): + package_qa_write_error(error_class, error_msg, d) + bb.fatal("License Issue: %s [%s]" % (error_msg, error_class)) + elif error_class in (d.getVar("WARN_LICENSE") or "").split(): + package_qa_write_error(error_class, error_msg, d) + bb.warn("License Issue: %s [%s]" % (error_msg, error_class)) + else: + bb.note("QA Issue: %s [%s]" % (error_msg, error_class)) + addtask populate_lic after do_patch before do_build do_populate_lic[dirs] = "${LICSSTATEDIR}/${PN}" do_populate_lic[cleandirs] = "${LICSSTATEDIR}"
@@ -190,7 +207,7 @@ def find_license_files(d): # Add explicity avoid of CLOSED license because this isn't generic if license_type != 'CLOSED': # And here is where we warn people that their licenses are lousy - bb.warn("%s: No generic license file exists for: %s in any provider" % (pn, license_type)) + package_license_handle_error("no-license", "%s: No generic license file exists for: %s in any provider" % (pn, license_type), d) pass if not generic_directory:
Signature · 1 line
2.30.2
Quoted 38 lines
-----Original Message-----
From: [email protected] <openembedded- [email protected]> On Behalf Of Mike Crowe via lists.openembedded.org
Sent: den 8 oktober 2021 10:54
To: [email protected]
Cc: Mike Crowe <[email protected]>
Subject: [OE-core] [PATCH] license: Allow treating missing license as errorUse mechanism inspired by insane.bbclass to allow individual recipes or other configuration to determine whether a missing licence should be treated as a warning (as it is now) or as an error. This is controlled by whether the error class is in
WARN_LICENSEorERROR_LICENSE.Use bb.fatal in the error case to ensure that the task really fails. If only bb.error is used then
do_populate_licisn't re-run on subsequent builds which could lead to the error being missed.Signed-off-by Mike Crowe <[email protected]>--- meta/classes/license.bbclass | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)meta/classes/license.bbclass +6
-0@@ -12,6 +12,23 @@ LICENSE_CREATE_PACKAGE ??= "0" LICENSE_PACKAGE_SUFFIX ??= "-lic" LICENSE_FILES_DIRECTORY ??= "${datadir}/licenses/" +# Elect whether a given type of error is a warning or error, they may +# have been set by other files. +WARN_LICENSE ?= "no-license" +ERROR_LICENSE ?= "" +WARN_LICENSE[doc] = "Space-separated list of license problems that should be reported only as warnings" +ERROR_LICENSE[doc] = "Space-separated list of license problems that should be reported as errors"
meta/classes/license.bbclass LICENSE_CREATE_PACKAGE ??= "0" · line 30
Quoted 10 lines
meta/classes/license.bbclass +10
-0+ +def package_license_handle_error(error_class, error_msg, d): + if error_class in (d.getVar("ERROR_LICENSE") or "").split(): + package_qa_write_error(error_class, error_msg, d) + bb.fatal("License Issue: %s [%s]" % (error_msg, error_class)) + elif error_class in (d.getVar("WARN_LICENSE") or "").split(): + package_qa_write_error(error_class, error_msg, d) + bb.warn("License Issue: %s [%s]" % (error_msg, error_class)) + else: + bb.note("QA Issue: %s [%s]" % (error_msg, error_class))
Change "QA Issue" to "License Issue" for consistency.
Quoted 14 lines
meta/classes/license.bbclass +2
-2+ addtask populate_lic after do_patch before do_build do_populate_lic[dirs] = "${LICSSTATEDIR}/${PN}" do_populate_lic[cleandirs] = "${LICSSTATEDIR}"@@ -190,7 +207,7 @@ def find_license_files(d): # Add explicity avoid of CLOSED license because this isn't generic if license_type != 'CLOSED': # And here is where we warn people that their licenses are lousy - bb.warn("%s: No generic license file exists for: %s in any provider" % (pn, license_type)) + package_license_handle_error("no-license", "%s: No generic license file exists for: %s in any provider" % (pn, license_type), d) pass if not generic_directory: --
Quoted 1 line
2.30.2
//Peter
Quoted 42 lines · Peter Kjellerstedt
Quoted 42 lines
-----Original Message-----
From: [email protected] <openembedded- [email protected]> On Behalf Of Mike Crowe via lists.openembedded.org
Sent: den 8 oktober 2021 10:54
To: [email protected]
Cc: Mike Crowe <[email protected]>
Subject: [OE-core] [PATCH] license: Allow treating missing license as errorUse mechanism inspired by insane.bbclass to allow individual recipes or other configuration to determine whether a missing licence should be treated as a warning (as it is now) or as an error. This is controlled by whether the error class is in
WARN_LICENSEorERROR_LICENSE.Use bb.fatal in the error case to ensure that the task really fails. If only bb.error is used then
do_populate_licisn't re-run on subsequent builds which could lead to the error being missed.Signed-off-by Mike Crowe <[email protected]>--- meta/classes/license.bbclass | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)meta/classes/license.bbclass +10
-0@@ -12,6 +12,23 @@ LICENSE_CREATE_PACKAGE ??= "0" LICENSE_PACKAGE_SUFFIX ??= "-lic" LICENSE_FILES_DIRECTORY ??= "${datadir}/licenses/" +# Elect whether a given type of error is a warning or error, they may +# have been set by other files. +WARN_LICENSE ?= "no-license" +ERROR_LICENSE ?= "" +WARN_LICENSE[doc] = "Space-separated list of license problems that should be reported only as warnings" +ERROR_LICENSE[doc] = "Space-separated list of license problems that should be reported as errors" + +def package_license_handle_error(error_class, error_msg, d): + if error_class in (d.getVar("ERROR_LICENSE") or "").split(): + package_qa_write_error(error_class, error_msg, d)
Quoted 8 lines
meta/classes/license.bbclass LICENSE_CREATE_PACKAGE ??= "0" · line 30
Quoted 6 lines
meta/classes/license.bbclass +6
-0+ bb.fatal("License Issue: %s [%s]" % (error_msg, error_class)) + elif error_class in (d.getVar("WARN_LICENSE") or "").split(): + package_qa_write_error(error_class, error_msg, d) + bb.warn("License Issue: %s [%s]" % (error_msg, error_class)) + else: + bb.note("QA Issue: %s [%s]" % (error_msg, error_class))Change "QA Issue" to "License Issue" for consistency.
Whoops. Thanks for spotting that. I've posted v2 with it fixed.
Mike.