summaryrefslogtreecommitdiffstats
path: root/Source/cmUVProcessChain.cxx
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2023-06-02 14:56:48 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2023-06-08 18:56:26 (GMT)
commitbb5ec5c9b484770e0b0f470da723bdce442a090b (patch)
tree50ed37adcfa59928f64a75c42e328c86564da908 /Source/cmUVProcessChain.cxx
parent6fe39cdfed5cfd0e17c01a88aa40f02d44e8d800 (diff)
downloadCMake-bb5ec5c9b484770e0b0f470da723bdce442a090b.zip
CMake-bb5ec5c9b484770e0b0f470da723bdce442a090b.tar.gz
CMake-bb5ec5c9b484770e0b0f470da723bdce442a090b.tar.bz2
cmUVProcessChain: Do some internal refactoring
Move most of cmUVProcessChain::InternalData::Finish() to Prepare() so that error codes can be checked before attepting to spawn any processes. Check some error codes that weren't being checked before. Change return type of Finish() to void as it can't fail.
Diffstat (limited to 'Source/cmUVProcessChain.cxx')
-rw-r--r--Source/cmUVProcessChain.cxx46
1 files changed, 20 insertions, 26 deletions
diff --git a/Source/cmUVProcessChain.cxx b/Source/cmUVProcessChain.cxx
index ed5f38b..436ada2 100644
--- a/Source/cmUVProcessChain.cxx
+++ b/Source/cmUVProcessChain.cxx
@@ -66,6 +66,7 @@ struct cmUVProcessChain::InternalData
StreamData<std::istream> OutputStreamData;
StreamData<std::istream> ErrorStreamData;
+ cm::uv_pipe_ptr TempErrorPipe;
unsigned int ProcessesCompleted = 0;
std::vector<std::unique_ptr<ProcessData>> Processes;
@@ -73,7 +74,7 @@ struct cmUVProcessChain::InternalData
bool Prepare(const cmUVProcessChainBuilder* builder);
bool AddCommand(const cmUVProcessChainBuilder::ProcessConfiguration& config,
bool first, bool last);
- bool Finish();
+ void Finish();
static const Status* GetStatus(const ProcessData& data);
};
@@ -207,12 +208,23 @@ bool cmUVProcessChain::InternalData::Prepare(
return false;
}
- errorData.BuiltinStream.init(*this->Loop, 0);
+ if (errorData.BuiltinStream.init(*this->Loop, 0) < 0) {
+ return false;
+ }
if (uv_pipe_open(errorData.BuiltinStream, pipeFd[0]) < 0) {
return false;
}
errorData.Stdio.flags = UV_INHERIT_FD;
errorData.Stdio.data.fd = pipeFd[1];
+
+ if (this->TempErrorPipe.init(*this->Loop, 0) < 0) {
+ return false;
+ }
+ if (uv_pipe_open(this->TempErrorPipe, errorData.Stdio.data.fd) < 0) {
+ return false;
+ }
+
+ errorData.Streambuf.open(errorData.BuiltinStream);
break;
}
@@ -235,10 +247,13 @@ bool cmUVProcessChain::InternalData::Prepare(
outputData.Stdio.flags = UV_INHERIT_FD;
outputData.Stdio.data.fd = errorData.Stdio.data.fd;
} else {
- outputData.BuiltinStream.init(*this->Loop, 0);
+ if (outputData.BuiltinStream.init(*this->Loop, 0) < 0) {
+ return false;
+ }
outputData.Stdio.flags =
static_cast<uv_stdio_flags>(UV_CREATE_PIPE | UV_WRITABLE_PIPE);
outputData.Stdio.data.stream = outputData.BuiltinStream;
+ outputData.Streambuf.open(outputData.BuiltinStream);
}
break;
@@ -313,31 +328,10 @@ bool cmUVProcessChain::InternalData::AddCommand(
return process.Process.spawn(*this->Loop, options, &process) >= 0;
}
-bool cmUVProcessChain::InternalData::Finish()
+void cmUVProcessChain::InternalData::Finish()
{
- if (this->Builder->Stdio[cmUVProcessChainBuilder::Stream_OUTPUT].Type ==
- cmUVProcessChainBuilder::Builtin &&
- !this->Builder->MergedBuiltinStreams) {
- this->OutputStreamData.Streambuf.open(
- this->OutputStreamData.BuiltinStream);
- }
-
- if (this->Builder->Stdio[cmUVProcessChainBuilder::Stream_ERROR].Type ==
- cmUVProcessChainBuilder::Builtin) {
- cm::uv_pipe_ptr tmpPipe;
- if (tmpPipe.init(*this->Loop, 0) < 0) {
- return false;
- }
- if (uv_pipe_open(tmpPipe, this->ErrorStreamData.Stdio.data.fd) < 0) {
- return false;
- }
- tmpPipe.reset();
-
- this->ErrorStreamData.Streambuf.open(this->ErrorStreamData.BuiltinStream);
- }
-
+ this->TempErrorPipe.reset();
this->Valid = true;
- return true;
}
cmUVProcessChain::cmUVProcessChain()