Files
cmake/Tests/RunCMake/FileAPI/ConfigCaseReconfigure-recon-check.cmake
Daksh Mamodiya e6482b840a fileapi: Fix dangling reply reference on case-insensitive filesystems
Reply file names embed the configuration name verbatim.  Reconfiguring
a build tree with a build type that differs from the previous one only
in case (e.g. Debug -> debug) makes CMake write a reply whose name also
differs only in case from the existing file.  On a case-insensitive
filesystem the write is skipped because the name already exists, but
RemoveOldReplyFiles compared on-disk names to the just-written names
textually and deleted the surviving file, leaving the reply index
citing a target or directory reply that no longer exists on disk.

Prune reply files by file identity via cmSystemTools::GetFileId instead
of by name, so an on-disk entry that aliases a reply we just wrote is
kept.  An entry whose identity cannot be obtained is retained rather
than deleted.

Fixes: #28022
2026-08-06 17:44:54 +02:00

22 lines
948 B
CMake

set(reply_dir "${RunCMake_TEST_BINARY_DIR}/.cmake/api/v1/reply")
# Every reply file referenced from the index must still exist on disk after
# the reconfigure. A dangling "jsonFile" reference is the bug this guards; it
# manifests only on a case-insensitive filesystem (Windows, default macOS).
file(GLOB reply_files "${reply_dir}/*.json")
set(dangling "")
foreach(reply_file IN LISTS reply_files)
file(READ "${reply_file}" content)
string(REGEX MATCHALL "\"jsonFile\"[ \t]*:[ \t]*\"[^\"]+\"" refs "${content}")
foreach(ref IN LISTS refs)
string(REGEX REPLACE "\"jsonFile\"[ \t]*:[ \t]*\"([^\"]+)\"" "\\1" name "${ref}")
if(NOT EXISTS "${reply_dir}/${name}")
get_filename_component(from "${reply_file}" NAME)
string(APPEND dangling "\n '${name}' referenced by ${from} is missing")
endif()
endforeach()
endforeach()
if(dangling)
set(RunCMake_TEST_FAILED "Dangling File API reply references:${dangling}")
endif()