diff options
author | Brad King <brad.king@kitware.com> | 2014-05-21 14:31:49 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2014-05-21 14:31:49 (GMT) |
commit | 42130606d4fe478ab838612df427684786cc9d7f (patch) | |
tree | 0ebe771570db2751346e71b11acab7203e0e6a76 | |
parent | 8dc8878a5e6388e0d08eb18d7cf631638cc49adb (diff) | |
parent | 2c448dbfe762278480bfd4f8ba9f458f9a104941 (diff) | |
download | CMake-42130606d4fe478ab838612df427684786cc9d7f.zip CMake-42130606d4fe478ab838612df427684786cc9d7f.tar.gz CMake-42130606d4fe478ab838612df427684786cc9d7f.tar.bz2 |
Merge topic 'file-command-open-errors'
2c448dbf file: Report system error on failure to open file
-rw-r--r-- | Source/cmFileCommand.cxx | 14 | ||||
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/file/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Tests/RunCMake/file/FileOpenFailRead-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/file/FileOpenFailRead-stderr.txt | 6 | ||||
-rw-r--r-- | Tests/RunCMake/file/FileOpenFailRead.cmake | 1 | ||||
-rw-r--r-- | Tests/RunCMake/file/RunCMakeTest.cmake | 3 |
7 files changed, 23 insertions, 6 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 5bfb664..4ee34df 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -232,9 +232,10 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args, cmsys::ofstream file(fileName.c_str(), append?std::ios::app: std::ios::out); if ( !file ) { - std::string error = "Internal CMake error when trying to open file: "; - error += fileName.c_str(); - error += " for writing."; + std::string error = "failed to open for writing ("; + error += cmSystemTools::GetLastSystemError(); + error += "):\n "; + error += fileName; this->SetError(error); return false; } @@ -292,9 +293,10 @@ bool cmFileCommand::HandleReadCommand(std::vector<std::string> const& args) if ( !file ) { - std::string error = "Internal CMake error when trying to open file: "; - error += fileName.c_str(); - error += " for reading."; + std::string error = "failed to open for reading ("; + error += cmSystemTools::GetLastSystemError(); + error += "):\n "; + error += fileName; this->SetError(error); return false; } diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 3eeda2f..4efc73a 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -84,6 +84,7 @@ add_RunCMake_test(add_dependencies) add_RunCMake_test(build_command) add_RunCMake_test(export) add_RunCMake_test(cmake_minimum_required) +add_RunCMake_test(file) add_RunCMake_test(find_package) add_RunCMake_test(get_filename_component) add_RunCMake_test(if) diff --git a/Tests/RunCMake/file/CMakeLists.txt b/Tests/RunCMake/file/CMakeLists.txt new file mode 100644 index 0000000..2897109 --- /dev/null +++ b/Tests/RunCMake/file/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.0) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/file/FileOpenFailRead-result.txt b/Tests/RunCMake/file/FileOpenFailRead-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/file/FileOpenFailRead-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/file/FileOpenFailRead-stderr.txt b/Tests/RunCMake/file/FileOpenFailRead-stderr.txt new file mode 100644 index 0000000..23d4337 --- /dev/null +++ b/Tests/RunCMake/file/FileOpenFailRead-stderr.txt @@ -0,0 +1,6 @@ +CMake Error at FileOpenFailRead.cmake:[0-9]+ \(file\): + file failed to open for reading \(.*\): + + .*/Tests/RunCMake/file/does_not_exist/file.txt +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/file/FileOpenFailRead.cmake b/Tests/RunCMake/file/FileOpenFailRead.cmake new file mode 100644 index 0000000..4d4c6dc --- /dev/null +++ b/Tests/RunCMake/file/FileOpenFailRead.cmake @@ -0,0 +1 @@ +file(READ "${CMAKE_CURRENT_SOURCE_DIR}/does_not_exist/file.txt" content) diff --git a/Tests/RunCMake/file/RunCMakeTest.cmake b/Tests/RunCMake/file/RunCMakeTest.cmake new file mode 100644 index 0000000..7b05229 --- /dev/null +++ b/Tests/RunCMake/file/RunCMakeTest.cmake @@ -0,0 +1,3 @@ +include(RunCMake) + +run_cmake(FileOpenFailRead) |