Re-run pip install on failure. (#47)

This commit is contained in:
Mikaël Capelle
2026-06-06 09:27:43 +02:00
committed by GitHub
parent 06addb8f8e
commit 8287612282
+20 -6
View File
@@ -49,9 +49,13 @@ function(mo2_python_pip_install TARGET)
string(MAKE_C_IDENTIFIER "${MO2_PACKAGES}" PIP_FILE_LOG)
set(pip_log_file "${CMAKE_CURRENT_BINARY_DIR}/${PIP_FILE_LOG}.log")
set(_success_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_requirements_success.log")
# there is no way to guess a file generated by pip except the log file, but the log
# file is always generated (even on failure), so we run a second command after pip
# (only if pip succeeds) to generate a success file that we can depend on
add_custom_command(
OUTPUT "${pip_log_file}"
OUTPUT "${_success_file}"
COMMAND ${PYTHON_EXE}
-I
-m pip
@@ -64,11 +68,12 @@ function(mo2_python_pip_install TARGET)
--target="${MO2_DIRECTORY}"
--log="${pip_log_file}"
${MO2_PACKAGES}
COMMAND ${PYTHON_EXE} -c "open('${_success_file}', 'w').close()"
)
set(pip_target_name "${TARGET}_pip_${PIP_FILE_LOG}")
add_custom_target(${pip_target_name} ALL DEPENDS "${pip_log_file}")
add_custom_target(${pip_target_name} ALL DEPENDS "${pip_log_file}" "${_success_file}")
set_target_properties(${pip_target_name} PROPERTIES FOLDER autogen)
add_dependencies(${TARGET} ${pip_target_name})
@@ -154,20 +159,29 @@ endfunction()
function(mo2_python_requirements TARGET)
cmake_parse_arguments(MO2 "" "LIBDIR" "" ${ARGN})
set(_success_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_requirements_success.log")
mo2_find_python_executable(PYTHON_EXE)
# there is no way to guess a file generated by pip except the log file, but the log
# file is always generated (even on failure), so we run a second command after pip
# (only if pip succeeds) to generate a success file that we can depend on
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pip.log"
OUTPUT "${_success_file}"
COMMAND ${PYTHON_EXE}
-I
-m pip
install --force --upgrade --disable-pip-version-check
install
--force
--upgrade
--disable-pip-version-check
--target="${MO2_LIBDIR}"
--log="${CMAKE_CURRENT_BINARY_DIR}/pip.log"
-r "${PROJECT_SOURCE_DIR}/plugin-requirements.txt"
COMMAND ${PYTHON_EXE} -c "open('${_success_file}', 'w').close()"
DEPENDS "${PROJECT_SOURCE_DIR}/plugin-requirements.txt"
)
add_custom_target("${TARGET}_libs"
ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pip.log")
add_custom_target("${TARGET}_libs" ALL DEPENDS "${_success_file}")
set_target_properties("${TARGET}_libs" PROPERTIES FOLDER autogen)
add_dependencies(${TARGET} "${TARGET}_libs")