mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-10 00:59:28 -06:00
Merge topic 'process-refactor'
d6111df5cbcmUVStream: Remove unused cmUVPipeIStreamc94d70c345cmUVProcessChain: Open output streams automaticallyca0e9418f3cmUVProcessChain: Simplify representation of merged streams38ee29a66acmUVProcessChain: Build stdout before stderrca0ba19d6dcmUVStream: Fix cmUVIStream constructor compilation with legacy XL compiler5f54ad41e7cmCTestScriptHandler: De-duplicate WaitForLine call6f5bbf9ee7cmSystemTools: Remove unused timeout argument from WaitForLine Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !11532
This commit is contained in:
@@ -10,8 +10,6 @@
|
||||
|
||||
#include <cm/filesystem>
|
||||
|
||||
#include <cm3p/uv.h>
|
||||
|
||||
#include "cmBuildArgs.h"
|
||||
#include "cmBuildOptions.h"
|
||||
#include "cmCTest.h"
|
||||
@@ -22,7 +20,6 @@
|
||||
#include "cmState.h"
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmUVHandlePtr.h"
|
||||
#include "cmUVProcessChain.h"
|
||||
#include "cmUVStream.h"
|
||||
#include "cmWorkingDirectory.h"
|
||||
@@ -94,11 +91,8 @@ bool cmCTestBuildAndTest::RunTest(std::vector<std::string> const& argv,
|
||||
auto chain = builder.Start();
|
||||
|
||||
cmProcessOutput processOutput(cmProcessOutput::Auto);
|
||||
cm::uv_pipe_ptr outputStream;
|
||||
outputStream.init(chain.GetLoop(), 0);
|
||||
uv_pipe_open(outputStream, chain.OutputStream());
|
||||
auto outputHandle = cmUVStreamRead(
|
||||
outputStream,
|
||||
chain.OutputStream(),
|
||||
[&processOutput](std::vector<char> data) {
|
||||
std::string decoded;
|
||||
processOutput.DecodeText(data.data(), data.size(), decoded);
|
||||
|
||||
@@ -872,18 +872,14 @@ bool cmCTestBuildHandler::RunMakeCommand(std::string const& command,
|
||||
}
|
||||
|
||||
// For every chunk of data
|
||||
cm::uv_pipe_ptr outputStream;
|
||||
bool outFinished = false;
|
||||
cm::uv_pipe_ptr errorStream;
|
||||
bool errFinished = false;
|
||||
auto startRead = [this, &chain, &processOutput, &tick,
|
||||
&ofs](cm::uv_pipe_ptr& pipe, int stream,
|
||||
auto startRead = [this, &processOutput, &tick,
|
||||
&ofs](uv_stream_t* stream,
|
||||
t_BuildProcessingQueueType& queue, bool& finished,
|
||||
int id) -> std::unique_ptr<cmUVStreamReadHandle> {
|
||||
pipe.init(chain.GetLoop(), 0);
|
||||
uv_pipe_open(pipe, stream);
|
||||
return cmUVStreamRead(
|
||||
pipe,
|
||||
stream,
|
||||
[this, &processOutput, &queue, id, &tick, &ofs](std::vector<char> data) {
|
||||
// Replace '\0' with '\n', since '\0' does not really make sense. This
|
||||
// is for Visual Studio output
|
||||
@@ -909,11 +905,10 @@ bool cmCTestBuildHandler::RunMakeCommand(std::string const& command,
|
||||
finished = true;
|
||||
});
|
||||
};
|
||||
auto outputHandle = startRead(outputStream, chain.OutputStream(),
|
||||
auto outputHandle = startRead(chain.OutputStream(),
|
||||
this->BuildProcessingQueue, outFinished, 1);
|
||||
auto errorHandle =
|
||||
startRead(errorStream, chain.ErrorStream(),
|
||||
this->BuildProcessingErrorQueue, errFinished, 2);
|
||||
auto errorHandle = startRead(
|
||||
chain.ErrorStream(), this->BuildProcessingErrorQueue, errFinished, 2);
|
||||
|
||||
while (!timedOut && !(outFinished && errFinished && chain.Finished())) {
|
||||
uv_run(&chain.GetLoop(), UV_RUN_ONCE);
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include "cmStateSnapshot.h"
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmUVHandlePtr.h"
|
||||
#include "cmUVProcessChain.h"
|
||||
#include "cmUVStream.h"
|
||||
#include "cmake.h"
|
||||
@@ -236,23 +235,19 @@ void cmCTestLaunch::RunChild()
|
||||
auto chain = builder.Start();
|
||||
|
||||
// Record child stdout and stderr if necessary.
|
||||
cm::uv_pipe_ptr outPipe;
|
||||
cm::uv_pipe_ptr errPipe;
|
||||
bool outFinished = true;
|
||||
bool errFinished = true;
|
||||
cmProcessOutput processOutput;
|
||||
std::unique_ptr<cmUVStreamReadHandle> outputHandle;
|
||||
std::unique_ptr<cmUVStreamReadHandle> errorHandle;
|
||||
if (!this->Reporter.Passthru) {
|
||||
auto beginRead = [&chain, &processOutput](
|
||||
cm::uv_pipe_ptr& pipe, int stream, std::ostream& out,
|
||||
auto beginRead =
|
||||
[&processOutput](uv_stream_t* stream, std::ostream& out,
|
||||
cmsys::ofstream& file, bool& haveData, bool& finished,
|
||||
int id) -> std::unique_ptr<cmUVStreamReadHandle> {
|
||||
pipe.init(chain.GetLoop(), 0);
|
||||
uv_pipe_open(pipe, stream);
|
||||
finished = false;
|
||||
return cmUVStreamRead(
|
||||
pipe,
|
||||
stream,
|
||||
[&processOutput, &out, &file, id, &haveData](std::vector<char> data) {
|
||||
std::string strdata;
|
||||
processOutput.DecodeText(data.data(), data.size(), strdata, id);
|
||||
@@ -270,9 +265,9 @@ void cmCTestLaunch::RunChild()
|
||||
finished = true;
|
||||
});
|
||||
};
|
||||
outputHandle = beginRead(outPipe, chain.OutputStream(), std::cout, fout,
|
||||
outputHandle = beginRead(chain.OutputStream(), std::cout, fout,
|
||||
this->HaveOut, outFinished, 1);
|
||||
errorHandle = beginRead(errPipe, chain.ErrorStream(), std::cerr, ferr,
|
||||
errorHandle = beginRead(chain.ErrorStream(), std::cerr, ferr,
|
||||
this->HaveErr, errFinished, 2);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
file LICENSE.rst or https://cmake.org/licensing for details. */
|
||||
#include "cmCTestScriptHandler.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
@@ -11,8 +10,6 @@
|
||||
|
||||
#include <cm/memory>
|
||||
|
||||
#include <cm3p/uv.h>
|
||||
|
||||
#include "cmCTest.h"
|
||||
#include "cmCTestBuildCommand.h"
|
||||
#include "cmCTestConfigureCommand.h"
|
||||
@@ -34,7 +31,6 @@
|
||||
#include "cmStateDirectory.h"
|
||||
#include "cmStateSnapshot.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmUVHandlePtr.h"
|
||||
#include "cmUVProcessChain.h"
|
||||
#include "cmake.h"
|
||||
|
||||
@@ -108,20 +104,14 @@ int cmCTestScriptHandler::ExecuteScript(std::string const& total_script_arg)
|
||||
.SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT)
|
||||
.SetBuiltinStream(cmUVProcessChainBuilder::Stream_ERROR);
|
||||
auto process = builder.Start();
|
||||
cm::uv_pipe_ptr outPipe;
|
||||
outPipe.init(process.GetLoop(), 0);
|
||||
uv_pipe_open(outPipe, process.OutputStream());
|
||||
cm::uv_pipe_ptr errPipe;
|
||||
errPipe.init(process.GetLoop(), 0);
|
||||
uv_pipe_open(errPipe, process.ErrorStream());
|
||||
|
||||
std::vector<char> out;
|
||||
std::vector<char> err;
|
||||
std::string line;
|
||||
auto pipe =
|
||||
cmSystemTools::WaitForLine(&process.GetLoop(), outPipe, errPipe, line,
|
||||
std::chrono::seconds(100), out, err);
|
||||
while (pipe != cmSystemTools::WaitForLineResult::None) {
|
||||
cmSystemTools::WaitForLineResult pipe;
|
||||
while ((pipe = cmSystemTools::WaitForLine(
|
||||
&process.GetLoop(), process.OutputStream(), process.ErrorStream(),
|
||||
line, out, err)) != cmSystemTools::WaitForLineResult::None) {
|
||||
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
||||
"Output: " << line << "\n");
|
||||
if (pipe == cmSystemTools::WaitForLineResult::STDERR) {
|
||||
@@ -129,9 +119,6 @@ int cmCTestScriptHandler::ExecuteScript(std::string const& total_script_arg)
|
||||
} else if (pipe == cmSystemTools::WaitForLineResult::STDOUT) {
|
||||
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, line << "\n");
|
||||
}
|
||||
pipe =
|
||||
cmSystemTools::WaitForLine(&process.GetLoop(), outPipe, errPipe, line,
|
||||
std::chrono::seconds(100), out, err);
|
||||
}
|
||||
|
||||
// Properly handle output of the build command
|
||||
|
||||
@@ -48,7 +48,7 @@ bool cmBinUtilsLinuxELFObjdumpGetRuntimeDependenciesTool::GetFileInfo(
|
||||
static cmsys::RegularExpression const neededRegex("^ *NEEDED *([^\n]*)$");
|
||||
static cmsys::RegularExpression const rpathRegex("^ *RPATH *([^\n]*)$");
|
||||
static cmsys::RegularExpression const runpathRegex("^ *RUNPATH *([^\n]*)$");
|
||||
cmUVPipeIStream output(process.GetLoop(), process.OutputStream());
|
||||
cmUVIStream output(process.OutputStream());
|
||||
while (std::getline(output, line)) {
|
||||
cmsys::RegularExpressionMatch match;
|
||||
if (neededRegex.find(line.c_str(), match)) {
|
||||
|
||||
@@ -51,7 +51,7 @@ bool cmBinUtilsMacOSMachOOToolGetRuntimeDependenciesTool::GetFileInfo(
|
||||
"^ *path (.*) \\(offset [0-9]+\\)$");
|
||||
static cmsys::RegularExpression const nameRegex(
|
||||
"^ *name (.*) \\(offset [0-9]+\\)$");
|
||||
cmUVPipeIStream output(process.GetLoop(), process.OutputStream());
|
||||
cmUVIStream output(process.OutputStream());
|
||||
while (std::getline(output, line)) {
|
||||
cmsys::RegularExpressionMatch cmdMatch;
|
||||
if (rpathRegex.find(line.c_str(), cmdMatch)) {
|
||||
|
||||
@@ -45,7 +45,7 @@ bool cmBinUtilsWindowsPEDumpbinGetRuntimeDependenciesTool::GetFileInfo(
|
||||
std::string line;
|
||||
static cmsys::RegularExpression const regex(
|
||||
"^ ([^\n]*\\.[Dd][Ll][Ll])\r$");
|
||||
cmUVPipeIStream output(process.GetLoop(), process.OutputStream());
|
||||
cmUVIStream output(process.OutputStream());
|
||||
while (std::getline(output, line)) {
|
||||
cmsys::RegularExpressionMatch match;
|
||||
if (regex.find(line.c_str(), match)) {
|
||||
|
||||
@@ -46,7 +46,7 @@ bool cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool::GetFileInfo(
|
||||
std::string line;
|
||||
static cmsys::RegularExpression const regex(
|
||||
"^[\t ]*DLL Name: ([^\n]*\\.[Dd][Ll][Ll])$");
|
||||
cmUVPipeIStream output(process.GetLoop(), process.OutputStream());
|
||||
cmUVIStream output(process.OutputStream());
|
||||
while (cmSystemTools::GetLineFromStream(output, line)) {
|
||||
cmsys::RegularExpressionMatch match;
|
||||
if (regex.find(line.c_str(), match)) {
|
||||
|
||||
@@ -921,9 +921,7 @@ bool cmCTest::RunMakeCommand(std::string const& command, std::string& output,
|
||||
builder.SetWorkingDirectory(dir);
|
||||
}
|
||||
auto chain = builder.Start();
|
||||
cm::uv_pipe_ptr outputStream;
|
||||
outputStream.init(chain.GetLoop(), 0);
|
||||
uv_pipe_open(outputStream, chain.OutputStream());
|
||||
uv_stream_t* outputStream = chain.OutputStream();
|
||||
|
||||
// Initialize tick's
|
||||
std::string::size_type tick = 0;
|
||||
@@ -3294,19 +3292,14 @@ bool cmCTest::RunCommand(std::vector<std::string> const& args,
|
||||
|
||||
std::vector<char> tempOutput;
|
||||
bool outFinished = false;
|
||||
cm::uv_pipe_ptr outStream;
|
||||
std::vector<char> tempError;
|
||||
bool errFinished = false;
|
||||
cm::uv_pipe_ptr errStream;
|
||||
cmProcessOutput processOutput(encoding);
|
||||
auto startRead = [this, &chain, &processOutput](
|
||||
cm::uv_pipe_ptr& pipe, int stream,
|
||||
std::vector<char>& temp,
|
||||
auto startRead = [this, &processOutput](
|
||||
uv_stream_t* stream, std::vector<char>& temp,
|
||||
bool& finished) -> std::unique_ptr<cmUVStreamReadHandle> {
|
||||
pipe.init(chain.GetLoop(), 0);
|
||||
uv_pipe_open(pipe, stream);
|
||||
return cmUVStreamRead(
|
||||
pipe,
|
||||
stream,
|
||||
[this, &temp, &processOutput](std::vector<char> data) {
|
||||
cm::append(temp, data);
|
||||
if (this->Impl->ExtraVerbose) {
|
||||
@@ -3317,10 +3310,8 @@ bool cmCTest::RunCommand(std::vector<std::string> const& args,
|
||||
},
|
||||
[&finished]() { finished = true; });
|
||||
};
|
||||
auto outputHandle =
|
||||
startRead(outStream, chain.OutputStream(), tempOutput, outFinished);
|
||||
auto errorHandle =
|
||||
startRead(errStream, chain.ErrorStream(), tempError, errFinished);
|
||||
auto outputHandle = startRead(chain.OutputStream(), tempOutput, outFinished);
|
||||
auto errorHandle = startRead(chain.ErrorStream(), tempError, errFinished);
|
||||
while (!timedOut && !(outFinished && errFinished)) {
|
||||
uv_run(&chain.GetLoop(), UV_RUN_ONCE);
|
||||
}
|
||||
|
||||
@@ -326,12 +326,14 @@ bool cmExecuteProcessCommand(std::vector<std::string> const& args,
|
||||
// Read the process output.
|
||||
struct ReadData
|
||||
{
|
||||
uv_stream_t* Stream = nullptr;
|
||||
bool Finished = false;
|
||||
std::vector<char> Output;
|
||||
cm::uv_pipe_ptr Stream;
|
||||
};
|
||||
ReadData outputData;
|
||||
ReadData errorData;
|
||||
outputData.Stream = chain.OutputStream();
|
||||
errorData.Stream = chain.ErrorStream();
|
||||
cmPolicies::PolicyStatus const cmp0176 =
|
||||
status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0176);
|
||||
cmProcessOutput::Encoding encoding =
|
||||
@@ -353,9 +355,7 @@ bool cmExecuteProcessCommand(std::vector<std::string> const& args,
|
||||
std::string strdata;
|
||||
|
||||
std::unique_ptr<cmUVStreamReadHandle> outputHandle;
|
||||
if (chain.OutputStream() >= 0) {
|
||||
outputData.Stream.init(chain.GetLoop(), 0);
|
||||
uv_pipe_open(outputData.Stream, chain.OutputStream());
|
||||
if (outputData.Stream) {
|
||||
outputHandle = cmUVStreamRead(
|
||||
outputData.Stream,
|
||||
[&arguments, &processOutput, &outputData,
|
||||
@@ -377,10 +377,7 @@ bool cmExecuteProcessCommand(std::vector<std::string> const& args,
|
||||
outputData.Finished = true;
|
||||
}
|
||||
std::unique_ptr<cmUVStreamReadHandle> errorHandle;
|
||||
if (chain.ErrorStream() >= 0 &&
|
||||
chain.ErrorStream() != chain.OutputStream()) {
|
||||
errorData.Stream.init(chain.GetLoop(), 0);
|
||||
uv_pipe_open(errorData.Stream, chain.ErrorStream());
|
||||
if (errorData.Stream) {
|
||||
errorHandle = cmUVStreamRead(
|
||||
errorData.Stream,
|
||||
[&arguments, &processOutput, &errorData,
|
||||
|
||||
@@ -201,10 +201,8 @@ void InstallScriptRunner::start(cm::uv_loop_ptr& loop,
|
||||
.SetExternalLoop(*loop)
|
||||
.SetMergedBuiltinStreams();
|
||||
this->chain = cm::make_unique<cmUVProcessChain>(builder.Start());
|
||||
this->pipe.init(this->chain->GetLoop(), 0);
|
||||
uv_pipe_open(this->pipe, this->chain->OutputStream());
|
||||
this->streamHandler = cmUVStreamRead(
|
||||
this->pipe,
|
||||
this->chain->OutputStream(),
|
||||
[this](std::vector<char> data) {
|
||||
std::string strdata;
|
||||
cmProcessOutput(cmProcessOutput::Auto)
|
||||
|
||||
@@ -8,10 +8,13 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cmUVHandlePtr.h"
|
||||
#include "cmUVProcessChain.h"
|
||||
#include "cmUVStream.h"
|
||||
|
||||
namespace cm {
|
||||
class uv_loop_ptr;
|
||||
}
|
||||
|
||||
class cmInstrumentation;
|
||||
|
||||
class cmInstallScriptHandler
|
||||
@@ -42,7 +45,6 @@ public:
|
||||
std::string name;
|
||||
std::unique_ptr<cmUVProcessChain> chain;
|
||||
std::unique_ptr<cmUVStreamReadHandle> streamHandler;
|
||||
cm::uv_pipe_ptr pipe;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
@@ -51,7 +51,7 @@ bool cmLDConfigLDConfigTool::GetLDConfigPaths(std::vector<std::string>& paths)
|
||||
|
||||
std::string line;
|
||||
static cmsys::RegularExpression const regex("^([^\t:]*):");
|
||||
cmUVPipeIStream output(process.GetLoop(), process.OutputStream());
|
||||
cmUVIStream output(process.OutputStream());
|
||||
while (std::getline(output, line)) {
|
||||
cmsys::RegularExpressionMatch match;
|
||||
if (regex.find(line.c_str(), match)) {
|
||||
|
||||
@@ -27,7 +27,7 @@ cm::optional<Json::Value> cmParsePlist(std::string const& filename)
|
||||
|
||||
Json::Reader reader;
|
||||
Json::Value value;
|
||||
cmUVPipeIStream outputStream(chain.GetLoop(), chain.OutputStream());
|
||||
cmUVIStream outputStream(chain.OutputStream());
|
||||
if (!reader.parse(outputStream, value)) {
|
||||
return cm::nullopt;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <cm3p/uv.h>
|
||||
|
||||
#include "cmProcessOutput.h"
|
||||
#include "cmUVHandlePtr.h"
|
||||
#include "cmUVStream.h"
|
||||
|
||||
std::vector<cmUVProcessChain::Status> cmProcessTools::RunProcess(
|
||||
@@ -24,11 +23,8 @@ std::vector<cmUVProcessChain::Status> cmProcessTools::RunProcess(
|
||||
auto chain = builder.Start();
|
||||
|
||||
std::string strdata;
|
||||
cm::uv_pipe_ptr outputPipe;
|
||||
outputPipe.init(chain.GetLoop(), 0);
|
||||
uv_pipe_open(outputPipe, chain.OutputStream());
|
||||
auto outputHandle = cmUVStreamRead(
|
||||
outputPipe,
|
||||
chain.OutputStream(),
|
||||
[&out, &processOutput, &strdata](std::vector<char> data) {
|
||||
if (out) {
|
||||
processOutput.DecodeText(data.data(), data.size(), strdata, 1);
|
||||
@@ -38,11 +34,8 @@ std::vector<cmUVProcessChain::Status> cmProcessTools::RunProcess(
|
||||
}
|
||||
},
|
||||
[&out]() { out = nullptr; });
|
||||
cm::uv_pipe_ptr errorPipe;
|
||||
errorPipe.init(chain.GetLoop(), 0);
|
||||
uv_pipe_open(errorPipe, chain.ErrorStream());
|
||||
auto errorHandle = cmUVStreamRead(
|
||||
errorPipe,
|
||||
chain.ErrorStream(),
|
||||
[&err, &processOutput, &strdata](std::vector<char> data) {
|
||||
if (err) {
|
||||
processOutput.DecodeText(data.data(), data.size(), strdata, 2);
|
||||
|
||||
@@ -896,9 +896,7 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command,
|
||||
|
||||
std::vector<char> tempStdOut;
|
||||
std::vector<char> tempStdErr;
|
||||
cm::uv_pipe_ptr outStream;
|
||||
bool outFinished = true;
|
||||
cm::uv_pipe_ptr errStream;
|
||||
bool errFinished = true;
|
||||
cmProcessOutput processOutput(encoding);
|
||||
std::unique_ptr<cmUVStreamReadHandle> outputHandle;
|
||||
@@ -906,21 +904,14 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command,
|
||||
if (outputflag != OUTPUT_PASSTHROUGH &&
|
||||
(captureStdOut || captureStdErr || outputflag != OUTPUT_NONE)) {
|
||||
auto startRead =
|
||||
[&outputflag, &processOutput,
|
||||
&chain](cm::uv_pipe_ptr& pipe, int stream, std::string* captureStd,
|
||||
std::vector<char>& tempStd, int id,
|
||||
void (*outputFunc)(std::string const&),
|
||||
bool& finished) -> std::unique_ptr<cmUVStreamReadHandle> {
|
||||
if (stream < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
pipe.init(chain.GetLoop(), 0);
|
||||
uv_pipe_open(pipe, stream);
|
||||
|
||||
[&outputflag, &processOutput](
|
||||
uv_stream_t* stream, std::string* captureStd,
|
||||
std::vector<char>& tempStd, int id,
|
||||
void (*outputFunc)(std::string const&),
|
||||
bool& finished) -> std::unique_ptr<cmUVStreamReadHandle> {
|
||||
finished = false;
|
||||
return cmUVStreamRead(
|
||||
pipe,
|
||||
stream,
|
||||
[outputflag, &processOutput, captureStd, &tempStd, id,
|
||||
outputFunc](std::vector<char> data) {
|
||||
// Translate NULL characters in the output into valid text.
|
||||
@@ -951,13 +942,11 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command,
|
||||
});
|
||||
};
|
||||
|
||||
outputHandle =
|
||||
startRead(outStream, chain.OutputStream(), captureStdOut, tempStdOut, 1,
|
||||
cmSystemTools::Stdout, outFinished);
|
||||
if (chain.OutputStream() != chain.ErrorStream()) {
|
||||
errorHandle =
|
||||
startRead(errStream, chain.ErrorStream(), captureStdErr, tempStdErr, 2,
|
||||
cmSystemTools::Stderr, errFinished);
|
||||
outputHandle = startRead(chain.OutputStream(), captureStdOut, tempStdOut,
|
||||
1, cmSystemTools::Stdout, outFinished);
|
||||
if (chain.ErrorStream()) {
|
||||
errorHandle = startRead(chain.ErrorStream(), captureStdErr, tempStdErr,
|
||||
2, cmSystemTools::Stderr, errFinished);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2788,8 +2777,7 @@ bool cmSystemTools::ListTar(std::string const& outFileName,
|
||||
|
||||
cmSystemTools::WaitForLineResult cmSystemTools::WaitForLine(
|
||||
uv_loop_t* loop, uv_stream_t* outPipe, uv_stream_t* errPipe,
|
||||
std::string& line, cmDuration timeout, std::vector<char>& out,
|
||||
std::vector<char>& err)
|
||||
std::string& line, std::vector<char>& out, std::vector<char>& err)
|
||||
{
|
||||
line.clear();
|
||||
auto outiter = out.begin();
|
||||
@@ -2859,22 +2847,7 @@ cmSystemTools::WaitForLineResult cmSystemTools::WaitForLine(
|
||||
ReadData errData;
|
||||
auto errHandle = startRead(errPipe, errData);
|
||||
|
||||
cm::uv_timer_ptr timer;
|
||||
bool timedOut = false;
|
||||
timer.init(*loop, &timedOut);
|
||||
timer.start(
|
||||
[](uv_timer_t* handle) {
|
||||
auto* timedOutPtr = static_cast<bool*>(handle->data);
|
||||
*timedOutPtr = true;
|
||||
},
|
||||
static_cast<uint64_t>(timeout.count() * 1000.0), 0,
|
||||
cm::uv_update_time::no);
|
||||
|
||||
uv_run(loop, UV_RUN_ONCE);
|
||||
if (timedOut) {
|
||||
// Timeout has been exceeded.
|
||||
return WaitForLineResult::Timeout;
|
||||
}
|
||||
if (outData.Read) {
|
||||
processOutput.DecodeText(outData.Buffer.data(), outData.Buffer.size(),
|
||||
strdata, 1);
|
||||
|
||||
@@ -374,13 +374,11 @@ public:
|
||||
None,
|
||||
STDOUT,
|
||||
STDERR,
|
||||
Timeout,
|
||||
};
|
||||
|
||||
/** a general output handler for libuv */
|
||||
static WaitForLineResult WaitForLine(uv_loop_t* loop, uv_stream_t* outPipe,
|
||||
uv_stream_t* errPipe, std::string& line,
|
||||
cmDuration timeout,
|
||||
std::vector<char>& out,
|
||||
std::vector<char>& err);
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ struct cmUVProcessChain::InternalData
|
||||
{
|
||||
struct StreamData
|
||||
{
|
||||
int BuiltinStream = -1;
|
||||
cm::uv_pipe_ptr BuiltinStream;
|
||||
uv_stdio_container_t Stdio;
|
||||
};
|
||||
|
||||
@@ -219,6 +219,44 @@ 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: {
|
||||
int pipeFd[2];
|
||||
if (cmGetPipes(pipeFd) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (outputData.BuiltinStream.init(*this->Loop, 0) < 0) {
|
||||
return false;
|
||||
}
|
||||
if (uv_pipe_open(outputData.BuiltinStream, pipeFd[0]) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this->TempOutputPipe.init(*this->Loop, 0) < 0) {
|
||||
return false;
|
||||
}
|
||||
if (uv_pipe_open(this->TempOutputPipe, pipeFd[1]) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
outputData.Stdio.flags = UV_INHERIT_FD;
|
||||
outputData.Stdio.data.fd = pipeFd[1];
|
||||
} 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;
|
||||
@@ -228,66 +266,37 @@ bool cmUVProcessChain::InternalData::Prepare(
|
||||
break;
|
||||
|
||||
case cmUVProcessChainBuilder::Builtin: {
|
||||
int pipeFd[2];
|
||||
if (cmGetPipes(pipeFd) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
errorData.BuiltinStream = pipeFd[0];
|
||||
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;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case cmUVProcessChainBuilder::External:
|
||||
errorData.Stdio.flags = UV_INHERIT_FD;
|
||||
errorData.Stdio.data.fd = error.FileDescriptor;
|
||||
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.BuiltinStream = errorData.BuiltinStream;
|
||||
outputData.Stdio.flags = UV_INHERIT_FD;
|
||||
outputData.Stdio.data.fd = errorData.Stdio.data.fd;
|
||||
errorData.Stdio.flags = UV_INHERIT_FD;
|
||||
errorData.Stdio.data.fd = outputData.Stdio.data.fd;
|
||||
} else {
|
||||
int pipeFd[2];
|
||||
if (cmGetPipes(pipeFd) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
outputData.BuiltinStream = pipeFd[0];
|
||||
outputData.Stdio.flags = UV_INHERIT_FD;
|
||||
outputData.Stdio.data.fd = pipeFd[1];
|
||||
if (errorData.BuiltinStream.init(*this->Loop, 0) < 0) {
|
||||
return false;
|
||||
}
|
||||
if (uv_pipe_open(errorData.BuiltinStream, pipeFd[0]) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this->TempOutputPipe.init(*this->Loop, 0) < 0) {
|
||||
if (this->TempErrorPipe.init(*this->Loop, 0) < 0) {
|
||||
return false;
|
||||
}
|
||||
if (uv_pipe_open(this->TempOutputPipe, outputData.Stdio.data.fd) < 0) {
|
||||
if (uv_pipe_open(this->TempErrorPipe, pipeFd[1]) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
errorData.Stdio.flags = UV_INHERIT_FD;
|
||||
errorData.Stdio.data.fd = pipeFd[1];
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case cmUVProcessChainBuilder::External:
|
||||
outputData.Stdio.flags = UV_INHERIT_FD;
|
||||
outputData.Stdio.data.fd = output.FileDescriptor;
|
||||
errorData.Stdio.flags = UV_INHERIT_FD;
|
||||
errorData.Stdio.data.fd = error.FileDescriptor;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -439,12 +448,12 @@ uv_loop_t& cmUVProcessChain::GetLoop()
|
||||
return *this->Data->Loop;
|
||||
}
|
||||
|
||||
int cmUVProcessChain::OutputStream()
|
||||
uv_stream_t* cmUVProcessChain::OutputStream()
|
||||
{
|
||||
return this->Data->OutputStreamData.BuiltinStream;
|
||||
}
|
||||
|
||||
int cmUVProcessChain::ErrorStream()
|
||||
uv_stream_t* cmUVProcessChain::ErrorStream()
|
||||
{
|
||||
return this->Data->ErrorStreamData.BuiltinStream;
|
||||
}
|
||||
|
||||
@@ -108,8 +108,8 @@ public:
|
||||
uv_loop_t& GetLoop();
|
||||
|
||||
// FIXME: Add stdin support
|
||||
int OutputStream();
|
||||
int ErrorStream();
|
||||
uv_stream_t* OutputStream();
|
||||
uv_stream_t* ErrorStream();
|
||||
|
||||
bool Valid() const;
|
||||
bool Wait(uint64_t milliseconds = 0);
|
||||
|
||||
@@ -38,7 +38,7 @@ cmBasicUVIStream<CharT, Traits>::cmBasicUVIStream()
|
||||
|
||||
template <typename CharT, typename Traits>
|
||||
cmBasicUVIStream<CharT, Traits>::cmBasicUVIStream(uv_stream_t* stream)
|
||||
: cmBasicUVIStream()
|
||||
: std::basic_istream<CharT, Traits>(&this->Buffer)
|
||||
{
|
||||
this->open(stream);
|
||||
}
|
||||
@@ -63,50 +63,6 @@ void cmBasicUVIStream<CharT, Traits>::close()
|
||||
|
||||
using cmUVIStream = cmBasicUVIStream<char>;
|
||||
|
||||
template <typename CharT, typename Traits = std::char_traits<CharT>>
|
||||
class cmBasicUVPipeIStream : public cmBasicUVIStream<CharT, Traits>
|
||||
{
|
||||
public:
|
||||
cmBasicUVPipeIStream();
|
||||
cmBasicUVPipeIStream(uv_loop_t& loop, int fd);
|
||||
|
||||
using cmBasicUVIStream<CharT, Traits>::is_open;
|
||||
|
||||
void open(uv_loop_t& loop, int fd);
|
||||
|
||||
void close();
|
||||
|
||||
private:
|
||||
cm::uv_pipe_ptr Pipe;
|
||||
};
|
||||
|
||||
template <typename CharT, typename Traits>
|
||||
cmBasicUVPipeIStream<CharT, Traits>::cmBasicUVPipeIStream() = default;
|
||||
|
||||
template <typename CharT, typename Traits>
|
||||
cmBasicUVPipeIStream<CharT, Traits>::cmBasicUVPipeIStream(uv_loop_t& loop,
|
||||
int fd)
|
||||
{
|
||||
this->open(loop, fd);
|
||||
}
|
||||
|
||||
template <typename CharT, typename Traits>
|
||||
void cmBasicUVPipeIStream<CharT, Traits>::open(uv_loop_t& loop, int fd)
|
||||
{
|
||||
this->Pipe.init(loop, 0);
|
||||
uv_pipe_open(this->Pipe, fd);
|
||||
this->cmBasicUVIStream<CharT, Traits>::open(this->Pipe);
|
||||
}
|
||||
|
||||
template <typename CharT, typename Traits>
|
||||
void cmBasicUVPipeIStream<CharT, Traits>::close()
|
||||
{
|
||||
this->cmBasicUVIStream<CharT, Traits>::close();
|
||||
this->Pipe.reset();
|
||||
}
|
||||
|
||||
using cmUVPipeIStream = cmBasicUVPipeIStream<char>;
|
||||
|
||||
class cmUVStreamReadHandle
|
||||
{
|
||||
private:
|
||||
|
||||
@@ -2210,7 +2210,7 @@ int cmcmd::RunPreprocessor(std::vector<std::string> const& command,
|
||||
return 1;
|
||||
}
|
||||
if (process.GetStatus(0).ExitStatus != 0) {
|
||||
cmUVPipeIStream errorStream(process.GetLoop(), process.ErrorStream());
|
||||
cmUVIStream errorStream(process.ErrorStream());
|
||||
std::cerr << errorStream.rdbuf();
|
||||
|
||||
return 1;
|
||||
@@ -2335,7 +2335,7 @@ int cmcmd::RunLLVMRC(std::vector<std::string> const& args)
|
||||
return result;
|
||||
}
|
||||
if (process.GetStatus(0).ExitStatus != 0) {
|
||||
cmUVPipeIStream errorStream(process.GetLoop(), process.ErrorStream());
|
||||
cmUVIStream errorStream(process.ErrorStream());
|
||||
std::cerr << errorStream.rdbuf();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -306,17 +306,17 @@ bool testUVProcessChainBuiltin(char const* helperCommand)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (chain->OutputStream() < 0) {
|
||||
if (!chain->OutputStream()) {
|
||||
std::cout << "OutputStream() was invalid, expecting valid" << std::endl;
|
||||
return false;
|
||||
}
|
||||
if (chain->ErrorStream() < 0) {
|
||||
if (!chain->ErrorStream()) {
|
||||
std::cout << "ErrorStream() was invalid, expecting valid" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
cmUVPipeIStream output(chain->GetLoop(), chain->OutputStream());
|
||||
cmUVPipeIStream error(chain->GetLoop(), chain->ErrorStream());
|
||||
cmUVIStream output(chain->OutputStream());
|
||||
cmUVIStream error(chain->ErrorStream());
|
||||
|
||||
if (!checkOutput(output, error)) {
|
||||
return false;
|
||||
@@ -338,21 +338,16 @@ bool testUVProcessChainBuiltinMerged(char const* helperCommand)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (chain->OutputStream() < 0) {
|
||||
if (!chain->OutputStream()) {
|
||||
std::cout << "OutputStream() was invalid, expecting valid" << std::endl;
|
||||
return false;
|
||||
}
|
||||
if (chain->ErrorStream() < 0) {
|
||||
std::cout << "ErrorStream() was invalid, expecting valid" << std::endl;
|
||||
return false;
|
||||
}
|
||||
if (chain->OutputStream() != chain->ErrorStream()) {
|
||||
std::cout << "OutputStream() and ErrorStream() expected to be the same"
|
||||
<< std::endl;
|
||||
if (chain->ErrorStream()) {
|
||||
std::cout << "ErrorStream() was valid, expecting invalid" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
cmUVPipeIStream mergedStream(chain->GetLoop(), chain->OutputStream());
|
||||
cmUVIStream mergedStream(chain->OutputStream());
|
||||
|
||||
std::string merged = getInput(mergedStream);
|
||||
auto qemuErrorPos = merged.find("qemu:");
|
||||
@@ -412,11 +407,11 @@ bool testUVProcessChainExternal(char const* helperCommand)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (chain->OutputStream() >= 0) {
|
||||
if (chain->OutputStream()) {
|
||||
std::cout << "OutputStream() was valid, expecting invalid" << std::endl;
|
||||
return false;
|
||||
}
|
||||
if (chain->ErrorStream() >= 0) {
|
||||
if (chain->ErrorStream()) {
|
||||
std::cout << "ErrorStream() was valid, expecting invalid" << std::endl;
|
||||
return false;
|
||||
}
|
||||
@@ -460,11 +455,11 @@ bool testUVProcessChainNone(char const* helperCommand)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (chain->OutputStream() >= 0) {
|
||||
if (chain->OutputStream()) {
|
||||
std::cout << "OutputStream() was valid, expecting invalid" << std::endl;
|
||||
return false;
|
||||
}
|
||||
if (chain->ErrorStream() >= 0) {
|
||||
if (chain->ErrorStream()) {
|
||||
std::cout << "ErrorStream() was valid, expecting invalid" << std::endl;
|
||||
return false;
|
||||
}
|
||||
@@ -487,7 +482,7 @@ bool testUVProcessChainCwdUnchanged(char const* helperCommand)
|
||||
return false;
|
||||
}
|
||||
|
||||
cmUVPipeIStream output(chain.GetLoop(), chain.OutputStream());
|
||||
cmUVIStream output(chain.OutputStream());
|
||||
auto cwd = getInput(output);
|
||||
if (!cmHasLiteralSuffix(cwd, "/Tests/CMakeLib")) {
|
||||
std::cout << "Working directory was \"" << cwd
|
||||
@@ -514,7 +509,7 @@ bool testUVProcessChainCwdChanged(char const* helperCommand)
|
||||
return false;
|
||||
}
|
||||
|
||||
cmUVPipeIStream output(chain.GetLoop(), chain.OutputStream());
|
||||
cmUVIStream output(chain.OutputStream());
|
||||
auto cwd = getInput(output);
|
||||
if (!cmHasLiteralSuffix(cwd, "/Tests")) {
|
||||
std::cout << "Working directory was \"" << cwd
|
||||
@@ -649,7 +644,7 @@ bool testUVProcessChainInputFile(char const* helperCommand)
|
||||
return false;
|
||||
}
|
||||
|
||||
cmUVPipeIStream stream(chain.GetLoop(), chain.OutputStream());
|
||||
cmUVIStream stream(chain.OutputStream());
|
||||
std::string output = getInput(stream);
|
||||
if (output != "HELO WRD!") {
|
||||
std::cout << "Output was \"" << output << "\", expected \"HELO WRD!\""
|
||||
@@ -700,7 +695,7 @@ bool testUVProcessChainExternalLoop(char const* helperCommand)
|
||||
return false;
|
||||
}
|
||||
|
||||
cmUVPipeIStream stream(chain.GetLoop(), chain.OutputStream());
|
||||
cmUVIStream stream(chain.OutputStream());
|
||||
std::string output = getInput(stream);
|
||||
if (output != "HELLO world!") {
|
||||
std::cout << "Output was \"" << output << "\", expected \"HELLO world!\""
|
||||
|
||||
@@ -443,7 +443,7 @@ end:
|
||||
return success;
|
||||
}
|
||||
|
||||
bool testUVPipeIStream()
|
||||
bool testUVIStream()
|
||||
{
|
||||
int pipe[] = { -1, -1 };
|
||||
if (cmGetPipes(pipe) < 0) {
|
||||
@@ -464,8 +464,11 @@ bool testUVPipeIStream()
|
||||
buf.len = str.length();
|
||||
uv_write(&writeReq, pipeSink, &buf, 1, nullptr);
|
||||
uv_run(loop, UV_RUN_DEFAULT);
|
||||
cm::uv_pipe_ptr pipeSource;
|
||||
pipeSource.init(*loop, 0);
|
||||
uv_pipe_open(pipeSource, pipe[0]);
|
||||
|
||||
cmUVPipeIStream pin(*loop, pipe[0]);
|
||||
cmUVIStream pin(pipeSource);
|
||||
std::string line;
|
||||
std::getline(pin, line);
|
||||
if (line != "Hello world!") {
|
||||
@@ -593,8 +596,8 @@ int testUVStreambuf(int argc, char** const argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!testUVPipeIStream()) {
|
||||
std::cout << "While executing testUVPipeIStream().\n";
|
||||
if (!testUVIStream()) {
|
||||
std::cout << "While executing testUVIStream().\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user