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
This commit is contained in:
Brad King
2026-04-13 10:15:11 -04:00
parent f79e0f9884
commit a3358bb66a
5 changed files with 16 additions and 4 deletions

View File

@@ -661,7 +661,7 @@ bool cmake::SetCacheArgs(std::vector<std::string> 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<std::string> 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)) {

View File

@@ -0,0 +1,2 @@
^-- CMAKE_SCRIPT_MODE_FILE='[^']*/Tests/RunCMake/CommandLine/P_PathOnDisk.cmake'
-- CMAKE_CURRENT_LIST_FILE='[^']*/Tests/RunCMake/CommandLine/P_PathOnDisk.cmake'$

View File

@@ -0,0 +1,2 @@
message(STATUS "CMAKE_SCRIPT_MODE_FILE='${CMAKE_SCRIPT_MODE_FILE}'")
message(STATUS "CMAKE_CURRENT_LIST_FILE='${CMAKE_CURRENT_LIST_FILE}'")

View File

@@ -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$

View File

@@ -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