diff options
| author | Ethan Morgan <ethan@gweithio.com> | 2026-02-14 16:44:06 +0000 |
|---|---|---|
| committer | Ethan Morgan <ethan@gweithio.com> | 2026-02-14 16:44:06 +0000 |
| commit | 54409423f767d8b1cf30cb7d0efca6b4ca138823 (patch) | |
| tree | d915ac7828703ce4b963efdd9728a1777ba18c1e /vcpkg/scripts/test_ports/vcpkg-ci-python3 | |
Diffstat (limited to 'vcpkg/scripts/test_ports/vcpkg-ci-python3')
4 files changed, 149 insertions, 0 deletions
diff --git a/vcpkg/scripts/test_ports/vcpkg-ci-python3/portfile.cmake b/vcpkg/scripts/test_ports/vcpkg-ci-python3/portfile.cmake new file mode 100644 index 0000000..8c5cd4f --- /dev/null +++ b/vcpkg/scripts/test_ports/vcpkg-ci-python3/portfile.cmake @@ -0,0 +1,6 @@ +set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
+
+vcpkg_cmake_configure(
+ SOURCE_PATH "${CURRENT_PORT_DIR}/project"
+)
+vcpkg_cmake_build()
diff --git a/vcpkg/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt b/vcpkg/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt new file mode 100644 index 0000000..6339bfa --- /dev/null +++ b/vcpkg/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt @@ -0,0 +1,87 @@ +cmake_minimum_required(VERSION 3.12)
+project(python3-test)
+
+set(Python_ARTIFACTS_PREFIX "_MEOW")
+
+# We need to opt-out of CMP0148 to be able to test the pre-CMake 3.12 Python
+# find modules. The old policy is deprecated, so, at some point, this aspect
+# of the test will have to go away.
+if(POLICY CMP0148)
+ cmake_policy(SET CMP0148 OLD)
+endif()
+
+# The purpose of this test is to ensure that we get the expected values
+# from the finders, not crosscompiling. So, let's not even go there.
+# These find_package() calls aren't required because FindPythonInterp
+# seems to not return a result in CI. Probably because FindPythonInterp
+# prefers the system Python instead of the executable from the python3
+# port.
+if(NOT CMAKE_CROSSCOMPILING)
+ find_package(PythonInterp)
+endif()
+find_package(PythonLibs)
+
+# The old find modules should NOT be prefixed.
+if(DEFINED PythonInterp_MEOW_FOUND OR DEFINED PYTHON_MEOW_EXECUTABLE)
+ message(FATAL_ERROR "FindPythonInterp prefixed the result variables")
+endif()
+if(DEFINED PythonLibs_MEOW_FOUND OR DEFINED PYTHON_MEOW_LIBRARIES)
+ message(FATAL_ERROR "FindPythonLibs prefixed the result variables")
+endif()
+
+function(test_result NAME TYPE EXPECTED UNEXPECTED)
+ if(NOT ${TYPE} ${EXPECTED}${NAME})
+ message(FATAL_ERROR "${EXPECTED}${NAME} should be ${TYPE}")
+ endif()
+ if(${TYPE} ${UNEXPECTED}${NAME})
+ message(FATAL_ERROR "${UNEXPECTED}${NAME} should not be ${TYPE}")
+ endif()
+endfunction()
+
+function(test_new_finder EXPECTED UNEXPECTED)
+ test_result(::Python TARGET ${EXPECTED} ${UNEXPECTED})
+ test_result(_LIBRARIES DEFINED ${EXPECTED} ${UNEXPECTED})
+
+ if(NOT CMAKE_CROSSCOMPILING)
+ test_result(_EXECUTABLE DEFINED ${EXPECTED} ${UNEXPECTED})
+ test_result(_STDLIB DEFINED ${EXPECTED} ${UNEXPECTED})
+ test_result(::Interpreter TARGET ${EXPECTED} ${UNEXPECTED})
+ endif()
+endfunction()
+
+if(NOT CMAKE_CROSSCOMPILING)
+ set(_INTERPRETER "Interpreter")
+endif()
+
+# The new find modules should be prefixed if CMake is 4.0+
+find_package(Python REQUIRED COMPONENTS ${_INTERPRETER} Development)
+if(CMAKE_VERSION VERSION_GREATER_EQUAL 4.0)
+ set(EXPECTED_PYTHON Python_MEOW)
+ set(UNEXPECTED_PYTHON Python)
+else()
+ set(EXPECTED_PYTHON Python)
+ set(UNEXPECTED_PYTHON Python_MEOW)
+endif()
+test_new_finder(${EXPECTED_PYTHON} ${UNEXPECTED_PYTHON})
+
+# Also test non-prefixed. Use Python3:: to avoid conflicts with Python_MEOW::
+# The test against Python3_MEOW should never happen because the prefix variable
+# should be Python3_ARTIFACT_PREFIX, but we set Python_ARTIFACT_PREFIX.
+find_package(Python3 REQUIRED COMPONENTS ${_INTERPRETER} Development)
+test_new_finder(Python3 Python3_MEOW)
+
+# Test embedding the libraries found.
+function(add_test_executable TARGET LIBRARIES INCLUDES)
+ add_executable(${TARGET} main.c)
+ target_link_libraries(${TARGET} PRIVATE ${LIBRARIES})
+ if(INCLUDES)
+ target_include_directories(${TARGET} PRIVATE ${INCLUDES})
+ endif()
+endfunction()
+
+# We're purposefully not testing the result of the old finders.
+# The python3 port never added a vcpkg-cmake-wrapper for FindPythonLibs,
+# and it seems like a poor use of time to do so at this point - the
+# old finders are soft removed as of CMake 3.27.
+add_test_executable(new_with_prefix "${EXPECTED_PYTHON}::Python" "")
+add_test_executable(new_without_prefix "${Python3_LIBRARIES}" "${Python3_INCLUDE_DIRS}")
diff --git a/vcpkg/scripts/test_ports/vcpkg-ci-python3/project/main.c b/vcpkg/scripts/test_ports/vcpkg-ci-python3/project/main.c new file mode 100644 index 0000000..cdd5cbe --- /dev/null +++ b/vcpkg/scripts/test_ports/vcpkg-ci-python3/project/main.c @@ -0,0 +1,19 @@ +#include <Python.h>
+
+int main()
+{
+ PyConfig config;
+ PyConfig_InitPythonConfig(&config);
+ config.write_bytecode = 0;
+ PyConfig_SetString(&config, &config.program_name, L"test");
+
+ PyStatus status = Py_InitializeFromConfig(&config);
+ if (PyStatus_Exception(status)) {
+ PyConfig_Clear(&config);
+ Py_ExitStatusException(status);
+ }
+
+ Py_FinalizeEx();
+ PyConfig_Clear(&config);
+ return 0;
+}
diff --git a/vcpkg/scripts/test_ports/vcpkg-ci-python3/vcpkg.json b/vcpkg/scripts/test_ports/vcpkg-ci-python3/vcpkg.json new file mode 100644 index 0000000..a2eca55 --- /dev/null +++ b/vcpkg/scripts/test_ports/vcpkg-ci-python3/vcpkg.json @@ -0,0 +1,37 @@ +{
+ "name": "vcpkg-ci-python3",
+ "version-string": "ci",
+ "description": "Port to test python3 in CI",
+ "homepage": "https://github.com/microsoft/vcpkg",
+ "license": "MIT",
+ "dependencies": [
+ "python3",
+ {
+ "name": "vcpkg-cmake",
+ "host": true
+ }
+ ],
+ "default-features": [
+ "ci"
+ ],
+ "features": {
+ "ci": {
+ "description": "Test features in CI",
+ "dependencies": [
+ {
+ "name": "python3",
+ "features": [
+ {
+ "name": "extensions",
+ "platform": "!(windows & staticcrt)"
+ },
+ {
+ "name": "readline",
+ "platform": "!windows"
+ }
+ ]
+ }
+ ]
+ }
+ }
+}
|