blob: 47611edea264fbc7e0d4989980d52e8d97a4670e [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001SUMMARY_${PN}-ptest ?= "${SUMMARY} - Package test files"
2DESCRIPTION_${PN}-ptest ?= "${DESCRIPTION} \
3This package contains a test directory ${PTEST_PATH} for package test purposes."
4
Brad Bishop6e60e8b2018-02-01 10:27:11 -05005PTEST_PATH ?= "${libdir}/${BPN}/ptest"
Brad Bishop19323692019-04-05 15:28:33 -04006PTEST_BUILD_HOST_FILES ?= "Makefile"
7PTEST_BUILD_HOST_PATTERN ?= ""
8
Andrew Geisslerb7d28612020-07-24 16:15:54 -05009FILES_${PN}-ptest += "${PTEST_PATH}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010SECTION_${PN}-ptest = "devel"
11ALLOW_EMPTY_${PN}-ptest = "1"
12PTEST_ENABLED = "${@bb.utils.contains('DISTRO_FEATURES', 'ptest', '1', '0', d)}"
13PTEST_ENABLED_class-native = ""
14PTEST_ENABLED_class-nativesdk = ""
15PTEST_ENABLED_class-cross-canadian = ""
Brad Bishopc342db32019-05-15 21:57:59 -040016RDEPENDS_${PN}-ptest += "${PN}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050017RDEPENDS_${PN}-ptest_class-native = ""
18RDEPENDS_${PN}-ptest_class-nativesdk = ""
19RRECOMMENDS_${PN}-ptest += "ptest-runner"
20
21PACKAGES =+ "${@bb.utils.contains('PTEST_ENABLED', '1', '${PN}-ptest', '', d)}"
22
23do_configure_ptest() {
24 :
25}
26
27do_configure_ptest_base() {
28 do_configure_ptest
29}
30
31do_compile_ptest() {
32 :
33}
34
35do_compile_ptest_base() {
36 do_compile_ptest
37}
38
39do_install_ptest() {
40 :
41}
42
43do_install_ptest_base() {
44 if [ -f ${WORKDIR}/run-ptest ]; then
45 install -D ${WORKDIR}/run-ptest ${D}${PTEST_PATH}/run-ptest
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046 fi
Patrick Williamsf1e5d692016-03-30 15:21:19 -050047 if grep -q install-ptest: Makefile; then
48 oe_runmake DESTDIR=${D}${PTEST_PATH} install-ptest
49 fi
50 do_install_ptest
51 chown -R root:root ${D}${PTEST_PATH}
Brad Bishop19323692019-04-05 15:28:33 -040052
53 # Strip build host paths from any installed Makefile
54 for filename in ${PTEST_BUILD_HOST_FILES}; do
55 for installed_ptest_file in $(find ${D}${PTEST_PATH} -type f -name $filename); do
56 bbnote "Stripping host paths from: $installed_ptest_file"
57 sed -e 's#${HOSTTOOLS_DIR}/*##g' \
58 -e 's#${WORKDIR}/*=#.=#g' \
59 -e 's#${WORKDIR}/*##g' \
60 -i $installed_ptest_file
61 if [ -n "${PTEST_BUILD_HOST_PATTERN}" ]; then
62 sed -E '/${PTEST_BUILD_HOST_PATTERN}/d' \
63 -i $installed_ptest_file
64 fi
65 done
66 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067}
68
Brad Bishopc342db32019-05-15 21:57:59 -040069PTEST_BINDIR_PKGD_PATH = "${PKGD}${PTEST_PATH}/bin"
70
71# This function needs to run after apply_update_alternative_renames because the
72# aforementioned function will update the ALTERNATIVE_LINK_NAME flag. Append is
73# used here to make this function to run as late as possible.
74PACKAGE_PREPROCESS_FUNCS_append = "${@bb.utils.contains('PTEST_BINDIR', '1', \
75 bb.utils.contains('PTEST_ENABLED', '1', ' ptest_update_alternatives', '', d), '', d)}"
76
77python ptest_update_alternatives() {
78 """
79 This function will generate the symlinks in the PTEST_BINDIR_PKGD_PATH
80 to match the renamed binaries by update-alternatives.
81 """
82
83 if not bb.data.inherits_class('update-alternatives', d) \
84 or not update_alternatives_enabled(d):
85 return
86
87 bb.note("Generating symlinks for ptest")
88 bin_paths = { d.getVar("bindir"), d.getVar("base_bindir"),
89 d.getVar("sbindir"), d.getVar("base_sbindir") }
90 ptest_bindir = d.getVar("PTEST_BINDIR_PKGD_PATH")
91 os.mkdir(ptest_bindir)
92 for pkg in (d.getVar('PACKAGES') or "").split():
93 alternatives = update_alternatives_alt_targets(d, pkg)
94 for alt_name, alt_link, alt_target, _ in alternatives:
95 # Some alternatives are for man pages,
96 # check if the alternative is in PATH
97 if os.path.dirname(alt_link) in bin_paths:
98 os.symlink(alt_target, os.path.join(ptest_bindir, alt_name))
99}
100
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500101do_configure_ptest_base[dirs] = "${B}"
102do_compile_ptest_base[dirs] = "${B}"
103do_install_ptest_base[dirs] = "${B}"
104do_install_ptest_base[cleandirs] = "${D}${PTEST_PATH}"
105
106addtask configure_ptest_base after do_configure before do_compile
107addtask compile_ptest_base after do_compile before do_install
108addtask install_ptest_base after do_install before do_package do_populate_sysroot
109
110python () {
111 if not bb.data.inherits_class('native', d) and not bb.data.inherits_class('cross', d):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500112 d.setVarFlag('do_install_ptest_base', 'fakeroot', '1')
Brad Bishopa5c52ff2018-11-23 10:55:50 +1300113 d.setVarFlag('do_install_ptest_base', 'umask', '022')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500114
115 # Remove all '*ptest_base' tasks when ptest is not enabled
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500116 if not(d.getVar('PTEST_ENABLED') == "1"):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500117 for i in ['do_configure_ptest_base', 'do_compile_ptest_base', 'do_install_ptest_base']:
118 bb.build.deltask(i, d)
119}