diff options
Diffstat (limited to 'meta/classes-recipe/ptest.bbclass')
-rw-r--r-- | meta/classes-recipe/ptest.bbclass | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/meta/classes-recipe/ptest.bbclass b/meta/classes-recipe/ptest.bbclass new file mode 100644 index 0000000000..0383206a6d --- /dev/null +++ b/meta/classes-recipe/ptest.bbclass | |||
@@ -0,0 +1,142 @@ | |||
1 | # | ||
2 | # Copyright OpenEmbedded Contributors | ||
3 | # | ||
4 | # SPDX-License-Identifier: MIT | ||
5 | # | ||
6 | |||
7 | SUMMARY:${PN}-ptest ?= "${SUMMARY} - Package test files" | ||
8 | DESCRIPTION:${PN}-ptest ?= "${DESCRIPTION} \ | ||
9 | This package contains a test directory ${PTEST_PATH} for package test purposes." | ||
10 | |||
11 | PTEST_PATH ?= "${libdir}/${BPN}/ptest" | ||
12 | PTEST_BUILD_HOST_FILES ?= "Makefile" | ||
13 | PTEST_BUILD_HOST_PATTERN ?= "" | ||
14 | PTEST_PARALLEL_MAKE ?= "${PARALLEL_MAKE}" | ||
15 | PTEST_PARALLEL_MAKEINST ?= "${PARALLEL_MAKEINST}" | ||
16 | EXTRA_OEMAKE:prepend:task-compile-ptest-base = "${PTEST_PARALLEL_MAKE} " | ||
17 | EXTRA_OEMAKE:prepend:task-install-ptest-base = "${PTEST_PARALLEL_MAKEINST} " | ||
18 | |||
19 | FILES:${PN}-ptest += "${PTEST_PATH}" | ||
20 | SECTION:${PN}-ptest = "devel" | ||
21 | ALLOW_EMPTY:${PN}-ptest = "1" | ||
22 | PTEST_ENABLED = "${@bb.utils.contains('DISTRO_FEATURES', 'ptest', '1', '0', d)}" | ||
23 | PTEST_ENABLED:class-native = "" | ||
24 | PTEST_ENABLED:class-nativesdk = "" | ||
25 | PTEST_ENABLED:class-cross-canadian = "" | ||
26 | RDEPENDS:${PN}-ptest += "${PN}" | ||
27 | RDEPENDS:${PN}-ptest:class-native = "" | ||
28 | RDEPENDS:${PN}-ptest:class-nativesdk = "" | ||
29 | RRECOMMENDS:${PN}-ptest += "ptest-runner" | ||
30 | |||
31 | PACKAGES =+ "${@bb.utils.contains('PTEST_ENABLED', '1', '${PN}-ptest', '', d)}" | ||
32 | |||
33 | require conf/distro/include/ptest-packagelists.inc | ||
34 | |||
35 | do_configure_ptest() { | ||
36 | : | ||
37 | } | ||
38 | |||
39 | do_configure_ptest_base() { | ||
40 | do_configure_ptest | ||
41 | } | ||
42 | |||
43 | do_compile_ptest() { | ||
44 | : | ||
45 | } | ||
46 | |||
47 | do_compile_ptest_base() { | ||
48 | do_compile_ptest | ||
49 | } | ||
50 | |||
51 | do_install_ptest() { | ||
52 | : | ||
53 | } | ||
54 | |||
55 | do_install_ptest_base() { | ||
56 | if [ -f ${WORKDIR}/run-ptest ]; then | ||
57 | install -D ${WORKDIR}/run-ptest ${D}${PTEST_PATH}/run-ptest | ||
58 | fi | ||
59 | if grep -q install-ptest: Makefile; then | ||
60 | oe_runmake DESTDIR=${D}${PTEST_PATH} install-ptest | ||
61 | fi | ||
62 | do_install_ptest | ||
63 | chown -R root:root ${D}${PTEST_PATH} | ||
64 | |||
65 | # Strip build host paths from any installed Makefile | ||
66 | for filename in ${PTEST_BUILD_HOST_FILES}; do | ||
67 | for installed_ptest_file in $(find ${D}${PTEST_PATH} -type f -name $filename); do | ||
68 | bbnote "Stripping host paths from: $installed_ptest_file" | ||
69 | sed -e 's#${HOSTTOOLS_DIR}/*##g' \ | ||
70 | -e 's#${WORKDIR}/*=#.=#g' \ | ||
71 | -e 's#${WORKDIR}/*##g' \ | ||
72 | -i $installed_ptest_file | ||
73 | if [ -n "${PTEST_BUILD_HOST_PATTERN}" ]; then | ||
74 | sed -E '/${PTEST_BUILD_HOST_PATTERN}/d' \ | ||
75 | -i $installed_ptest_file | ||
76 | fi | ||
77 | done | ||
78 | done | ||
79 | } | ||
80 | |||
81 | PTEST_BINDIR_PKGD_PATH = "${PKGD}${PTEST_PATH}/bin" | ||
82 | |||
83 | # This function needs to run after apply_update_alternative_renames because the | ||
84 | # aforementioned function will update the ALTERNATIVE_LINK_NAME flag. Append is | ||
85 | # used here to make this function to run as late as possible. | ||
86 | PACKAGE_PREPROCESS_FUNCS:append = "${@bb.utils.contains('PTEST_BINDIR', '1', \ | ||
87 | bb.utils.contains('PTEST_ENABLED', '1', ' ptest_update_alternatives', '', d), '', d)}" | ||
88 | |||
89 | python ptest_update_alternatives() { | ||
90 | """ | ||
91 | This function will generate the symlinks in the PTEST_BINDIR_PKGD_PATH | ||
92 | to match the renamed binaries by update-alternatives. | ||
93 | """ | ||
94 | |||
95 | if not bb.data.inherits_class('update-alternatives', d) \ | ||
96 | or not update_alternatives_enabled(d): | ||
97 | return | ||
98 | |||
99 | bb.note("Generating symlinks for ptest") | ||
100 | bin_paths = { d.getVar("bindir"), d.getVar("base_bindir"), | ||
101 | d.getVar("sbindir"), d.getVar("base_sbindir") } | ||
102 | ptest_bindir = d.getVar("PTEST_BINDIR_PKGD_PATH") | ||
103 | os.mkdir(ptest_bindir) | ||
104 | for pkg in (d.getVar('PACKAGES') or "").split(): | ||
105 | alternatives = update_alternatives_alt_targets(d, pkg) | ||
106 | for alt_name, alt_link, alt_target, _ in alternatives: | ||
107 | # Some alternatives are for man pages, | ||
108 | # check if the alternative is in PATH | ||
109 | if os.path.dirname(alt_link) in bin_paths: | ||
110 | os.symlink(alt_target, os.path.join(ptest_bindir, alt_name)) | ||
111 | } | ||
112 | |||
113 | do_configure_ptest_base[dirs] = "${B}" | ||
114 | do_compile_ptest_base[dirs] = "${B}" | ||
115 | do_install_ptest_base[dirs] = "${B}" | ||
116 | do_install_ptest_base[cleandirs] = "${D}${PTEST_PATH}" | ||
117 | |||
118 | addtask configure_ptest_base after do_configure before do_compile | ||
119 | addtask compile_ptest_base after do_compile before do_install | ||
120 | addtask install_ptest_base after do_install before do_package do_populate_sysroot | ||
121 | |||
122 | python () { | ||
123 | if not bb.data.inherits_class('native', d) and not bb.data.inherits_class('cross', d): | ||
124 | d.setVarFlag('do_install_ptest_base', 'fakeroot', '1') | ||
125 | d.setVarFlag('do_install_ptest_base', 'umask', '022') | ||
126 | |||
127 | # Remove all '*ptest_base' tasks when ptest is not enabled | ||
128 | if not(d.getVar('PTEST_ENABLED') == "1"): | ||
129 | for i in ['do_configure_ptest_base', 'do_compile_ptest_base', 'do_install_ptest_base']: | ||
130 | bb.build.deltask(i, d) | ||
131 | } | ||
132 | |||
133 | QARECIPETEST[missing-ptest] = "package_qa_check_missing_ptest" | ||
134 | def package_qa_check_missing_ptest(pn, d, messages): | ||
135 | # This checks that ptest package is actually included | ||
136 | # in standard oe-core ptest images - only for oe-core recipes | ||
137 | if not 'meta/recipes' in d.getVar('FILE') or not(d.getVar('PTEST_ENABLED') == "1"): | ||
138 | return | ||
139 | |||
140 | enabled_ptests = " ".join([d.getVar('PTESTS_FAST'), d.getVar('PTESTS_SLOW'), d.getVar('PTESTS_PROBLEMS')]).split() | ||
141 | if (pn + "-ptest").replace(d.getVar('MLPREFIX'), '') not in enabled_ptests: | ||
142 | oe.qa.handle_error("missing-ptest", "supports ptests but is not included in oe-core's ptest-packagelists.inc", d) | ||