From 00c1161b01d11cd2f4cd636f6bf26911f009419e Mon Sep 17 00:00:00 2001 From: Alex Overchenko Date: Tue, 10 Sep 2024 19:51:07 +0300 Subject: [PATCH] file(REAL_PATH): Warn on non-existing paths The command is documented to work only for cases that the referenced path exists. Fixes: #26260 --- Source/cmFileCommand.cxx | 7 +++++++ Tests/RunCMake/file/REAL_PATH-existing.cmake | 2 ++ Tests/RunCMake/file/REAL_PATH-non-existing-stderr.txt | 9 +++++++++ Tests/RunCMake/file/REAL_PATH-non-existing.cmake | 2 ++ Tests/RunCMake/file/RunCMakeTest.cmake | 2 ++ 5 files changed, 22 insertions(+) create mode 100644 Tests/RunCMake/file/REAL_PATH-existing.cmake create mode 100644 Tests/RunCMake/file/REAL_PATH-non-existing-stderr.txt create mode 100644 Tests/RunCMake/file/REAL_PATH-non-existing.cmake diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index f5cd6e8689..6e646c1bba 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -1439,6 +1439,13 @@ bool HandleRealPathCommand(std::vector const& args, realPath = oldPolicyPath; } + if (!cmSystemTools::FileExists(realPath)) { + status.GetMakefile().IssueMessage( + MessageType::AUTHOR_WARNING, + cmStrCat("Given path:\n ", input, + "\ndoes not refer to an existing path on disk.")); + } + status.GetMakefile().AddDefinition(args[2], realPath); return true; diff --git a/Tests/RunCMake/file/REAL_PATH-existing.cmake b/Tests/RunCMake/file/REAL_PATH-existing.cmake new file mode 100644 index 0000000000..5f67739567 --- /dev/null +++ b/Tests/RunCMake/file/REAL_PATH-existing.cmake @@ -0,0 +1,2 @@ +file(REAL_PATH "dir" real_path_dir) +file(REAL_PATH "dir/empty.txt" real_path_file) diff --git a/Tests/RunCMake/file/REAL_PATH-non-existing-stderr.txt b/Tests/RunCMake/file/REAL_PATH-non-existing-stderr.txt new file mode 100644 index 0000000000..4ac75210c3 --- /dev/null +++ b/Tests/RunCMake/file/REAL_PATH-non-existing-stderr.txt @@ -0,0 +1,9 @@ +^CMake Warning \(dev\) at REAL_PATH-non-existing.cmake:[0-9]+ \(file\): + Given path: + + dir/bad-magic-file\.txt + + does not refer to an existing path on disk. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) +This warning is for project developers. Use -Wno-dev to suppress it.$ diff --git a/Tests/RunCMake/file/REAL_PATH-non-existing.cmake b/Tests/RunCMake/file/REAL_PATH-non-existing.cmake new file mode 100644 index 0000000000..c6357a8afe --- /dev/null +++ b/Tests/RunCMake/file/REAL_PATH-non-existing.cmake @@ -0,0 +1,2 @@ + +file(REAL_PATH "dir/bad-magic-file.txt" real_path) diff --git a/Tests/RunCMake/file/RunCMakeTest.cmake b/Tests/RunCMake/file/RunCMakeTest.cmake index 524636d32a..38ec2acd33 100644 --- a/Tests/RunCMake/file/RunCMakeTest.cmake +++ b/Tests/RunCMake/file/RunCMakeTest.cmake @@ -99,6 +99,8 @@ if(NOT WIN32 endif() endif() +run_cmake(REAL_PATH-non-existing) +run_cmake(REAL_PATH-existing) run_cmake(REAL_PATH-unexpected-arg) run_cmake(REAL_PATH-no-base-dir) run_cmake(REAL_PATH)