summaryrefslogtreecommitdiffstats
path: root/Source/cmUVProcessChain.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmUVProcessChain.cxx')
-rw-r--r--Source/cmUVProcessChain.cxx69
1 files changed, 47 insertions, 22 deletions
diff --git a/Source/cmUVProcessChain.cxx b/Source/cmUVProcessChain.cxx
index 3faf2f6..257c054 100644
--- a/Source/cmUVProcessChain.cxx
+++ b/Source/cmUVProcessChain.cxx
@@ -140,6 +140,19 @@ cmUVProcessChainBuilder& cmUVProcessChainBuilder::SetExternalStream(
return *this;
}
+cmUVProcessChainBuilder& cmUVProcessChainBuilder::SetMergedBuiltinStreams()
+{
+ this->MergedBuiltinStreams = true;
+ return this->SetBuiltinStream(Stream_OUTPUT).SetBuiltinStream(Stream_ERROR);
+}
+
+cmUVProcessChainBuilder& cmUVProcessChainBuilder::SetWorkingDirectory(
+ std::string dir)
+{
+ this->WorkingDirectory = std::move(dir);
+ return *this;
+}
+
cmUVProcessChain cmUVProcessChainBuilder::Start() const
{
cmUVProcessChain chain;
@@ -174,27 +187,6 @@ bool cmUVProcessChain::InternalData::Prepare(
{
this->Builder = builder;
- auto const& output =
- this->Builder->Stdio[cmUVProcessChainBuilder::Stream_OUTPUT];
- auto& outputData = this->OutputStreamData;
- switch (output.Type) {
- case cmUVProcessChainBuilder::None:
- outputData.Stdio.flags = UV_IGNORE;
- break;
-
- case cmUVProcessChainBuilder::Builtin:
- outputData.BuiltinStream.init(*this->Loop, 0);
- outputData.Stdio.flags =
- static_cast<uv_stdio_flags>(UV_CREATE_PIPE | UV_WRITABLE_PIPE);
- outputData.Stdio.data.stream = outputData.BuiltinStream;
- break;
-
- case cmUVProcessChainBuilder::External:
- outputData.Stdio.flags = UV_INHERIT_FD;
- outputData.Stdio.data.fd = output.FileDescriptor;
- break;
- }
-
auto const& error =
this->Builder->Stdio[cmUVProcessChainBuilder::Stream_ERROR];
auto& errorData = this->ErrorStreamData;
@@ -224,6 +216,32 @@ bool cmUVProcessChain::InternalData::Prepare(
break;
}
+ auto const& output =
+ this->Builder->Stdio[cmUVProcessChainBuilder::Stream_OUTPUT];
+ auto& outputData = this->OutputStreamData;
+ switch (output.Type) {
+ case cmUVProcessChainBuilder::None:
+ outputData.Stdio.flags = UV_IGNORE;
+ break;
+
+ case cmUVProcessChainBuilder::Builtin:
+ if (this->Builder->MergedBuiltinStreams) {
+ outputData.Stdio.flags = UV_INHERIT_FD;
+ outputData.Stdio.data.fd = errorData.Stdio.data.fd;
+ } else {
+ outputData.BuiltinStream.init(*this->Loop, 0);
+ outputData.Stdio.flags =
+ static_cast<uv_stdio_flags>(UV_CREATE_PIPE | UV_WRITABLE_PIPE);
+ outputData.Stdio.data.stream = outputData.BuiltinStream;
+ }
+ break;
+
+ case cmUVProcessChainBuilder::External:
+ outputData.Stdio.flags = UV_INHERIT_FD;
+ outputData.Stdio.data.fd = output.FileDescriptor;
+ break;
+ }
+
return true;
}
@@ -248,6 +266,9 @@ bool cmUVProcessChain::InternalData::AddCommand(
arguments.push_back(nullptr);
options.args = const_cast<char**>(arguments.data());
options.flags = UV_PROCESS_WINDOWS_HIDE;
+ if (!this->Builder->WorkingDirectory.empty()) {
+ options.cwd = this->Builder->WorkingDirectory.c_str();
+ }
std::array<uv_stdio_container_t, 3> stdio;
stdio[0] = uv_stdio_container_t();
@@ -289,7 +310,8 @@ bool cmUVProcessChain::InternalData::AddCommand(
bool cmUVProcessChain::InternalData::Finish()
{
if (this->Builder->Stdio[cmUVProcessChainBuilder::Stream_OUTPUT].Type ==
- cmUVProcessChainBuilder::Builtin) {
+ cmUVProcessChainBuilder::Builtin &&
+ !this->Builder->MergedBuiltinStreams) {
this->OutputStreamData.Streambuf.open(
this->OutputStreamData.BuiltinStream);
}
@@ -339,6 +361,9 @@ uv_loop_t& cmUVProcessChain::GetLoop()
std::istream* cmUVProcessChain::OutputStream()
{
+ if (this->Data->Builder->MergedBuiltinStreams) {
+ return this->Data->ErrorStreamData.GetBuiltinStream();
+ }
return this->Data->OutputStreamData.GetBuiltinStream();
}