Browse Source

Merge topic 'file-REAL_PATH-warn-non-existing'

00c1161b01 file(REAL_PATH): Warn on non-existing paths

Acked-by: Kitware Robot <[email protected]>
Merge-request: !9806
Brad King 1 year ago
parent
commit
844417294b

+ 7 - 0
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;

+ 2 - 0
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)

+ 9 - 0
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.$

+ 2 - 0
Tests/RunCMake/file/REAL_PATH-non-existing.cmake

@@ -0,0 +1,2 @@
+
+file(REAL_PATH "dir/bad-magic-file.txt" real_path)

+ 2 - 0
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)