yocto-check-layer.bbclass 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: MIT
  5. #
  6. # This class is used by the yocto-check-layer script for additional
  7. # per-recipe tests.
  8. #
  9. # It adds an anonymous python function with extra processing to all recipes,
  10. # globally inheriting this class isn't advisable - yocto-check-layer script
  11. # handles that during its signature dump
  12. # Ensure that recipes don't skip required QA checks as listed
  13. # in CHECKLAYER_REQUIRED_TESTS, defined by insane.bbclass
  14. def check_insane_skip(d):
  15. required_tests = set((d.getVar('CHECKLAYER_REQUIRED_TESTS') or '').split())
  16. packages = set((d.getVar('PACKAGES') or '').split())
  17. for package in packages:
  18. skip = set((d.getVar('INSANE_SKIP') or "").split() +
  19. (d.getVar('INSANE_SKIP:' + package) or "").split())
  20. skip_required = skip & required_tests
  21. if skip_required:
  22. oe.qa.write_error(" ".join(skip_required), 'Package %s is skipping required QA tests.' % package, d)
  23. bb.error("QA Issue: %s [%s]" % ('Package %s is skipping required QA tests.' % package, " ".join(skip_required)))
  24. d.setVar("QA_ERRORS_FOUND", "True")
  25. # Check that no tasks (with rare exceptions) between do_fetch and do_build
  26. # use the network.
  27. def check_network_flag(d):
  28. # BPN:task names that are allowed to reach the network, using fnmatch to compare.
  29. allowed = []
  30. # build-appliance-image uses pip at image time
  31. allowed += ["build-appliance-image:do_image"]
  32. def is_allowed(bpn, task):
  33. from fnmatch import fnmatch
  34. name = f"{bpn}:{task}"
  35. return any(fnmatch(name, pattern) for pattern in allowed)
  36. bpn = d.getVar("BPN")
  37. seen = set()
  38. stack = {"do_build"}
  39. while stack:
  40. task = stack.pop()
  41. if task == "do_fetch":
  42. continue
  43. seen.add(task)
  44. deps = d.getVarFlag(task, "deps") or []
  45. stack |= {d for d in deps if d not in seen}
  46. network = bb.utils.to_boolean(d.getVarFlag(task, "network"))
  47. if network and not is_allowed(bpn, task):
  48. bb.error(f"QA Issue: task {task} has network enabled")
  49. python () {
  50. check_insane_skip(d)
  51. check_network_flag(d)
  52. }