浏览代码

FindPython: Add tests for IronPython v3

Marc Chevrier 2 年之前
父节点
当前提交
9b45210b05
共有 4 个文件被更改,包括 154 次插入28 次删除
  1. 2 2
      Modules/FindPython/Support.cmake
  2. 4 2
      Tests/CMakeLists.txt
  3. 117 24
      Tests/FindPython/CMakeLists.txt
  4. 31 0
      Tests/FindPython/IronPython3/CMakeLists.txt

+ 2 - 2
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"

+ 4 - 2
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)

+ 117 - 24
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 $<CONFIGURATION>
     --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 $<CONFIGURATION>
     )
-  add_test(NAME FindPython.Implementation.IronPython COMMAND
+  add_test(NAME FindPython.Implementation.IronPython2 COMMAND
     ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
     --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 $<CONFIGURATION>
+    --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 $<CONFIGURATION>
+    )
+  add_test(NAME FindPython.Implementation.IronPython3 COMMAND
+    ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+    --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 $<CONFIGURATION>
+    )
+endif()
+
 if(CMake_TEST_FindPython2_IronPython)
   add_test(NAME FindPython.IronPython2.LOCATION COMMAND
     ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
@@ -601,26 +624,6 @@ if(CMake_TEST_FindPython2_IronPython)
     --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
     )
 
-  add_test(NAME FindPython.IronPython.LOCATION COMMAND
-    ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
-    --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 $<CONFIGURATION>
-    )
-  add_test(NAME FindPython.IronPython.VERSION COMMAND
-    ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
-    --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 $<CONFIGURATION>
-    )
   add_test(NAME FindPython.IronPython.V2.LOCATION COMMAND
     ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
     --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 $<CONFIGURATION>
+    --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 $<CONFIGURATION>
+    )
+  add_test(NAME FindPython.IronPython3.VERSION COMMAND
+    ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+    --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 $<CONFIGURATION>
+    )
+
+  add_test(NAME FindPython.IronPython.V3.LOCATION COMMAND
+    ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+    --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 $<CONFIGURATION>
+    )
+  add_test(NAME FindPython.IronPython.V3.VERSION COMMAND
+    ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+    --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 $<CONFIGURATION>
+    )
+
+  add_test(NAME FindPython.IronPython3.VersionRange.LOCATION COMMAND
+    ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+    --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 $<CONFIGURATION>
+    --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 $<CONFIGURATION>
+    --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 $<CONFIGURATION>
+    )
+  add_test(NAME FindPython.IronPython.VERSION COMMAND
+    ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+    --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 $<CONFIGURATION>
+    )
+endif()
+
 if(CMake_TEST_FindPython2_PyPy)
   add_test(NAME FindPython.PyPy2.LOCATION COMMAND
     ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>

+ 31 - 0
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()