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