lib/oe/qa,insane: Move extra error handling functions to library
PATCH v5 1/2 lib/oe/qa,insane: Move extra error handling functions to library
Extract package_qa_write_error, package_qa_handle_error and package_qa_add_message functions from insane.bbclass to lib/oe/qa.py and drop the package_qa_ prefixes.
Update various bbclasses to use the new functions. No import is required since base.bbclass puts oe.qa in OE_IMPORTS.
Stop requiring callers to manually track whether a fatal error has been encountered via a "sane" flag. Instead replace the QA_SANE variable with QA_ERRORS_FOUND and call oe.qa.exit_if_errors or oe.qa.exit_with_message_if_errors at the end of each task.
Inspired by discussion resulting from
https://lists.openembedded.org/g/openembedded-core/message/156793 and
https://lists.openembedded.org/g/openembedded-core/message/156900
--- meta/classes/buildhistory.bbclass | 3 +- meta/classes/insane.bbclass | 180 ++++++++++++------------------ meta/classes/multilib.bbclass | 3 +- meta/classes/package.bbclass | 26 ++--- meta/classes/ptest.bbclass | 2 +- meta/lib/oe/qa.py | 34 ++++++ 6 files changed, 120 insertions(+), 128 deletions(-)
meta/classes/buildhistory.bbclass +2 -1
@@ -287,7 +287,7 @@ python buildhistory_emit_pkghistory() { r = bb.utils.vercmp((pkge, pkgv, pkgr), (last_pkge, last_pkgv, last_pkgr)) if r < 0: msg = "Package version for package %s went backwards which would break package feeds (from %s:%s-%s to %s:%s-%s)" % (pkg, last_pkge, last_pkgv, last_pkgr, pkge, pkgv, pkgr) - package_qa_handle_error("version-going-backwards", msg, d) + oe.qa.handle_error("version-going-backwards", msg, d) pkginfo = PackageInfo(pkg) # Apparently the version can be different on a per-package basis (see Python)
@@ -321,6 +321,7 @@ python buildhistory_emit_pkghistory() { # Create files-in-<package-name>.txt files containing a list of files of each recipe's package bb.build.exec_func("buildhistory_list_pkg_files", d) + oe.qa.exit_if_errors(d) } python buildhistory_emit_outputsigs() {
meta/classes/insane.bbclass +70 -110
552 lines not on this page · raw message
meta/classes/multilib.bbclass +2 -1
@@ -210,7 +210,7 @@ python do_package_qa_multilib() { if len(candidates) > 0: msg = "%s package %s - suspicious values '%s' in %s" \ % (d.getVar('PN'), pkg, ' '.join(candidates), var) - package_qa_handle_error("multilib", msg, d) + oe.qa.handle_error("multilib", msg, d) ml = d.getVar('MLPREFIX') if not ml:
@@ -228,4 +228,5 @@ python do_package_qa_multilib() { check_mlprefix(pkg, 'RSUGGESTS', ml) check_mlprefix(pkg, 'RREPLACES', ml) check_mlprefix(pkg, 'RCONFLICTS', ml) + oe.qa.exit_if_errors(d) }
meta/classes/package.bbclass +11 -15
@@ -41,8 +41,6 @@ inherit packagedata inherit chrpath inherit package_pkgdata - -# Need the package_qa_handle_error() in insane.bbclass inherit insane PKGD = "${WORKDIR}/package"
@@ -865,7 +863,7 @@ python fixup_perms () { self._setdir(lsplit[0], lsplit[1], lsplit[2], lsplit[3], lsplit[4], lsplit[5], lsplit[6], lsplit[7]) else: msg = "Fixup Perms: invalid config line %s" % line - package_qa_handle_error("perm-config", msg, d) + oe.qa.handle_error("perm-config", msg, d) self.path = None self.link = None
@@ -1005,7 +1003,7 @@ python fixup_perms () { continue if len(lsplit) != 8 and not (len(lsplit) == 3 and lsplit[1].lower() == "link"): msg = "Fixup perms: %s invalid line: %s" % (conf, line) - package_qa_handle_error("perm-line", msg, d) + oe.qa.handle_error("perm-line", msg, d) continue entry = fs_perms_entry(d.expand(line)) if entry and entry.path:
@@ -1042,7 +1040,7 @@ python fixup_perms () { ptarget = os.path.join(os.path.dirname(dir), link) if os.path.exists(target): msg = "Fixup Perms: Unable to correct directory link, target already exists: %s -> %s" % (dir, ptarget) - package_qa_handle_error("perm-link", msg, d) + oe.qa.handle_error("perm-link", msg, d) continue # Create path to move directory to, move it, and then setup the symlink
@@ -1202,7 +1200,7 @@ python split_and_strip_files () { bb.note("Skipping file %s from %s for already-stripped QA test" % (file[len(dvar):], pn)) else: msg = "File '%s' from %s was already stripped, this will prevent future debugging!" % (file[len(dvar):], pn) - package_qa_handle_error("already-stripped", msg, d) + oe.qa.handle_error("already-stripped", msg, d) continue # At this point we have an unstripped elf file. We need to:
@@ -1362,7 +1360,7 @@ python populate_packages () { for i, pkg in enumerate(packages): if pkg in package_dict: msg = "%s is listed in PACKAGES multiple times, this leads to packaging errors." % pkg - package_qa_handle_error("packages-list", msg, d) + oe.qa.handle_error("packages-list", msg, d) # Ensure the source package gets the chance to pick up the source files # before the debug package by ordering it first in PACKAGES. Whether it # actually picks up any source files is controlled by
@@ -1399,7 +1397,7 @@ python populate_packages () { filesvar = d.getVar('FILES:%s' % pkg) or "" if "//" in filesvar: msg = "FILES variable for package %s contains '//' which is invalid. Attempting to fix this but you should correct the metadata.\n" % pkg - package_qa_handle_error("files-invalid", msg, d) + oe.qa.handle_error("files-invalid", msg, d) filesvar.replace("//", "/") origfiles = filesvar.split()
@@ -1468,7 +1466,7 @@ python populate_packages () { licenses = d.getVar('LICENSE_EXCLUSION-' + pkg) if licenses: msg = "Excluding %s from packaging as it has incompatible license(s): %s" % (pkg, licenses) - package_qa_handle_error("incompatible-license", msg, d) + oe.qa.handle_error("incompatible-license", msg, d) else: package_list.append(pkg) d.setVar('PACKAGES', ' '.join(package_list))
@@ -1492,7 +1490,7 @@ python populate_packages () { msg = msg + "\n " + f msg = msg + "\nPlease set FILES such that these items are packaged. Alternatively if they are unneeded, avoid installing them or delete them within do_install.\n" msg = msg + "%s: %d installed and not shipped files." % (pn, len(unshipped)) - package_qa_handle_error("installed-vs-shipped", msg, d) + oe.qa.handle_error("installed-vs-shipped", msg, d) } populate_packages[dirs] = "${D}"
@@ -1838,7 +1836,7 @@ python package_do_shlibs() { ver = d.getVar('PKGV') if not ver: msg = "PKGV not defined" - package_qa_handle_error("pkgv-undefined", msg, d) + oe.qa.handle_error("pkgv-undefined", msg, d) return pkgdest = d.getVar('PKGDEST')
@@ -2402,7 +2400,7 @@ python do_package () { if not workdir or not outdir or not dest or not dvar or not pn: msg = "WORKDIR, DEPLOY_DIR, D, PN and PKGD all must be defined, unable to package" - package_qa_handle_error("var-undefined", msg, d) + oe.qa.handle_error("var-undefined", msg, d) return bb.build.exec_func("package_convert_pr_autoinc", d)
@@ -2455,9 +2453,7 @@ python do_package () { for f in (d.getVar('PACKAGEFUNCS') or '').split(): bb.build.exec_func(f, d) - qa_sane = d.getVar("QA_SANE") - if not qa_sane: - bb.fatal("Fatal QA errors found, failing task.") + oe.qa.exit_if_errors(d) } do_package[dirs] = "${SHLIBSWORKDIR} ${PKGDESTWORK} ${D}"
meta/classes/ptest.bbclass +1 -1
@@ -129,4 +129,4 @@ def package_qa_check_missing_ptest(pn, d, messages): enabled_ptests = " ".join([d.getVar('PTESTS_FAST'), d.getVar('PTESTS_SLOW'), d.getVar('PTESTS_PROBLEMS')]).split() if (pn + "-ptest").replace(d.getVar('MLPREFIX'), '') not in enabled_ptests: - package_qa_handle_error("missing-ptest", "supports ptests but is not included in oe-core's ptest-packagelists.inc", d) + oe.qa.handle_error("missing-ptest", "supports ptests but is not included in oe-core's ptest-packagelists.inc", d)
meta/lib/oe/qa.py +34 -0
@@ -171,6 +171,40 @@ def elf_machine_to_string(machine): except: return "Unknown (%s)" % repr(machine) +def write_error(type, error, d): + logfile = d.getVar('QA_LOGFILE') + if logfile: + p = d.getVar('P') + with open(logfile, "a+") as f: + f.write("%s: %s [%s]\n" % (p, error, type)) + +def handle_error(error_class, error_msg, d): + if error_class in (d.getVar("ERROR_QA") or "").split(): + write_error(error_class, error_msg, d) + bb.error("QA Issue: %s [%s]" % (error_msg, error_class)) + d.setVar("QA_ERRORS_FOUND", "True") + return False + elif error_class in (d.getVar("WARN_QA") or "").split(): + write_error(error_class, error_msg, d) + bb.warn("QA Issue: %s [%s]" % (error_msg, error_class)) + else: + bb.note("QA Issue: %s [%s]" % (error_msg, error_class)) + return True + +def add_message(messages, section, new_msg): + if section not in messages: + messages[section] = new_msg + else: + messages[section] = messages[section] + "\n" + new_msg + +def exit_with_message_if_errors(message, d): + qa_fatal_errors = bb.utils.to_boolean(d.getVar("QA_ERRORS_FOUND"), False) + if qa_fatal_errors: + bb.fatal(message) + +def exit_if_errors(d): + exit_with_message_if_errors("Fatal QA errors were found, failing task.", d) + if __name__ == "__main__": import sys
Signature · 1 line
2.30.2
PATCH v5 2/2 insane,license,license_image: Allow treating license problems as errors
Use the same WARN_WA and ERROR_QA variables as insane.bbclass to allow individual recipes, the distro or other configuration to determine whether the various detected license errors should be treated as a warning (as now) or as an error.
oe.qa.handle_error isn't immediately fatal, so oe.qa.exit_if_errors must be called at the end of do_populate_lic to fail the task.
--- meta/classes/insane.bbclass | 2 ++ meta/classes/license.bbclass | 20 +++++++++++++------- meta/classes/license_image.bbclass | 11 ++++++----- 3 files changed, 21 insertions(+), 12 deletions(-)
meta/classes/insane.bbclass +2 -0
@@ -26,6 +26,8 @@ WARN_QA ?= " libdir xorg-driver-abi \ invalid-packageconfig host-user-contaminated uppercase-pn patch-fuzz \ mime mime-xdg unlisted-pkg-lics unhandled-features-check \ missing-update-alternatives native-last missing-ptest \ + license-exists license-no-generic license-syntax license-format \ + license-incompatible license-file-missing \ " ERROR_QA ?= "dev-so debug-deps dev-deps debug-files arch pkgconfig la \ perms dep-cmp pkgvarcheck perm-config perm-line perm-link \
meta/classes/license.bbclass +13 -7
@@ -29,6 +29,7 @@ python do_populate_lic() { with open(os.path.join(destdir, "recipeinfo"), "w") as f: for key in sorted(info.keys()): f.write("%s: %s\n" % (key, info[key])) + oe.qa.exit_if_errors(d) } PSEUDO_IGNORE_PATHS .= ",${@','.join(((d.getVar('COMMON_LICENSE_DIR') or '') + ' ' + (d.getVar('LICENSE_PATH') or '') + ' ' + d.getVar('COREBASE') + '/meta/COPYING').split())}"
@@ -182,7 +183,8 @@ def find_license_files(d): # The user may attempt to use NO_GENERIC_LICENSE for a generic license which doesn't make sense # and should not be allowed, warn the user in this case. if d.getVarFlag('NO_GENERIC_LICENSE', license_type): - bb.warn("%s: %s is a generic license, please don't use NO_GENERIC_LICENSE for it." % (pn, license_type)) + oe.qa.handle_error("license-no-generic", + "%s: %s is a generic license, please don't use NO_GENERIC_LICENSE for it." % (pn, license_type), d) elif non_generic_lic and non_generic_lic in lic_chksums: # if NO_GENERIC_LICENSE is set, we copy the license files from the fetched source
@@ -194,7 +196,8 @@ 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)) + oe.qa.handle_error("license-exists", + "%s: No generic license file exists for: %s in any provider" % (pn, license_type), d) pass if not generic_directory:
@@ -219,7 +222,8 @@ def find_license_files(d): except oe.license.InvalidLicense as exc: bb.fatal('%s: %s' % (d.getVar('PF'), exc)) except SyntaxError: - bb.warn("%s: Failed to parse it's LICENSE field." % (d.getVar('PF'))) + oe.qa.handle_error("license-syntax", + "%s: Failed to parse it's LICENSE field." % (d.getVar('PF')), d) # Add files from LIC_FILES_CHKSUM to list of license files lic_chksum_paths = defaultdict(OrderedDict) for path, data in sorted(lic_chksums.items()):
@@ -410,14 +414,16 @@ def check_license_format(d): for pos, element in enumerate(elements): if license_pattern.match(element): if pos > 0 and license_pattern.match(elements[pos - 1]): - bb.warn('%s: LICENSE value "%s" has an invalid format - license names ' \ + oe.qa.handle_error('license-format', + '%s: LICENSE value "%s" has an invalid format - license names ' \ 'must be separated by the following characters to indicate ' \ 'the license selection: %s' % - (pn, licenses, license_operator_chars)) + (pn, licenses, license_operator_chars), d) elif not license_operator.match(element): - bb.warn('%s: LICENSE value "%s" has an invalid separator "%s" that is not ' \ + oe.qa.handle_error('license-format', + '%s: LICENSE value "%s" has an invalid separator "%s" that is not ' \ 'in the valid list of separators (%s)' % - (pn, licenses, element, license_operator_chars)) + (pn, licenses, element, license_operator_chars), d) SSTATETASKS += "do_populate_lic" do_populate_lic[sstate-inputdirs] = "${LICSSTATEDIR}"
meta/classes/license_image.bbclass +6 -5
@@ -75,7 +75,7 @@ def write_license_files(d, license_manifest, pkg_dic, rootfs=True): pkg_dic[pkg]["LICENSES"] = re.sub(r' *', ' ', pkg_dic[pkg]["LICENSES"]) pkg_dic[pkg]["LICENSES"] = pkg_dic[pkg]["LICENSES"].split() if pkg in whitelist: - bb.warn("Including %s with an incompatible license %s into the image, because it has been whitelisted." %(pkg, pkg_dic[pkg]["LICENSE"])) + oe.qa.handle_error('license-incompatible', "Including %s with an incompatible license %s into the image, because it has been whitelisted." %(pkg, pkg_dic[pkg]["LICENSE"]), d) if not "IMAGE_MANIFEST" in pkg_dic[pkg]: # Rootfs manifest
@@ -105,10 +105,10 @@ def write_license_files(d, license_manifest, pkg_dic, rootfs=True): continue if not os.path.exists(lic_file): - bb.warn("The license listed %s was not in the "\ - "licenses collected for recipe %s" - % (lic, pkg_dic[pkg]["PN"])) - + oe.qa.handle_error('license-file-missing', + "The license listed %s was not in the "\ + "licenses collected for recipe %s" + % (lic, pkg_dic[pkg]["PN"]), d) # Two options here: # - Just copy the manifest # - Copy the manifest and the license directories
@@ -274,6 +274,7 @@ do_rootfs[recrdeptask] += "do_populate_lic" python do_populate_lic_deploy() { license_deployed_manifest(d) + oe.qa.exit_if_errors(d) } addtask populate_lic_deploy before do_build after do_image_complete
Signature · 1 line
2.30.2
Quoted 17 lines · Mike Crowe via lists.openembedded.org
Extract
package_qa_write_error,package_qa_handle_errorandpackage_qa_add_messagefunctions from insane.bbclass tolib/oe/qa.pyand drop thepackage_qa_prefixes.Update various bbclasses to use the new functions. No import is required since base.bbclass puts oe.qa in
OE_IMPORTS.Stop requiring callers to manually track whether a fatal error has been encountered via a "sane" flag. Instead replace the
QA_SANEvariable withQA_ERRORS_FOUNDand call oe.qa.exit_if_errors or oe.qa.exit_with_message_if_errors at the end of each task.Inspired by discussion resulting from
https://lists.openembedded.org/g/openembedded-core/message/156793 and
https://lists.openembedded.org/g/openembedded-core/message/156900Signed-off-by Mike Crowe <[email protected]>
Quoted 8 lines
--- meta/classes/buildhistory.bbclass | 3 +- meta/classes/insane.bbclass | 180 ++++++++++++------------------ meta/classes/multilib.bbclass | 3 +- meta/classes/package.bbclass | 26 ++--- meta/classes/ptest.bbclass | 2 +- meta/lib/oe/qa.py | 34 ++++++ 6 files changed, 120 insertions(+), 128 deletions(-)
There was an indentation issue with multilib.bbclass but I fixed that and now have merged this, thanks.
I think you are right about there being legacy reasons for collecting up the messages and the "sane" variable tracking so if you are feeling keen (or anyone else is) further cleanup of this code is very welcome.
Cheers,
Richard