I have the following lines in my CMake file, basically running a python script.
find_package(Python3 COMPONENTS Interpreter)
if(Python3_Interpreter_FOUND)
set(MY_CTESTS_DIR ${PROJECT_BINARY_DIR}/tests)
set(MY_TESTING_DIR ${MY_CTESTS_DIR}/temporary)
file(TO_NATIVE_PATH "${PROJECT_SOURCE_DIR}/test/my_script.py" NATIVE_SCRIPT_SCRIPT)
file(TO_NATIVE_PATH "${PROJECT_BINARY_DIR}/tests" NATIVE_CTESTS_DIR)
file(TO_NATIVE_PATH "${PROJECT_SOURCE_DIR}/test" NATIVE_WORKING_DIR)
execute_process(
COMMAND "${Python3_EXECUTABLE}" "${NATIVE_SCRIPT_SCRIPT}" "${NATIVE_CTESTS_DIR}"
WORKING_DIRECTORY "${NATIVE_WORKING_DIR}"
RESULT_VARIABLE TEST_SCRIPT_RESULT
OUTPUT_VARIABLE TEST_SCRIPT_OUTPUT
ERROR_VARIABLE TEST_SCRIPT_ERROR
)
if(NOT TEST_SCRIPT_RESULT EQUAL 0)
message(FATAL_ERROR "Python script failed: ${TEST_SCRIPT_ERROR}")
endif()
endif()
This works on every platform I test, except CygWin (with CMake 3.31.3). The error reported is that the python script file is not found (though it is available).
-- Found Python3: /cygdrive/c/hostedtoolcache/windows/Python/3.9.13/x64/python3.exe (found version "3.9.13") found components: Interpreter
CMake Error at cmake/test.cmake:36 (message):
Python script failed:
C:\hostedtoolcache\windows\Python\3.9.13\x64\python3.exe: can't open file
'D:\cygdrive\d\a\my\my\test\my_script.py': [Errno 2] No
such file or directory
Call Stack (most recent call first):
CMakeLists.txt:35 (include)
-- Configuring incomplete, errors occurred!
Error: Process completed with exit code 1.Note, that I already tried to circumvent the CygWin path issue, but with no success. What is the correct way to run Python scripts via CMake on CygWin (for GitHub Actions)? Thank you!
Note, that I already tried to circumvent the CygWin path issue, but with no success. What is the correct way to run Python scripts via CMake on CygWin (for GitHub Actions)? Thank you!