[Bf-blender-cvs] [65df39b9ce0] temp-D7478-unittest-python-exe: Add `TEST_PYTHON_EXE` as advanced CMake option, and default to `${PYTHON_EXECUTABLE}` on macOS/Linux. The default value on Windows remains the Python from the installation directory.
Sybren A. Stüvel
noreply at git.blender.org
Fri Apr 24 10:17:04 CEST 2020
Commit: 65df39b9ce032b300eba33010702b2bd7fedfa92
Author: Sybren A. Stüvel
Date: Fri Apr 17 12:40:32 2020 +0200
Branches: temp-D7478-unittest-python-exe
https://developer.blender.org/rB65df39b9ce032b300eba33010702b2bd7fedfa92
Add `TEST_PYTHON_EXE` as advanced CMake option, and default to `${PYTHON_EXECUTABLE}` on macOS/Linux. The default value on Windows remains the Python from the installation directory.
===================================================================
M CMakeLists.txt
M tests/CMakeLists.txt
===================================================================
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5fb0393dcda..f1782944978 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -429,6 +429,8 @@ endif()
option(WITH_GTESTS "Enable GTest unit testing" OFF)
option(WITH_OPENGL_RENDER_TESTS "Enable OpenGL render related unit testing (Experimental)" OFF)
option(WITH_OPENGL_DRAW_TESTS "Enable OpenGL UI drawing related unit testing (Experimental)" OFF)
+set(TEST_PYTHON_EXE "" CACHE PATH "Python executable to run unit tests")
+mark_as_advanced(TEST_PYTHON_EXE)
# Documentation
if(UNIX AND NOT APPLE)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 18123da22bd..a3d4b2a501e 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -14,35 +14,26 @@ endif()
# Path to Blender and Python executables for all platforms.
if(MSVC)
set(TEST_BLENDER_EXE ${TEST_INSTALL_DIR}/blender.exe)
- set(TEST_PYTHON_EXE "${TEST_INSTALL_DIR}/${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}/python/bin/python$<$<CONFIG:Debug>:_d>")
+ set(_default_test_python_exe "${TEST_INSTALL_DIR}/${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}/python/bin/python$<$<CONFIG:Debug>:_d>")
elseif(APPLE)
set(TEST_BLENDER_EXE ${TEST_INSTALL_DIR}/Blender.app/Contents/MacOS/Blender)
- set(TEST_PYTHON_EXE)
+ set(_default_test_python_exe ${PYTHON_EXECUTABLE})
else()
set(TEST_BLENDER_EXE ${TEST_INSTALL_DIR}/blender)
+ set(_default_test_python_exe ${PYTHON_EXECUTABLE})
+endif()
- # Search for the Python executable to use in the tests.
- # The installation directory's Python is the best one to use. However, it can only be there after the install step, which means
- # that Python will never be here on a fresh system. This is why the search continues to the pre-built libraries, and if that
- # doesn't exist either, default to whatever Python CMake found.
- set(_python_exe "${TEST_INSTALL_DIR}/${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}/python/bin/python${PYTHON_VERSION}m")
- if(EXISTS ${_python_exe})
- message(STATUS "Tests: Using Python from installation directory: ${_python_exe}")
- set(TEST_PYTHON_EXE ${_python_exe})
- else()
- set(_python_exe "${LIBDIR}/python/bin/python${PYTHON_VERSION}m")
- if(EXISTS ${_python_exe})
- message(STATUS "Tests: Using Python from pre-compiled LIBDIR: ${_python_exe}")
- set(TEST_PYTHON_EXE ${_python_exe})
- elseif(EXISTS ${PYTHON_EXECUTABLE})
- message(STATUS "Tests: Using Python from PYTHON_EXECUTABLE: ${PYTHON_EXECUTABLE}")
- set(TEST_PYTHON_EXE ${PYTHON_EXECUTABLE})
- else()
- message(FATAL_ERROR "Tests: unable to find a Python executable to run the tests.")
- endif()
- endif()
- unset(_python_exe)
+# The installation directory's Python is the best one to use. However, it can only be there after the install step,
+# which means that Python will never be there on a fresh system. To suit different needs, the user can pass
+# -DTEST_PYTHON_EXE=/path/to/python to CMake.
+if (NOT TEST_PYTHON_EXE)
+ set(TEST_PYTHON_EXE ${_default_test_python_exe})
+ message(STATUS "Tests: Using Python executable: ${TEST_PYTHON_EXE}")
+elseif(NOT EXISTS ${TEST_PYTHON_EXE})
+ message(FATAL_ERROR "Tests: TEST_PYTHON_EXE ${TEST_PYTHON_EXE} does not exist")
endif()
+unset(_default_test_python_exe)
+
# For testing with Valgrind
# set(TEST_BLENDER_EXE valgrind --track-origins=yes --error-limit=no ${TEST_BLENDER_EXE})
More information about the Bf-blender-cvs
mailing list