From 4fc4d1197234dd2139967548e5fcee7076d9b64f Mon Sep 17 00:00:00 2001 From: SoftFever <103989404+SoftFever@users.noreply.github.com> Date: Sat, 28 Nov 2026 00:54:50 +0800 Subject: [PATCH] Fix the Deps Build Failing After a Dependency's Patch Changes (#17957) Unpack a dependency's source again when its patches change When a pull replaced, edited or removed one of a dependency's patches, the next deps build failed at the patch step (OCCT after the seam patch was replaced) or kept the old change in the source. The deps build now unpacks that dependency fresh before patching it, while builds whose patches are unchanged unpack nothing. The first deps build after this change unpacks each patched dependency once. --- deps/CMakeLists.txt | 58 +++++++++++++++++++++++++++ deps/python3/patch_winapi_audit.cmake | 6 +-- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index bab2b18bfe..c36715f7bc 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -510,6 +510,64 @@ else() #list(APPEND _dep_list "dep_libigl") endif() +# ExternalProject unpacks a dependency's source once and later re-runs its PATCH_COMMAND on that +# same tree whenever the command changes. A patch that was replaced, edited or dropped then fails +# to apply over its earlier version, or its old change stays in the source. So each patched +# dependency gets a step before its download step that depends on a record of the patch command +# and of the patch files' contents: when the record changes, the source is unpacked again and the +# current patches go onto a clean tree. The record is rewritten only when its contents change, so +# reconfiguring or switching between branches with the same patches unpacks nothing. +# +# The record hashes the files under deps/ that the command names, plus the .patch files beside +# them, which a patch script such as python3/patch_winapi_audit.cmake reads from its own folder. +function(orcaslicer_reextract_on_patch_change target) + # Recipes pass PATCH_COMMAND with no value on platforms that need no patch, which + # ExternalProject_Get_Property() rejects as unset, so read the property it would read. + get_property(_command TARGET ${target} PROPERTY _EP_PATCH_COMMAND) + if ("${_command}" STREQUAL "") + return() + endif () + + set(_files "") + foreach (_arg IN LISTS _command) + string(FIND "${_arg}" "${CMAKE_CURRENT_SOURCE_DIR}/" _in_deps) + if (_in_deps EQUAL 0 AND EXISTS "${_arg}" AND NOT IS_DIRECTORY "${_arg}") + get_filename_component(_dir "${_arg}" DIRECTORY) + file(GLOB _patches "${_dir}/*.patch") + list(APPEND _files "${_arg}" ${_patches}) + endif () + endforeach () + set(_record "${_command}\n") + if (_files) + list(REMOVE_DUPLICATES _files) + foreach (_file IN LISTS _files) + file(SHA256 "${_file}" _hash) + string(APPEND _record "${_hash} ${_file}\n") + endforeach () + endif () + + ExternalProject_Get_Property(${target} STAMP_DIR) + set(_record_file "${STAMP_DIR}/${target}-patch-record.txt") + set(_old_record "") + if (EXISTS "${_record_file}") + file(READ "${_record_file}" _old_record) + endif () + if (NOT _old_record STREQUAL _record) + file(WRITE "${_record_file}" "${_record}") + endif () + + ExternalProject_Add_Step(${target} patch_record + DEPENDEES mkdir + DEPENDERS download + DEPENDS "${_record_file}" + COMMENT "Patches of '${target}' are new or changed: unpacking its source afresh") +endfunction() + +get_property(_targets DIRECTORY PROPERTY BUILDSYSTEM_TARGETS) +foreach (_target IN LISTS _targets) + orcaslicer_reextract_on_patch_change(${_target}) +endforeach () + add_custom_target(deps ALL DEPENDS ${_dep_list}) # Note: I'm not using any of the LOG_xxx options in ExternalProject_Add() commands diff --git a/deps/python3/patch_winapi_audit.cmake b/deps/python3/patch_winapi_audit.cmake index 85610c0eb3..f7b1913bf7 100644 --- a/deps/python3/patch_winapi_audit.cmake +++ b/deps/python3/patch_winapi_audit.cmake @@ -7,9 +7,9 @@ # changes the format to "uOu", as upstream does (python/cpython#159237), until the pinned # CPython release carries the fix. # -# Applying is idempotent: ExternalProject re-runs the patch step when PATCH_COMMAND changes or -# the patch stamp is missing, which can happen on a source tree that already carries the patch. -# A reverse check recognises that state instead of failing the build on an already patched file. +# Applying is idempotent: ExternalProject re-runs the patch step when the patch stamp is missing, +# which can happen on a source tree that already carries the patch. A reverse check recognises +# that state instead of failing the build on an already patched file. # When the pinned CPython release carries the fix, drop this script, its patch and PATCH_COMMAND. set(_patch "${CMAKE_CURRENT_LIST_DIR}/0001-winapi-createprocess-audit-format.patch")