1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

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.
This commit is contained in:
Brad King
2021-04-14 12:15:54 -04:00
parent eef585efaa
commit ec1b6157cb
12 changed files with 28 additions and 21 deletions

View File

@@ -51,15 +51,16 @@ int cmCPackSTGZGenerator::PackageFiles()
* so we must iterate over generated packages. * so we must iterate over generated packages.
*/ */
for (std::string const& pfn : this->packageFileNames) { 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__) #if defined(_MSC_VER) || defined(__MINGW32__)
S_IREAD | S_IWRITE | S_IEXEC S_IREAD | S_IWRITE | S_IEXEC
#else #else
S_IRUSR | S_IWUSR | S_IXUSR | S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP |
S_IRGRP | S_IWGRP | S_IXGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH |
S_IROTH | S_IWOTH | S_IXOTH S_IXOTH
#endif #endif
); ));
} }
return retval; return retval;
} }

View File

@@ -921,7 +921,7 @@ bool cmCTestScriptHandler::TryToRemoveBinaryDirectoryOnce(
} }
} }
return cmSystemTools::RemoveADirectory(directoryPath); return static_cast<bool>(cmSystemTools::RemoveADirectory(directoryPath));
} }
cmDuration cmCTestScriptHandler::GetRemainingTimeAllowed() cmDuration cmCTestScriptHandler::GetRemainingTimeAllowed()

View File

@@ -1881,7 +1881,7 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed()
std::string dirName = this->CTest->GetBinaryDir() + "/Testing/Temporary"; std::string dirName = this->CTest->GetBinaryDir() + "/Testing/Temporary";
cmsys::Directory directory; cmsys::Directory directory;
if (directory.Load(dirName) == 0) { if (!directory.Load(dirName)) {
cmCTestLog(this->CTest, ERROR_MESSAGE, cmCTestLog(this->CTest, ERROR_MESSAGE,
"Unable to read the contents of " << dirName << std::endl); "Unable to read the contents of " << dirName << std::endl);
return; return;

View File

@@ -4,7 +4,6 @@
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
#include <cerrno>
#include <chrono> #include <chrono>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
@@ -2842,9 +2841,10 @@ int cmCTest::ExecuteTests()
cmCTestLog(this, OUTPUT, cmCTestLog(this, OUTPUT,
"Internal ctest changing into directory: " << workDir "Internal ctest changing into directory: " << workDir
<< std::endl); << std::endl);
if (cmSystemTools::ChangeDirectory(workDir) != 0) { cmsys::Status status = cmSystemTools::ChangeDirectory(workDir);
if (!status) {
auto msg = "Failed to change working directory to \"" + workDir + auto msg = "Failed to change working directory to \"" + workDir +
"\" : " + std::strerror(errno) + "\n"; "\" : " + status.GetString() + "\n";
cmCTestLog(this, ERROR_MESSAGE, msg); cmCTestLog(this, ERROR_MESSAGE, msg);
return 1; return 1;
} }

View File

@@ -654,10 +654,10 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs,
if (argP1 != newArgs.end() && argP2 != newArgs.end() && if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
this->IsKeyword(keyIS_NEWER_THAN, *argP1)) { this->IsKeyword(keyIS_NEWER_THAN, *argP1)) {
int fileIsNewer = 0; int fileIsNewer = 0;
bool success = cmSystemTools::FileTimeCompare( cmsys::Status ftcStatus = cmSystemTools::FileTimeCompare(
arg->GetValue(), (argP2)->GetValue(), &fileIsNewer); arg->GetValue(), (argP2)->GetValue(), &fileIsNewer);
this->HandleBinaryOp( this->HandleBinaryOp(
(!success || fileIsNewer == 1 || fileIsNewer == 0), reducible, arg, (!ftcStatus || fileIsNewer == 1 || fileIsNewer == 0), reducible, arg,
newArgs, argP1, argP2); newArgs, argP1, argP2);
} }

View File

@@ -2956,9 +2956,12 @@ bool HandleCreateLinkCommand(std::vector<std::string> const& args,
// Check if copy-on-error is enabled in the arguments. // Check if copy-on-error is enabled in the arguments.
if (!completed && arguments.CopyOnError) { if (!completed && arguments.CopyOnError) {
completed = cmsys::SystemTools::CopyFileAlways(fileName, newFileName); cmsys::Status copied =
if (!completed) { cmsys::SystemTools::CopyFileAlways(fileName, newFileName);
result = "Copy failed: " + cmSystemTools::GetLastSystemError(); if (copied) {
completed = true;
} else {
result = "Copy failed: " + copied.GetString();
} }
} }

View File

@@ -116,7 +116,7 @@ bool cmQtAutoGenerator::MakeParentDirectory(std::string const& filename)
bool success = true; bool success = true;
std::string const dirName = cmSystemTools::GetFilenamePath(filename); std::string const dirName = cmSystemTools::GetFilenamePath(filename);
if (!dirName.empty()) { if (!dirName.empty()) {
success = cmSystemTools::MakeDirectory(dirName); success = static_cast<bool>(cmSystemTools::MakeDirectory(dirName));
} }
return success; return success;
} }

