mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 21:59:54 -06:00
ctest_empty_binary_directory: Report more detail in failure message
This commit is contained in:
@@ -2,25 +2,27 @@
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
#include "cmCTestEmptyBinaryDirectoryCommand.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "cmCTestScriptHandler.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
#include "cmExecutionStatus.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmMessageType.h"
|
||||
#include "cmStringAlgorithms.h"
|
||||
|
||||
bool cmCTestEmptyBinaryDirectoryCommand::InitialPass(
|
||||
std::vector<std::string> const& args, cmExecutionStatus& /*unused*/)
|
||||
std::vector<std::string> const& args, cmExecutionStatus& status)
|
||||
{
|
||||
if (args.size() != 1) {
|
||||
this->SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!cmCTestScriptHandler::EmptyBinaryDirectory(args[0])) {
|
||||
std::ostringstream ostr;
|
||||
ostr << "problem removing the binary directory: " << args[0];
|
||||
this->SetError(ostr.str());
|
||||
return false;
|
||||
std::string err;
|
||||
if (!cmCTestScriptHandler::EmptyBinaryDirectory(args[0], err)) {
|
||||
status.GetMakefile().IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("Did not remove the binary directory:\n ", args[0],
|
||||
"\nbecause:\n ", err));
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -672,9 +672,11 @@ int cmCTestScriptHandler::RunConfigurationDashboard()
|
||||
|
||||
// clear the binary directory?
|
||||
if (this->EmptyBinDir) {
|
||||
if (!cmCTestScriptHandler::EmptyBinaryDirectory(this->BinaryDir)) {
|
||||
std::string err;
|
||||
if (!cmCTestScriptHandler::EmptyBinaryDirectory(this->BinaryDir, err)) {
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
||||
"Problem removing the binary directory" << std::endl);
|
||||
"Problem removing the binary directory ("
|
||||
<< err << "): " << this->BinaryDir << std::endl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -860,10 +862,12 @@ bool cmCTestScriptHandler::RunScript(cmCTest* ctest, cmMakefile* mf,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cmCTestScriptHandler::EmptyBinaryDirectory(const std::string& sname)
|
||||
bool cmCTestScriptHandler::EmptyBinaryDirectory(const std::string& sname,
|
||||
std::string& err)
|
||||
{
|
||||
// try to avoid deleting root
|
||||
if (sname.size() < 2) {
|
||||
err = "path too short";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -876,20 +880,24 @@ bool cmCTestScriptHandler::EmptyBinaryDirectory(const std::string& sname)
|
||||
std::string check = cmStrCat(sname, "/CMakeCache.txt");
|
||||
|
||||
if (!cmSystemTools::FileExists(check)) {
|
||||
err = "path does not contain an existing CMakeCache.txt file";
|
||||
return false;
|
||||
}
|
||||
|
||||
cmsys::Status status;
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
if (TryToRemoveBinaryDirectoryOnce(sname)) {
|
||||
status = TryToRemoveBinaryDirectoryOnce(sname);
|
||||
if (status) {
|
||||
return true;
|
||||
}
|
||||
cmSystemTools::Delay(100);
|
||||
}
|
||||
|
||||
err = status.GetString();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cmCTestScriptHandler::TryToRemoveBinaryDirectoryOnce(
|
||||
cmsys::Status cmCTestScriptHandler::TryToRemoveBinaryDirectoryOnce(
|
||||
const std::string& directoryPath)
|
||||
{
|
||||
cmsys::Directory directory;
|
||||
@@ -907,18 +915,18 @@ bool cmCTestScriptHandler::TryToRemoveBinaryDirectoryOnce(
|
||||
bool isDirectory = cmSystemTools::FileIsDirectory(fullPath) &&
|
||||
!cmSystemTools::FileIsSymlink(fullPath);
|
||||
|
||||
cmsys::Status status;
|
||||
if (isDirectory) {
|
||||
if (!cmSystemTools::RemoveADirectory(fullPath)) {
|
||||
return false;
|
||||
}
|
||||
status = cmSystemTools::RemoveADirectory(fullPath);
|
||||
} else {
|
||||
if (!cmSystemTools::RemoveFile(fullPath)) {
|
||||
return false;
|
||||
}
|
||||
status = cmSystemTools::RemoveFile(fullPath);
|
||||
}
|
||||
if (!status) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
return static_cast<bool>(cmSystemTools::RemoveADirectory(directoryPath));
|
||||
return cmSystemTools::RemoveADirectory(directoryPath);
|
||||
}
|
||||
|
||||
cmDuration cmCTestScriptHandler::GetRemainingTimeAllowed()
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cmsys/Status.hxx"
|
||||
|
||||
#include "cmCTestGenericHandler.h"
|
||||
#include "cmDuration.h"
|
||||
|
||||
@@ -80,7 +82,7 @@ public:
|
||||
/*
|
||||
* Empty Binary Directory
|
||||
*/
|
||||
static bool EmptyBinaryDirectory(const std::string& dir);
|
||||
static bool EmptyBinaryDirectory(const std::string& dir, std::string& err);
|
||||
|
||||
/*
|
||||
* Write an initial CMakeCache.txt from the given contents.
|
||||
@@ -139,7 +141,8 @@ private:
|
||||
std::unique_ptr<cmCTestCommand> command);
|
||||
|
||||
// Try to remove the binary directory once
|
||||
static bool TryToRemoveBinaryDirectoryOnce(const std::string& directoryPath);
|
||||
static cmsys::Status TryToRemoveBinaryDirectoryOnce(
|
||||
const std::string& directoryPath);
|
||||
|
||||
std::vector<std::string> ConfigurationScripts;
|
||||
std::vector<bool> ScriptProcessScope;
|
||||
|
||||
@@ -511,6 +511,7 @@ add_RunCMake_test(ctest_skipped_test)
|
||||
add_RunCMake_test(ctest_update)
|
||||
add_RunCMake_test(ctest_upload)
|
||||
add_RunCMake_test(ctest_environment)
|
||||
add_RunCMake_test(ctest_empty_binary_directory)
|
||||
add_RunCMake_test(ctest_fixtures)
|
||||
add_RunCMake_test(define_property)
|
||||
add_RunCMake_test(file -DCYGWIN=${CYGWIN} -DMSYS=${MSYS})
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(CTestTest@CASE_NAME@ NONE)
|
||||
@@ -0,0 +1 @@
|
||||
(-1|255)
|
||||
@@ -0,0 +1,12 @@
|
||||
^CMake Error at [^
|
||||
]*/Tests/RunCMake/ctest_empty_binary_directory/NoCache/test.cmake:[0-9]+ \(ctest_empty_binary_directory\):
|
||||
Did not remove the binary directory:
|
||||
|
||||
[^
|
||||
]*/Tests/RunCMake/ctest_empty_binary_directory/NoCache-build
|
||||
|
||||
because:
|
||||
|
||||
path does not contain an existing CMakeCache\.txt file
|
||||
+
|
||||
script continues after ctest_empty_binary_directory error$
|
||||
@@ -0,0 +1,3 @@
|
||||
include(RunCTest)
|
||||
|
||||
run_ctest(NoCache)
|
||||
@@ -0,0 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
set(CTEST_SOURCE_DIRECTORY "@RunCMake_BINARY_DIR@/@CASE_NAME@")
|
||||
set(CTEST_BINARY_DIRECTORY "@RunCMake_BINARY_DIR@/@CASE_NAME@-build")
|
||||
ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY})
|
||||
message("script continues after ctest_empty_binary_directory error")
|
||||
Reference in New Issue
Block a user