diff options
author | Alex Overchenko <alex.overchenko@axonim.by> | 2024-09-10 16:51:07 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2024-09-12 12:20:29 (GMT) |
commit | 00c1161b01d11cd2f4cd636f6bf26911f009419e (patch) | |
tree | c0161dd2b6265964c51702173b42fd639183e670 | |
parent | 613a88347056f7764470f22891e2a2e1a98575d0 (diff) | |
download | CMake-00c1161b01d11cd2f4cd636f6bf26911f009419e.zip CMake-00c1161b01d11cd2f4cd636f6bf26911f009419e.tar.gz CMake-00c1161b01d11cd2f4cd636f6bf26911f009419e.tar.bz2 |
file(REAL_PATH): Warn on non-existing paths
The command is documented to work only for cases that the referenced
path exists.
Fixes: #26260
-rw-r--r-- | Source/cmFileCommand.cxx | 7 | ||||
-rw-r--r-- | Tests/RunCMake/file/REAL_PATH-existing.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/file/REAL_PATH-non-existing-stderr.txt | 9 | ||||
-rw-r--r-- | Tests/RunCMake/file/REAL_PATH-non-existing.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/file/RunCMakeTest.cmake | 2 |
5 files changed, 22 insertions, 0 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index f5cd6e8..6e646c1 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -1439,6 +1439,13 @@ bool HandleRealPathCommand(std::vector<std::string> 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 0000000..5f67739 --- /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 0000000..4ac7521 --- /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 0000000..c6357a8 --- /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 524636d..38ec2ac 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) |