View File

@@ -1016,7 +1016,7 @@ cmSystemTools::CopyResult cmSystemTools::CopySingleFile(
} }
mode_t perm = 0; 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 files are the same do not copy
if (SystemTools::SameFile(oldname, newname)) { if (SystemTools::SameFile(oldname, newname)) {
@@ -3130,7 +3130,7 @@ bool cmSystemTools::RepeatedRemoveDirectory(const std::string& dir)
} }
return false; return false;
#else #else
return cmSystemTools::RemoveADirectory(dir); return static_cast<bool>(cmSystemTools::RemoveADirectory(dir));
#endif #endif
} }

View File

@@ -12,6 +12,7 @@
#include <cm/string_view> #include <cm/string_view>
#include "cmsys/Process.h" #include "cmsys/Process.h"
#include "cmsys/Status.hxx" // IWYU pragma: export
#include "cmsys/SystemTools.hxx" // IWYU pragma: export #include "cmsys/SystemTools.hxx" // IWYU pragma: export
#include "cmCryptoHash.h" #include "cmCryptoHash.h"

View File

@@ -19,7 +19,7 @@ cmWorkingDirectory::~cmWorkingDirectory()
bool cmWorkingDirectory::SetDirectory(std::string const& newdir) bool cmWorkingDirectory::SetDirectory(std::string const& newdir)
{ {
if (cmSystemTools::ChangeDirectory(newdir) == 0) { if (cmSystemTools::ChangeDirectory(newdir)) {
this->ResultCode = 0; this->ResultCode = 0;
return true; return true;
} }

View File

@@ -1635,7 +1635,7 @@ bool cmcmd::SymlinkInternal(std::string const& file, std::string const& link)
cmSystemTools::RemoveFile(link); cmSystemTools::RemoveFile(link);
} }
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
return cmSystemTools::CopyFileAlways(file, link); return static_cast<bool>(cmSystemTools::CopyFileAlways(file, link));
#else #else
std::string linktext = cmSystemTools::GetFilenameName(file); std::string linktext = cmSystemTools::GetFilenameName(file);
return cmSystemTools::CreateSymlink(linktext, link); return cmSystemTools::CreateSymlink(linktext, link);

View File

@@ -525,6 +525,7 @@ KWSYS_CXX_SOURCES="\
FStream \ FStream \
Glob \ Glob \
RegularExpression \ RegularExpression \
Status \
SystemTools" SystemTools"
KWSYS_FILES="\ KWSYS_FILES="\
@@ -535,6 +536,7 @@ KWSYS_FILES="\
Glob.hxx \ Glob.hxx \
Process.h \ Process.h \
RegularExpression.hxx \ RegularExpression.hxx \
Status.hxx \
String.h \ String.h \
String.hxx \ String.hxx \
System.h \ System.h \