summaryrefslogtreecommitdiffstats
path: root/Source/CTest/cmProcess.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/CTest/cmProcess.cxx')
-rw-r--r--Source/CTest/cmProcess.cxx56
1 files changed, 37 insertions, 19 deletions
diff --git a/Source/CTest/cmProcess.cxx b/Source/CTest/cmProcess.cxx
index f4ec6da..69ffb33 100644
--- a/Source/CTest/cmProcess.cxx
+++ b/Source/CTest/cmProcess.cxx
@@ -2,19 +2,27 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmProcess.h"
-#include "cmConfigure.h"
#include "cmProcessOutput.h"
-#include "cmSystemTools.h"
#include <iostream>
+void cmsysProcess_SetTimeout(cmsysProcess* process,
+ std::chrono::duration<double> timeout)
+{
+ cmsysProcess_SetTimeout(
+ process,
+ double(
+ std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count()) /
+ 1000.0);
+};
+
cmProcess::cmProcess()
{
- this->Process = CM_NULLPTR;
- this->Timeout = 0;
- this->TotalTime = 0;
+ this->Process = nullptr;
+ this->Timeout = std::chrono::duration<double>::zero();
+ this->TotalTime = std::chrono::duration<double>::zero();
this->ExitValue = 0;
this->Id = 0;
- this->StartTime = 0;
+ this->StartTime = std::chrono::steady_clock::time_point();
}
cmProcess::~cmProcess()
@@ -36,16 +44,15 @@ bool cmProcess::StartProcess()
if (this->Command.empty()) {
return false;
}
- this->StartTime = cmSystemTools::GetTime();
+ this->StartTime = std::chrono::steady_clock::now();
this->ProcessArgs.clear();
// put the command as arg0
this->ProcessArgs.push_back(this->Command.c_str());
// now put the command arguments in
- for (std::vector<std::string>::iterator i = this->Arguments.begin();
- i != this->Arguments.end(); ++i) {
- this->ProcessArgs.push_back(i->c_str());
+ for (std::string const& arg : this->Arguments) {
+ this->ProcessArgs.push_back(arg.c_str());
}
- this->ProcessArgs.push_back(CM_NULLPTR); // null terminate the list
+ this->ProcessArgs.push_back(nullptr); // null terminate the list
this->Process = cmsysProcess_New();
cmsysProcess_SetCommand(this->Process, &*this->ProcessArgs.begin());
if (!this->WorkingDirectory.empty()) {
@@ -103,10 +110,15 @@ bool cmProcess::Buffer::GetLast(std::string& line)
return false;
}
-int cmProcess::GetNextOutputLine(std::string& line, double timeout)
+int cmProcess::GetNextOutputLine(std::string& line,
+ std::chrono::duration<double> timeout)
{
cmProcessOutput processOutput(cmProcessOutput::UTF8);
std::string strdata;
+ double waitTimeout =
+ double(
+ std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count()) /
+ 1000.0;
for (;;) {
// Look for lines already buffered.
if (this->Output.GetLine(line)) {
@@ -116,7 +128,8 @@ int cmProcess::GetNextOutputLine(std::string& line, double timeout)
// Check for more data from the process.
char* data;
int length;
- int p = cmsysProcess_WaitForData(this->Process, &data, &length, &timeout);
+ int p =
+ cmsysProcess_WaitForData(this->Process, &data, &length, &waitTimeout);
if (p == cmsysProcess_Pipe_Timeout) {
return cmsysProcess_Pipe_Timeout;
}
@@ -139,19 +152,19 @@ int cmProcess::GetNextOutputLine(std::string& line, double timeout)
}
// No more data. Wait for process exit.
- if (!cmsysProcess_WaitForExit(this->Process, &timeout)) {
+ if (!cmsysProcess_WaitForExit(this->Process, &waitTimeout)) {
return cmsysProcess_Pipe_Timeout;
}
// Record exit information.
this->ExitValue = cmsysProcess_GetExitValue(this->Process);
- this->TotalTime = cmSystemTools::GetTime() - this->StartTime;
+ this->TotalTime = std::chrono::steady_clock::now() - this->StartTime;
// Because of a processor clock scew the runtime may become slightly
// negative. If someone changed the system clock while the process was
// running this may be even more. Make sure not to report a negative
// duration here.
- if (this->TotalTime <= 0.0) {
- this->TotalTime = 0.0;
+ if (this->TotalTime <= std::chrono::duration<double>::zero()) {
+ this->TotalTime = std::chrono::duration<double>::zero();
}
// std::cerr << "Time to run: " << this->TotalTime << "\n";
return cmsysProcess_Pipe_None;
@@ -224,7 +237,7 @@ int cmProcess::ReportStatus()
return result;
}
-void cmProcess::ChangeTimeout(double t)
+void cmProcess::ChangeTimeout(std::chrono::duration<double> t)
{
this->Timeout = t;
cmsysProcess_SetTimeout(this->Process, this->Timeout);
@@ -233,10 +246,15 @@ void cmProcess::ChangeTimeout(double t)
void cmProcess::ResetStartTime()
{
cmsysProcess_ResetStartTime(this->Process);
- this->StartTime = cmSystemTools::GetTime();
+ this->StartTime = std::chrono::steady_clock::now();
}
int cmProcess::GetExitException()
{
return cmsysProcess_GetExitException(this->Process);
}
+
+std::string cmProcess::GetExitExceptionString()
+{
+ return cmsysProcess_GetExceptionString(this->Process);
+}