Commit ec1b6157 authored by Brad King's avatar Brad King 💬
Browse files

Update CMake code using KWSys to account for Status return values

KWSys as of 2021-04-14 changed the return type of `SystemTools`
operations from `bool` to `Status`.  Update our call sites.
This may improve error reporting accuracy in a few places.
parent eef585ef
......@@ -51,15 +51,16 @@ int cmCPackSTGZGenerator::PackageFiles()
* so we must iterate over generated packages.
*/
for (std::string const& pfn : this->packageFileNames) {
retval &= cmSystemTools::SetPermissions(pfn.c_str(),
retval &= static_cast<bool>(
cmSystemTools::SetPermissions(pfn.c_str(),
#if defined(_MSC_VER) || defined(__MINGW32__)
S_IREAD | S_IWRITE | S_IEXEC
S_IREAD | S_IWRITE | S_IEXEC
#else
S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IWGRP | S_IXGRP |
S_IROTH | S_IWOTH | S_IXOTH
S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP |
S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH |
S_IXOTH
#endif
);
));
}
return retval;
}
......
......@@ -921,7 +921,7 @@ bool cmCTestScriptHandler::TryToRemoveBinaryDirectoryOnce(
}
}
return cmSystemTools::RemoveADirectory(directoryPath);
return static_cast<bool>(cmSystemTools::RemoveADirectory(directoryPath));
}
cmDuration cmCTestScriptHandler::GetRemainingTimeAllowed()
......
......@@ -1881,7 +1881,7 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed()
std::string dirName = this->CTest->GetBinaryDir() + "/Testing/Temporary";
cmsys::Directory directory;
if (directory.Load(dirName) == 0) {
if (!directory.Load(dirName)) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Unable to read the contents of " << dirName << std::endl);
return;
......
......@@ -4,7 +4,6 @@
#include <algorithm>
#include <cctype>
#include <cerrno>
#include <chrono>
#include <cstdio>
#include <cstdlib>
......@@ -2842,9 +2841,10 @@ int cmCTest::ExecuteTests()
cmCTestLog(this, OUTPUT,
"Internal ctest changing into directory: " << workDir
<< std::endl);
if (cmSystemTools::ChangeDirectory(workDir) != 0) {
cmsys::Status status = cmSystemTools::ChangeDirectory(workDir);
if (!status) {
auto msg = "Failed to change working directory to \"" + workDir +
"\" : " + std::strerror(errno) + "\n";
"\" : " + status.GetString() + "\n";
cmCTestLog(this, ERROR_MESSAGE, msg);
return 1;
}
......
......@@ -654,10 +654,10 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs,
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
this->IsKeyword(keyIS_NEWER_THAN, *argP1)) {
int fileIsNewer = 0;
bool success = cmSystemTools::FileTimeCompare(
cmsys::Status ftcStatus = cmSystemTools::FileTimeCompare(
arg->GetValue(), (argP2)->GetValue(), &fileIsNewer);
this->HandleBinaryOp(
(!success || fileIsNewer == 1 || fileIsNewer == 0), reducible, arg,
(!ftcStatus || fileIsNewer == 1 || fileIsNewer == 0), reducible, arg,
newArgs, argP1, argP2);
}
......
......@@ -2956,9 +2956,12 @@ bool HandleCreateLinkCommand(std::vector<std::string> const& args,
// Check if copy-on-error is enabled in the arguments.
if (!completed && arguments.CopyOnError) {
completed = cmsys::SystemTools::CopyFileAlways(fileName, newFileName);
if (!completed) {
result = "Copy failed: " + cmSystemTools::GetLastSystemError();
cmsys::Status copied =
cmsys::SystemTools::CopyFileAlways(fileName, newFileName);
if (copied) {
completed = true;
} else {
result = "Copy failed: " + copied.GetString();
}
}
......
......@@ -116,7 +116,7 @@ bool cmQtAutoGenerator::MakeParentDirectory(std::string const& filename)
bool success = true;
std::string const dirName = cmSystemTools::GetFilenamePath(filename);
if (!dirName.empty()) {
success = cmSystemTools::MakeDirectory(dirName);
success = static_cast<bool>(cmSystemTools::MakeDirectory(dirName));
}
return success;
}
......
......@@ -1016,7 +1016,7 @@ cmSystemTools::CopyResult cmSystemTools::CopySingleFile(
}
mode_t perm = 0;
bool perms = SystemTools::GetPermissions(oldname, perm);
cmsys::Status perms = SystemTools::GetPermissions(oldname, perm);
// If files are the same do not copy
if (SystemTools::SameFile(oldname, newname)) {
......@@ -3130,7 +3130,7 @@ bool cmSystemTools::RepeatedRemoveDirectory(const std::string& dir)
}
return false;
#else
return cmSystemTools::RemoveADirectory(dir);
return static_cast<bool>(cmSystemTools::RemoveADirectory(dir));
#endif
}
......
......@@ -12,6 +12,7 @@
#include <cm/string_view>
#include "cmsys/Process.h"
#include "cmsys/Status.hxx" // IWYU pragma: export
#include "cmsys/SystemTools.hxx" // IWYU pragma: export
#include "cmCryptoHash.h"
......
......@@ -19,7 +19,7 @@ cmWorkingDirectory::~cmWorkingDirectory()
bool cmWorkingDirectory::SetDirectory(std::string const& newdir)
{
if (cmSystemTools::ChangeDirectory(newdir) == 0) {
if (cmSystemTools::ChangeDirectory(newdir)) {
this->ResultCode = 0;
return true;
}
......
......@@ -1635,7 +1635,7 @@ bool cmcmd::SymlinkInternal(std::string const& file, std::string const& link)
cmSystemTools::RemoveFile(link);
}
#if defined(_WIN32) && !defined(__CYGWIN__)
return cmSystemTools::CopyFileAlways(file, link);
return static_cast<bool>(cmSystemTools::CopyFileAlways(file, link));
#else
std::string linktext = cmSystemTools::GetFilenameName(file);
return cmSystemTools::CreateSymlink(linktext, link);
......
......@@ -525,6 +525,7 @@ KWSYS_CXX_SOURCES="\
FStream \
Glob \
RegularExpression \
Status \
SystemTools"
KWSYS_FILES="\
......@@ -535,6 +536,7 @@ KWSYS_FILES="\
Glob.hxx \
Process.h \
RegularExpression.hxx \
Status.hxx \
String.h \
String.hxx \
System.h \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment