From b1c113d9a79c8ed78bffa63645a146593d19dadc Mon Sep 17 00:00:00 2001
From: Brad King <brad.king@kitware.com>
Date: Mon, 9 Jun 2014 16:19:07 -0400
Subject: cmake: Do not open directories as scripts (#14966)

Check if a file path is a directory before opening it.  Extend the
RunCMake.CommandLine test with a case running "cmake -P" on a directory.
---
 Source/cmListFileCache.cxx                        | 3 ++-
 Tests/RunCMake/CommandLine/P_directory-result.txt | 1 +
 Tests/RunCMake/CommandLine/P_directory-stderr.txt | 1 +
 Tests/RunCMake/CommandLine/RunCMakeTest.cmake     | 2 ++
 4 files changed, 6 insertions(+), 1 deletion(-)
 create mode 100644 Tests/RunCMake/CommandLine/P_directory-result.txt
 create mode 100644 Tests/RunCMake/CommandLine/P_directory-stderr.txt

diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx
index 705666d..3fc5b69 100644
--- a/Source/cmListFileCache.cxx
+++ b/Source/cmListFileCache.cxx
@@ -142,7 +142,8 @@ bool cmListFile::ParseFile(const char* filename,
                            bool topLevel,
                            cmMakefile *mf)
 {
-  if(!cmSystemTools::FileExists(filename))
+  if(!cmSystemTools::FileExists(filename) ||
+     cmSystemTools::FileIsDirectory(filename))
     {
     return false;
     }
diff --git a/Tests/RunCMake/CommandLine/P_directory-result.txt b/Tests/RunCMake/CommandLine/P_directory-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/P_directory-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/P_directory-stderr.txt b/Tests/RunCMake/CommandLine/P_directory-stderr.txt
new file mode 100644
index 0000000..b8319a1
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/P_directory-stderr.txt
@@ -0,0 +1 @@
+^CMake Error: Error processing file: .*/Tests/RunCMake/CommandLine$
diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
index 3aaeac0..f3d9637 100644
--- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
@@ -35,3 +35,5 @@ run_cmake_command(E_sleep-no-args ${CMAKE_COMMAND} -E sleep)
 run_cmake_command(E_sleep-bad-arg1 ${CMAKE_COMMAND} -E sleep x)
 run_cmake_command(E_sleep-bad-arg2 ${CMAKE_COMMAND} -E sleep 1 -1)
 run_cmake_command(E_sleep-one-tenth ${CMAKE_COMMAND} -E sleep 0.1)
+
+run_cmake_command(P_directory ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR})
-- 
cgit v0.12