From a3358bb66aeef19fc2748dfd92da7f54223c0f3b Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 13 Apr 2026 10:15:11 -0400 Subject: [PATCH] cmake: Restore normalization of `-P` script to on-disk path This was missed in commit ee83165923 (cmake: Explicitly normalize input paths as they exist on disk, 2024-10-17, v4.0.0-rc1~597^2), causing `CMAKE_CURRENT_LIST_FILE` in `cmake -P` scripts to be regressed by the KWSys behavior change merged by commit e9bd437a43 (Merge branch 'upstream-KWSys' into normalize-input-paths, 2024-10-24, v4.0.0-rc1~589^2~1). Issue: #27750 --- Source/cmake.cxx | 4 ++-- Tests/RunCMake/CommandLine/P_PathOnDisk-stdout.txt | 2 ++ Tests/RunCMake/CommandLine/P_PathOnDisk.cmake | 2 ++ Tests/RunCMake/CommandLine/P_no-file-stderr.txt | 6 ++++-- Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 6 ++++++ 5 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 Tests/RunCMake/CommandLine/P_PathOnDisk-stdout.txt create mode 100644 Tests/RunCMake/CommandLine/P_PathOnDisk.cmake diff --git a/Source/cmake.cxx b/Source/cmake.cxx index a181aee100..bfd6e00d3b 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -661,7 +661,7 @@ bool cmake::SetCacheArgs(std::vector const& args) state->SetWorkingMode(SCRIPT_MODE); state->SetHomeDirectory(cmSystemTools::GetLogicalWorkingDirectory()); state->SetHomeOutputDirectory(cmSystemTools::GetLogicalWorkingDirectory()); - state->ReadListFile(args, path); + state->ReadListFile(args, cmSystemTools::ToNormalizedPathOnDisk(path)); return true; }; @@ -802,7 +802,7 @@ void cmake::ReadListFile(std::vector const& args, snapshot.SetDefaultDefinitions(); cmMakefile mf(gg, snapshot); if (this->GetWorkingMode() != NORMAL_MODE) { - mf.SetScriptModeFile(cmSystemTools::ToNormalizedPathOnDisk(path)); + mf.SetScriptModeFile(path); mf.SetArgcArgv(args); } if (!cmSystemTools::FileExists(path, true)) { diff --git a/Tests/RunCMake/CommandLine/P_PathOnDisk-stdout.txt b/Tests/RunCMake/CommandLine/P_PathOnDisk-stdout.txt new file mode 100644 index 0000000000..3909b2e340 --- /dev/null +++ b/Tests/RunCMake/CommandLine/P_PathOnDisk-stdout.txt @@ -0,0 +1,2 @@ +^-- CMAKE_SCRIPT_MODE_FILE='[^']*/Tests/RunCMake/CommandLine/P_PathOnDisk.cmake' +-- CMAKE_CURRENT_LIST_FILE='[^']*/Tests/RunCMake/CommandLine/P_PathOnDisk.cmake'$ diff --git a/Tests/RunCMake/CommandLine/P_PathOnDisk.cmake b/Tests/RunCMake/CommandLine/P_PathOnDisk.cmake new file mode 100644 index 0000000000..eb34810420 --- /dev/null +++ b/Tests/RunCMake/CommandLine/P_PathOnDisk.cmake @@ -0,0 +1,2 @@ +message(STATUS "CMAKE_SCRIPT_MODE_FILE='${CMAKE_SCRIPT_MODE_FILE}'") +message(STATUS "CMAKE_CURRENT_LIST_FILE='${CMAKE_CURRENT_LIST_FILE}'") diff --git a/Tests/RunCMake/CommandLine/P_no-file-stderr.txt b/Tests/RunCMake/CommandLine/P_no-file-stderr.txt index a3b4e8e055..704526b972 100644 --- a/Tests/RunCMake/CommandLine/P_no-file-stderr.txt +++ b/Tests/RunCMake/CommandLine/P_no-file-stderr.txt @@ -1,2 +1,4 @@ -^CMake Error: Not a file: nosuchscriptfile.cmake -CMake Error: Error processing file: nosuchscriptfile.cmake$ +^CMake Error: Not a file: [^ +]*/Tests/RunCMake/CommandLine/P_no-file-build/nosuchscriptfile.cmake +CMake Error: Error processing file: [^ +]*/Tests/RunCMake/CommandLine/P_no-file-build/nosuchscriptfile.cmake$ diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index 9fda9eb5b1..265f75a489 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -70,6 +70,12 @@ run_cmake_command(P_P_in_arbitrary_args ${CMAKE_COMMAND} -P "${RunCMake_SOURCE_D run_cmake_command(P_P_in_arbitrary_args_2 ${CMAKE_COMMAND} -P "${RunCMake_SOURCE_DIR}/P_arbitrary_args.cmake" -- -P -o) run_cmake_command(P_fresh ${CMAKE_COMMAND} -P "${RunCMake_SOURCE_DIR}/P_fresh.cmake" --fresh) +if(CMAKE_HOST_WIN32) + run_cmake_command(P_PathOnDisk ${CMAKE_COMMAND} -P "${RunCMake_SOURCE_DIR}/../CommandLine/P_pathondisk.cmake") +else() + run_cmake_command(P_PathOnDisk ${CMAKE_COMMAND} -P "${RunCMake_SOURCE_DIR}/../CommandLine/P_PathOnDisk.cmake") +endif() + run_cmake_command(build-no-dir ${CMAKE_COMMAND} --build) run_cmake_command(build-no-dir2