From 1d37d3b1624ff953beb1d456e2d1a4a3ea1549ec Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Tue, 30 May 2017 19:29:05 +0200 Subject: [PATCH] tests/CMakeLists.txt: Clean up cmake tests to work with python 2&3 Adds additional checks and PYTHON_DEFAULT_INTERP var that is used to find the correct python binary as well as checks to see if the _python2-mraa or _python3-mraa targets have been built by checking mraa.py. This does assume that this is all that is needed as checking for TARGET() is not enough as the target is always 'valid'. We prefer python2 and will only run the java tests if we can find python2 Signed-off-by: Brendan Le Foll --- tests/CMakeLists.txt | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2ea91ad..5a670c2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,4 @@ -if (BUILDSWIGJAVA) +if (PYTHON2INTERP_FOUND AND BUILDSWIGJAVA) add_test (NAME check_clean COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/check_clean.py WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) @@ -6,24 +6,29 @@ if (BUILDSWIGJAVA) add_test (NAME check_samplenames COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/check_samplenames.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) -endif() +endif () if (BUILDSWIGPYTHON) - if (PYTHON2INTERP_FOUND) + if (PYTHON2INTERP_FOUND AND EXISTS "${CMAKE_BINARY_DIR}/src/python/python2/mraa.py") set (PYTHON_DEFAULT_PYTHONPATH "${CMAKE_BINARY_DIR}/src/python/python2") - elseif (PYTHON3INTERP_FOUND) + set (PYTHON_DEFAULT_INTERP "${PYTHON2_EXECUTABLE}") + elseif (PYTHON3INTERP_FOUND AND EXISTS "${CMAKE_BINARY_DIR}/src/python/python3/mraa.py") set (PYTHON_DEFAULT_PYTHONPATH "${CMAKE_BINARY_DIR}/src/python/python3") + set (PYTHON_DEFAULT_INTERP "${PYTHON3_EXECUTABLE}") + else () + message (STATUS "Could not run tests since python interpreter or python bindings not built") endif () + if (MOCKPLAT) add_subdirectory (mock) - else() - add_test (NAME py_general COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/general_checks.py) + else () + add_test (NAME py_general COMMAND ${PYTHON_DEFAULT_INTERP} ${CMAKE_CURRENT_SOURCE_DIR}/general_checks.py) set_tests_properties(py_general PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}") - add_test (NAME py_platform COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/platform_checks.py) + add_test (NAME py_platform COMMAND ${PYTHON_DEFAULT_INTERP} ${CMAKE_CURRENT_SOURCE_DIR}/platform_checks.py) set_tests_properties(py_platform PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}") - add_test (NAME py_gpio COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gpio_checks.py) + add_test (NAME py_gpio COMMAND ${PYTHON_DEFAULT_INTERP} ${CMAKE_CURRENT_SOURCE_DIR}/gpio_checks.py) set_tests_properties(py_gpio PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}") - endif() -endif() + endif () +endif ()