1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7SUMMARY:${PN}-ptest ?= "${SUMMARY} - Package test files"
8DESCRIPTION:${PN}-ptest ?= "${DESCRIPTION}  \
9This package contains a test directory ${PTEST_PATH} for package test purposes."
10
11PTEST_PATH ?= "${libdir}/${BPN}/ptest"
12PTEST_BUILD_HOST_FILES ?= "Makefile"
13PTEST_BUILD_HOST_PATTERN ?= ""
14PTEST_PARALLEL_MAKE ?= "${PARALLEL_MAKE}"
15PTEST_PARALLEL_MAKEINST ?= "${PARALLEL_MAKEINST}"
16EXTRA_OEMAKE:prepend:task-compile-ptest-base = "${PTEST_PARALLEL_MAKE} "
17EXTRA_OEMAKE:prepend:task-install-ptest-base = "${PTEST_PARALLEL_MAKEINST} "
18
19FILES:${PN}-ptest += "${PTEST_PATH}"
20SECTION:${PN}-ptest = "devel"
21ALLOW_EMPTY:${PN}-ptest = "1"
22PTEST_ENABLED = "${@bb.utils.contains('DISTRO_FEATURES', 'ptest', '1', '0', d)}"
23PTEST_ENABLED:class-native = ""
24PTEST_ENABLED:class-nativesdk = ""
25PTEST_ENABLED:class-cross-canadian = ""
26RDEPENDS:${PN}-ptest += "${PN}"
27RDEPENDS:${PN}-ptest:class-native = ""
28RDEPENDS:${PN}-ptest:class-nativesdk = ""
29RRECOMMENDS:${PN}-ptest += "ptest-runner"
30
31PACKAGES =+ "${@bb.utils.contains('PTEST_ENABLED', '1', '${PN}-ptest', '', d)}"
32
33require conf/distro/include/ptest-packagelists.inc
34
35do_configure_ptest() {
36    :
37}
38
39do_configure_ptest_base() {
40    do_configure_ptest
41}
42
43do_compile_ptest() {
44    :
45}
46
47do_compile_ptest_base() {
48    do_compile_ptest
49}
50
51do_install_ptest() {
52    :
53}
54
55do_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
81PTEST_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.
86PACKAGE_PREPROCESS_FUNCS:append = "${@bb.utils.contains('PTEST_BINDIR', '1', \
87                                    bb.utils.contains('PTEST_ENABLED', '1', ' ptest_update_alternatives', '', d), '', d)}"
88
89python 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
113do_configure_ptest_base[dirs] = "${B}"
114do_compile_ptest_base[dirs] = "${B}"
115do_install_ptest_base[dirs] = "${B}"
116do_install_ptest_base[cleandirs] = "${D}${PTEST_PATH}"
117
118addtask configure_ptest_base after do_configure before do_compile
119addtask compile_ptest_base   after do_compile   before do_install
120addtask install_ptest_base   after do_install   before do_package do_populate_sysroot
121
122python () {
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
133QARECIPETEST[missing-ptest] = "package_qa_check_missing_ptest"
134def 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.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)
143