From 9b45210b052c7c81ab84313c4a3b537e66c2a7b7 Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Thu, 29 Jun 2023 15:11:12 +0200 Subject: FindPython: Add tests for IronPython v3 --- Modules/FindPython/Support.cmake | 4 +- Tests/CMakeLists.txt | 6 +- Tests/FindPython/CMakeLists.txt | 141 +++++++++++++++++++++++----- Tests/FindPython/IronPython3/CMakeLists.txt | 31 ++++++ 4 files changed, 154 insertions(+), 28 deletions(-) create mode 100644 Tests/FindPython/IronPython3/CMakeLists.txt diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake index 76d4a9b..0f0e2af 100644 --- a/Modules/FindPython/Support.cmake +++ b/Modules/FindPython/Support.cmake @@ -981,7 +981,7 @@ function (_PYTHON_VALIDATE_COMPILER) # retrieve python environment version from compiler set (working_dir "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PythonCompilerVersion.dir") - file (WRITE "${working_dir}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]]))\n") + file (WRITE "${working_dir}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]])); sys.stdout.flush()\n") execute_process (COMMAND ${launcher} "${_${_PYTHON_PREFIX}_COMPILER}" ${_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_ARCH_FLAGS} /target:exe /embed "${working_dir}/version.py" @@ -2520,7 +2520,7 @@ if ("Compiler" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) # retrieve python environment version from compiler _python_get_launcher (_${_PYTHON_PREFIX}_COMPILER_LAUNCHER COMPILER) set (_${_PYTHON_PREFIX}_VERSION_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PythonCompilerVersion.dir") - file (WRITE "${_${_PYTHON_PREFIX}_VERSION_DIR}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]]))\n") + file (WRITE "${_${_PYTHON_PREFIX}_VERSION_DIR}/version.py" "import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]])); sys.stdout.flush()\n") execute_process (COMMAND ${_${_PYTHON_PREFIX}_COMPILER_LAUNCHER} "${_${_PYTHON_PREFIX}_COMPILER}" ${_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_ARCH_FLAGS} /target:exe /embed "${_${_PYTHON_PREFIX}_VERSION_DIR}/version.py" diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 914ebce..2a7c839 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1557,15 +1557,17 @@ if(BUILD_TESTING) endif() if(CMake_TEST_FindPython_IronPython) set(CMake_TEST_FindPython2_IronPython TRUE) + set(CMake_TEST_FindPython3_IronPython TRUE) endif() if(CMake_TEST_FindPython_PyPy) set(CMake_TEST_FindPython2_PyPy TRUE) set(CMake_TEST_FindPython3_PyPy TRUE) endif() - if(CMake_TEST_FindPython2 OR CMake_TEST_FindPython2 + if(CMake_TEST_FindPython2 OR CMake_TEST_FindPython3 OR CMake_TEST_FindPython2_SABIModule OR CMake_TEST_FindPython3_SABIModule OR CMake_TEST_FindPython2_NumPy OR CMake_TEST_FindPython3_NumPy - OR CMake_TEST_FindPython3_Conda OR CMake_TEST_FindPython2_IronPython + OR CMake_TEST_FindPython3_Conda + OR CMake_TEST_FindPython2_IronPython OR CMake_TEST_FindPython3_IronPython OR CMake_TEST_FindPython2_PyPy OR CMake_TEST_FindPython3_PyPy) if (CMake_TEST_FindPython2 AND CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin") set(CMake_TEST_FindPython2_SABIModule TRUE) diff --git a/Tests/FindPython/CMakeLists.txt b/Tests/FindPython/CMakeLists.txt index 3e1993e..bb9bef0 100644 --- a/Tests/FindPython/CMakeLists.txt +++ b/Tests/FindPython/CMakeLists.txt @@ -557,21 +557,21 @@ if(CMake_TEST_FindPython3_Conda) endif() if (CMake_TEST_FindPython2 AND CMake_TEST_FindPython2_IronPython) - add_test(NAME FindPython.Implementation.CPython COMMAND + add_test(NAME FindPython.Implementation.CPython2 COMMAND ${CMAKE_CTEST_COMMAND} -C $ --build-and-test "${CMake_SOURCE_DIR}/Tests/FindPython/Implementation" - "${CMake_BINARY_DIR}/Tests/FindPython/Implementation.CPython" + "${CMake_BINARY_DIR}/Tests/FindPython/Implementation.CPython2" ${build_generator_args} --build-project TestImplementationCPython --build-options ${build_options} -DPython_REQUESTED_VERSION=2 -DPython_REQUESTED_IMPLEMENTATIONS=CPython --test-command ${CMAKE_CTEST_COMMAND} -V -C $ ) - add_test(NAME FindPython.Implementation.IronPython COMMAND + add_test(NAME FindPython.Implementation.IronPython2 COMMAND ${CMAKE_CTEST_COMMAND} -C $ --build-and-test "${CMake_SOURCE_DIR}/Tests/FindPython/Implementation" - "${CMake_BINARY_DIR}/Tests/FindPython/Implementation.IronPython" + "${CMake_BINARY_DIR}/Tests/FindPython/Implementation.IronPython2" ${build_generator_args} --build-project TestImplementationIronPython --build-options ${build_options} -DPython_REQUESTED_VERSION=2 -DPython_REQUESTED_IMPLEMENTATION=IronPython @@ -579,6 +579,29 @@ if (CMake_TEST_FindPython2 AND CMake_TEST_FindPython2_IronPython) ) endif() +if (CMake_TEST_FindPython3 AND CMake_TEST_FindPython3_IronPython) + add_test(NAME FindPython.Implementation.CPython3 COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/Implementation" + "${CMake_BINARY_DIR}/Tests/FindPython/Implementation.CPython3" + ${build_generator_args} + --build-project TestImplementationCPython + --build-options ${build_options} -DPython_REQUESTED_VERSION=3 -DPython_REQUESTED_IMPLEMENTATIONS=CPython + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ + ) + add_test(NAME FindPython.Implementation.IronPython3 COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/Implementation" + "${CMake_BINARY_DIR}/Tests/FindPython/Implementation.IronPython3" + ${build_generator_args} + --build-project TestImplementationIronPython + --build-options ${build_options} -DPython_REQUESTED_VERSION=3 -DPython_REQUESTED_IMPLEMENTATION=IronPython + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ + ) +endif() + if(CMake_TEST_FindPython2_IronPython) add_test(NAME FindPython.IronPython2.LOCATION COMMAND ${CMAKE_CTEST_COMMAND} -C $ @@ -601,26 +624,6 @@ if(CMake_TEST_FindPython2_IronPython) --test-command ${CMAKE_CTEST_COMMAND} -V -C $ ) - add_test(NAME FindPython.IronPython.LOCATION COMMAND - ${CMAKE_CTEST_COMMAND} -C $ - --build-and-test - "${CMake_SOURCE_DIR}/Tests/FindPython/IronPython" - "${CMake_BINARY_DIR}/Tests/FindPython/IronPython.LOCATION" - ${build_generator_args} - --build-project TestIronPython - --build-options ${build_options} -DPython_FIND_STRATEGY=LOCATION - --test-command ${CMAKE_CTEST_COMMAND} -V -C $ - ) - add_test(NAME FindPython.IronPython.VERSION COMMAND - ${CMAKE_CTEST_COMMAND} -C $ - --build-and-test - "${CMake_SOURCE_DIR}/Tests/FindPython/IronPython" - "${CMake_BINARY_DIR}/Tests/FindPython/IronPython.VERSION" - ${build_generator_args} - --build-project TestIronPython - --build-options ${build_options} -DPython_FIND_STRATEGY=VERSION - --test-command ${CMAKE_CTEST_COMMAND} -V -C $ - ) add_test(NAME FindPython.IronPython.V2.LOCATION COMMAND ${CMAKE_CTEST_COMMAND} -C $ --build-and-test @@ -666,6 +669,96 @@ if(CMake_TEST_FindPython2_IronPython) ) endif() +if(CMake_TEST_FindPython3_IronPython) + add_test(NAME FindPython.IronPython3.LOCATION COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/IronPython3" + "${CMake_BINARY_DIR}/Tests/FindPython/IronPython3.LOCATION" + ${build_generator_args} + --build-project TestIronPython3 + --build-options ${build_options} -DPython3_FIND_STRATEGY=LOCATION + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ + ) + add_test(NAME FindPython.IronPython3.VERSION COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/IronPython3" + "${CMake_BINARY_DIR}/Tests/FindPython/IronPython3.VERSION" + ${build_generator_args} + --build-project TestIronPython3 + --build-options ${build_options} -DPython3_FIND_STRATEGY=VERSION + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ + ) + + add_test(NAME FindPython.IronPython.V3.LOCATION COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/IronPython" + "${CMake_BINARY_DIR}/Tests/FindPython/IronPython.V3.LOCATION" + ${build_generator_args} + --build-project TestIronPython + --build-options ${build_options} -DPython_REQUESTED_VERSION=3 -DPython_FIND_STRATEGY=LOCATION + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ + ) + add_test(NAME FindPython.IronPython.V3.VERSION COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/IronPython" + "${CMake_BINARY_DIR}/Tests/FindPython/IronPython.V3.VERSION" + ${build_generator_args} + --build-project TestIronPython + --build-options ${build_options} -DPython_REQUESTED_VERSION=3 -DPython_FIND_STRATEGY=VERSION + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ + ) + + add_test(NAME FindPython.IronPython3.VersionRange.LOCATION COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/VersionRange" + "${CMake_BINARY_DIR}/Tests/FindPython/IronPython3.VersionRange.LOCATION" + ${build_generator_args} + --build-project TestVersionRange + --build-options ${build_options} -DPython=Python3 -DPython_REQUESTED_VERSION=3 + -DPython3_FIND_IMPLEMENTATIONS=IronPython + -DPython3_FIND_STRATEGY=LOCATION + ) + add_test(NAME FindPython.IronPython3.VersionRange.VERSION COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/VersionRange" + "${CMake_BINARY_DIR}/Tests/FindPython/IronPython3.VersionRange.VERSION" + ${build_generator_args} + --build-project TestVersionRange + --build-options ${build_options} -DPython=Python3 -DPython_REQUESTED_VERSION=3 + -DPython3_FIND_IMPLEMENTATIONS=IronPython + -DPython3_FIND_STRATEGY=VERSION + ) +endif() + +if(CMake_TEST_FindPython2_IronPython OR CMake_TEST_FindPython3_IronPython) + add_test(NAME FindPython.IronPython.LOCATION COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/IronPython" + "${CMake_BINARY_DIR}/Tests/FindPython/IronPython.LOCATION" + ${build_generator_args} + --build-project TestIronPython + --build-options ${build_options} -DPython_FIND_STRATEGY=LOCATION + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ + ) + add_test(NAME FindPython.IronPython.VERSION COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindPython/IronPython" + "${CMake_BINARY_DIR}/Tests/FindPython/IronPython.VERSION" + ${build_generator_args} + --build-project TestIronPython + --build-options ${build_options} -DPython_FIND_STRATEGY=VERSION + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ + ) +endif() + if(CMake_TEST_FindPython2_PyPy) add_test(NAME FindPython.PyPy2.LOCATION COMMAND ${CMAKE_CTEST_COMMAND} -C $ diff --git a/Tests/FindPython/IronPython3/CMakeLists.txt b/Tests/FindPython/IronPython3/CMakeLists.txt new file mode 100644 index 0000000..b09097a --- /dev/null +++ b/Tests/FindPython/IronPython3/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 3.5) + +project(TestIronPython3 LANGUAGES NONE) + +set (Python3_FIND_IMPLEMENTATIONS "IronPython") + +find_package(Python3 COMPONENTS Interpreter Compiler) +if (NOT Python3_FOUND) + message (FATAL_ERROR "Failed to find Python 3") +endif() + +if (NOT Python3_Interpreter_FOUND) + message (FATAL_ERROR "Failed to find Python 3 Interpreter") +endif() +if (NOT Python3_INTERPRETER_ID STREQUAL "IronPython") + message (FATAL_ERROR "Erroneous interpreter ID (${Python3_INTERPRETER_ID})") +endif() + +if (NOT Python3_Compiler_FOUND) + message (FATAL_ERROR "Failed to find Python 3 Compiler") +endif() +if (NOT Python3_COMPILER_ID STREQUAL "IronPython") + message (FATAL_ERROR "Erroneous compiler ID (${Python3_COMPILER_ID})") +endif() + +if(NOT TARGET Python3::Interpreter) + message(SEND_ERROR "Python3::Interpreter not found") +endif() +if(NOT TARGET Python3::Compiler) + message(SEND_ERROR "Python3::Compiler not found") +endif() -- cgit v0.12