classes/ptest-python-pytest: simplify python ptest file overriding
PATCH v3 1/1 classes/ptest-python-pytest: simplify python ptest file overriding
The complexity of overriding files from the bbclass made the behavior at times hard to follow and predict. This change replaces the default file with a heredoc equivalent that creates a default file if the user does not provide their own version of run-ptest in the SRC_URI.
--- .../ptest-python-pytest.bbclass | 30 +++++++++++-------- meta/files/ptest-python-pytest/run-ptest | 3 -- 2 files changed, 18 insertions(+), 15 deletions(-) delete mode 100755 meta/files/ptest-python-pytest/run-ptest
meta/classes-recipe/ptest-python-pytest.bbclass +18 -12
@@ -6,24 +6,30 @@ inherit ptest -FILESEXTRAPATHS:prepend := "${COREBASE}/meta/files:" - -SRC_URI:append = "\ - file://ptest-python-pytest/run-ptest \ -" - # Overridable configuration for the directory within the source tree # containing the pytest files PTEST_PYTEST_DIR ?= "tests" do_install_ptest() { - if [ ! -f ${D}${PTEST_PATH}/run-ptest ]; then - install -m 0755 ${UNPACKDIR}/ptest-python-pytest/run-ptest ${D}${PTEST_PATH} + # Check if the recipe provides its own version of run-ptest + # If nothing exists in the SRC_URI, dynamically create a + # run-test script of "last resort" that has the default + # pytest behavior. + # + # Users can override this behavior by simply including a + # custom script (run-ptest) in the source file list + if [ ! -f "${UNPACKDIR}/run-ptest" ]; then + cat > ${D}${PTEST_PATH}/run-ptest << EOF +#!/bin/sh +pytest --automake +EOF + # Ensure the newly created script has the execute bit set + chmod 755 ${D}${PTEST_PATH}/run-ptest + fi + if [ -d "${S}/${PTEST_PYTEST_DIR}" ]; then + install -d ${D}${PTEST_PATH}/${PTEST_PYTEST_DIR} + cp -rf ${S}/${PTEST_PYTEST_DIR}/* ${D}${PTEST_PATH}/${PTEST_PYTEST_DIR}/ fi - if [ -d "${S}/${PTEST_PYTEST_DIR}" ]; then - install -d ${D}${PTEST_PATH}/${PTEST_PYTEST_DIR} - cp -rf ${S}/${PTEST_PYTEST_DIR}/* ${D}${PTEST_PATH}/${PTEST_PYTEST_DIR}/ - fi } FILES:${PN}-ptest:prepend = "${PTEST_PATH}/*"
meta/files/ptest-python-pytest/run-ptest deleted +0 -3
@@ -1,3 +0,0 @@ -#!/bin/sh - -pytest --automake
Signature · 1 line
2.34.1
Hi Derek,
Quoted 28 lines · Derek Straka via lists.openembedded.org
The complexity of overriding files from the bbclass made the behavior at times hard to follow and predict. This change replaces the default file with a heredoc equivalent that creates a default file if the user does not provide their own version of run-ptest in the
SRC_URI.Signed-off-by Derek Straka <[email protected]>--- .../ptest-python-pytest.bbclass | 30 +++++++++++-------- meta/files/ptest-python-pytest/run-ptest | 3 -- 2 files changed, 18 insertions(+), 15 deletions(-)delete mode 100755 meta/files/ptest-python-pytest/run-ptest
meta/classes-recipe/ptest-python-pytest.bbclass +0
-6@@ -6,24 +6,30 @@ inherit ptest -FILESEXTRAPATHS:prepend := "${COREBASE}/meta/files:" - -SRC_URI:append = "\ - file://ptest-python-pytest/run-ptest \ -" - # Overridable configuration for the directory within the source tree # containing the pytest files
meta/classes-recipe/ptest-python-pytest.bbclass line 18
Quoted 10 lines
meta/classes-recipe/ptest-python-pytest.bbclass +5
-2PTEST_PYTEST_DIR ?= "tests" do_install_ptest() { - if [ ! -f ${D}${PTEST_PATH}/run-ptest ]; then - install -m 0755 ${UNPACKDIR}/ptest-python-pytest/run-ptest ${D}${PTEST_PATH} + # Check if the recipe provides its own version of run-ptest + # If nothing exists in the SRC_URI, dynamically create a + # run-test script of "last resort" that has the default + # pytest behavior. + #
Ah, this is a smart way to work around having to fiddle with FILESEXTRAPATHS!
meta/classes-recipe/ptest-python-pytest.bbclass line 21
Quoted 3 lines
meta/classes-recipe/ptest-python-pytest.bbclass +3
-0+ # Users can override this behavior by simply including a + # custom script (run-ptest) in the source file list + if [ ! -f "${UNPACKDIR}/run-ptest" ]; then
You should be able to check for the presence of ${D}${PTEST_PATH}/run-ptest directly instead. Since do_install_ptest_base does install the file from UNPACKDIR in there. do_install_ptest is called only from within do_install_ptest_base which always cleans ${D}${PTEST_PATH} (via the cleandirs varflag for the task).
The benefit is that we wouldn't need to rely on the file being installed via SRC_URI file:// and could be part of a tarball/git archive (maybe it works already today, I haven't tested).
Also, it probably works better wrt https://git.openembedded.org/openembedded-core/tree/meta/classes-recipe/ptest.bbclass#n60 which calls make to install ptest into ${D}${PTEST_PATH} which wouldn't be handled by this check.
Quoted 7 lines
meta/classes-recipe/ptest-python-pytest.bbclass +7
-0+ cat > ${D}${PTEST_PATH}/run-ptest << EOF +#!/bin/sh +pytest --automake +EOF + # Ensure the newly created script has the execute bit set + chmod 755 ${D}${PTEST_PATH}/run-ptest + fi
meta/classes-recipe/ptest-python-pytest.bbclass line 28
Quoted 10 lines
meta/classes-recipe/ptest-python-pytest.bbclass +3
-4+ if [ -d "${S}/${PTEST_PYTEST_DIR}" ]; then + install -d ${D}${PTEST_PATH}/${PTEST_PYTEST_DIR} + cp -rf ${S}/${PTEST_PYTEST_DIR}/* ${D}${PTEST_PATH}/${PTEST_PYTEST_DIR}/ fi - if [ -d "${S}/${PTEST_PYTEST_DIR}" ]; then - install -d ${D}${PTEST_PATH}/${PTEST_PYTEST_DIR} - cp -rf ${S}/${PTEST_PYTEST_DIR}/* ${D}${PTEST_PATH}/${PTEST_PYTEST_DIR}/ - fi
The indentation seems odd though?
Quoted 3 lines
meta/classes-recipe/ptest-python-pytest.bbclass +0
-0}FILES:${PN}-ptest:prepend = "${PTEST_PATH}/*"
This line can be removed (in a separate patch) as it's already there, coming from the ptest.bbclass, c.f. https://git.openembedded.org/openembedded-core/tree/meta/classes-recipe/ptest.bbclass#n19
Cheers,
Quentin