diff options
author | Brad King <brad.king@kitware.com> | 2021-04-16 15:40:18 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-04-16 15:40:24 (GMT) |
commit | 09dee5f9baf836d27a437b0efc3b7fa73b3ecc10 (patch) | |
tree | f1248ce69c1508ac5c1dba99a95e9b135f1eb59a | |
parent | bb290fc7a455d014429df452da0c05e83d4f9f34 (diff) | |
parent | c2d2772f15d08f006c0841d4caf028c41f315ca4 (diff) | |
download | CMake-09dee5f9baf836d27a437b0efc3b7fa73b3ecc10.zip CMake-09dee5f9baf836d27a437b0efc3b7fa73b3ecc10.tar.gz CMake-09dee5f9baf836d27a437b0efc3b7fa73b3ecc10.tar.bz2 |
Merge topic 'report-system-error'
c2d2772f15 try_compile: Improve error message when a file cannot be removed
79a2f1e22a cmcmd: Improve error message from cmake_symlink_{library,executable}
7f89053953 cmSystemTools: Return KWSys Status from CreateLink and CreateSymlink
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6007
-rw-r--r-- | Source/cmCoreTryCompile.cxx | 14 | ||||
-rw-r--r-- | Source/cmFileCommand.cxx | 6 | ||||
-rw-r--r-- | Source/cmSystemTools.cxx | 24 | ||||
-rw-r--r-- | Source/cmSystemTools.h | 12 | ||||
-rw-r--r-- | Source/cmcmd.cxx | 23 | ||||
-rw-r--r-- | Source/cmcmd.h | 6 |
6 files changed, 50 insertions, 35 deletions
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 6672aa6..cb84d1d 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -1015,17 +1015,21 @@ void cmCoreTryCompile::CleanupFiles(std::string const& binDir) // cannot delete them immediately. Try a few times. cmSystemTools::WindowsFileRetry retry = cmSystemTools::GetWindowsFileRetry(); - while (!cmSystemTools::RemoveFile(fullPath) && --retry.Count && - cmSystemTools::FileExists(fullPath)) { + cmsys::Status status; + while (!((status = cmSystemTools::RemoveFile(fullPath))) && + --retry.Count && cmSystemTools::FileExists(fullPath)) { cmSystemTools::Delay(retry.Delay); } if (retry.Count == 0) #else - if (!cmSystemTools::RemoveFile(fullPath)) + cmsys::Status status = cmSystemTools::RemoveFile(fullPath); + if (!status) #endif { - std::string m = "Remove failed on file: " + fullPath; - cmSystemTools::ReportLastSystemError(m.c_str()); + this->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("The file:\n ", fullPath, + "\ncould not be removed:\n ", status.GetString())); } } } diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 26bdedf..05ebcca 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -2949,9 +2949,11 @@ bool HandleCreateLinkCommand(std::vector<std::string> const& args, // Check if the command requires a symbolic link. if (arguments.Symbolic) { - completed = cmSystemTools::CreateSymlink(fileName, newFileName, &result); + completed = static_cast<bool>( + cmSystemTools::CreateSymlink(fileName, newFileName, &result)); } else { - completed = cmSystemTools::CreateLink(fileName, newFileName, &result); + completed = static_cast<bool>( + cmSystemTools::CreateLink(fileName, newFileName, &result)); } // Check if copy-on-error is enabled in the arguments. diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 2b3266d..5382fac 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -3158,9 +3158,9 @@ std::string cmSystemTools::EncodeURL(std::string const& in, bool escapeSlashes) return out; } -bool cmSystemTools::CreateSymlink(const std::string& origName, - const std::string& newName, - std::string* errorMessage) +cmsys::Status cmSystemTools::CreateSymlink(std::string const& origName, + std::string const& newName, + std::string* errorMessage) { uv_fs_t req; int flags = 0; @@ -3171,7 +3171,9 @@ bool cmSystemTools::CreateSymlink(const std::string& origName, #endif int err = uv_fs_symlink(nullptr, &req, origName.c_str(), newName.c_str(), flags, nullptr); + cmsys::Status status; if (err) { + status = cmsys::Status::POSIX(-err); std::string e = "failed to create symbolic link '" + newName + "': " + uv_strerror(err); if (errorMessage) { @@ -3179,20 +3181,20 @@ bool cmSystemTools::CreateSymlink(const std::string& origName, } else { cmSystemTools::Error(e); } - return false; } - - return true; + return status; } -bool cmSystemTools::CreateLink(const std::string& origName, - const std::string& newName, - std::string* errorMessage) +cmsys::Status cmSystemTools::CreateLink(std::string const& origName, + std::string const& newName, + std::string* errorMessage) { uv_fs_t req; int err = uv_fs_link(nullptr, &req, origName.c_str(), newName.c_str(), nullptr); + cmsys::Status status; if (err) { + status = cmsys::Status::POSIX(-err); std::string e = "failed to create link '" + newName + "': " + uv_strerror(err); if (errorMessage) { @@ -3200,10 +3202,8 @@ bool cmSystemTools::CreateLink(const std::string& origName, } else { cmSystemTools::Error(e); } - return false; } - - return true; + return status; } cm::string_view cmSystemTools::GetSystemName() diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 99f20e0..0aecf71 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -489,15 +489,15 @@ public: /** Create a symbolic link if the platform supports it. Returns whether creation succeeded. */ - static bool CreateSymlink(const std::string& origName, - const std::string& newName, - std::string* errorMessage = nullptr); + static cmsys::Status CreateSymlink(std::string const& origName, + std::string const& newName, + std::string* errorMessage = nullptr); /** Create a hard link if the platform supports it. Returns whether creation succeeded. */ - static bool CreateLink(const std::string& origName, - const std::string& newName, - std::string* errorMessage = nullptr); + static cmsys::Status CreateLink(std::string const& origName, + std::string const& newName, + std::string* errorMessage = nullptr); /** Get the system name. */ static cm::string_view GetSystemName(); diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index a47eccd..928435e 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -1601,14 +1601,18 @@ int cmcmd::SymlinkLibrary(std::vector<std::string> const& args) cmSystemTools::ConvertToUnixSlashes(soName); cmSystemTools::ConvertToUnixSlashes(name); if (soName != realName) { - if (!cmcmd::SymlinkInternal(realName, soName)) { - cmSystemTools::ReportLastSystemError("cmake_symlink_library"); + cmsys::Status status = cmcmd::SymlinkInternal(realName, soName); + if (!status) { + cmSystemTools::Error( + cmStrCat("cmake_symlink_library: System Error: ", status.GetString())); result = 1; } } if (name != soName) { - if (!cmcmd::SymlinkInternal(soName, name)) { - cmSystemTools::ReportLastSystemError("cmake_symlink_library"); + cmsys::Status status = cmcmd::SymlinkInternal(soName, name); + if (!status) { + cmSystemTools::Error( + cmStrCat("cmake_symlink_library: System Error: ", status.GetString())); result = 1; } } @@ -1621,21 +1625,24 @@ int cmcmd::SymlinkExecutable(std::vector<std::string> const& args) std::string const& realName = args[2]; std::string const& name = args[3]; if (name != realName) { - if (!cmcmd::SymlinkInternal(realName, name)) { - cmSystemTools::ReportLastSystemError("cmake_symlink_executable"); + cmsys::Status status = cmcmd::SymlinkInternal(realName, name); + if (!status) { + cmSystemTools::Error(cmStrCat("cmake_symlink_executable: System Error: ", + status.GetString())); result = 1; } } return result; } -bool cmcmd::SymlinkInternal(std::string const& file, std::string const& link) +cmsys::Status cmcmd::SymlinkInternal(std::string const& file, + std::string const& link) { if (cmSystemTools::FileExists(link) || cmSystemTools::FileIsSymlink(link)) { cmSystemTools::RemoveFile(link); } #if defined(_WIN32) && !defined(__CYGWIN__) - return static_cast<bool>(cmSystemTools::CopyFileAlways(file, link)); + return cmSystemTools::CopyFileAlways(file, link); #else std::string linktext = cmSystemTools::GetFilenameName(file); return cmSystemTools::CreateSymlink(linktext, link); diff --git a/Source/cmcmd.h b/Source/cmcmd.h index a2e0b1e..ba78edb 100644 --- a/Source/cmcmd.h +++ b/Source/cmcmd.h @@ -8,6 +8,8 @@ #include <string> #include <vector> +#include "cmsys/Status.hxx" + #include "cmCryptoHash.h" class cmConsoleBuf; @@ -28,8 +30,8 @@ protected: cmCryptoHash::Algo algo); static int SymlinkLibrary(std::vector<std::string> const& args); static int SymlinkExecutable(std::vector<std::string> const& args); - static bool SymlinkInternal(std::string const& file, - std::string const& link); + static cmsys::Status SymlinkInternal(std::string const& file, + std::string const& link); static int ExecuteEchoColor(std::vector<std::string> const& args); static int ExecuteLinkScript(std::vector<std::string> const& args); static int WindowsCEEnvironment(const char* version, |