Commit d1be129a authored by Tobias Hunger's avatar Tobias Hunger

Utils::ShellCommand: Add runSynchronous method

Add runSynchronous method and move code from runCommand there.

Change-Id: Ic7c452d583fd88468fc6466a683159ecd8328b48
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent c2075f6a
......@@ -326,59 +326,10 @@ Utils::SynchronousProcessResponse ShellCommand::runCommand(const Utils::FileName
if (!(d->m_flags & SuppressCommandLogging))
proxy->appendCommand(dir, binary, arguments);
if (d->m_flags & FullySynchronously) {
if (d->m_flags & FullySynchronously)
response = runFullySynchronous(binary, arguments, proxy.data(), timeoutS, dir, interpreter);
} else {
Utils::SynchronousProcess process;
process.setExitCodeInterpreter(interpreter);
connect(this, &ShellCommand::terminate, &process, &Utils::SynchronousProcess::terminate);
process.setWorkingDirectory(dir);
process.setProcessEnvironment(processEnvironment());
process.setTimeoutS(timeoutS);
if (d->m_codec)
process.setCodec(d->m_codec);
process.setFlags(processFlags());
// connect stderr to the output window if desired
if (d->m_flags & MergeOutputChannels) {
process.setProcessChannelMode(QProcess::MergedChannels);
} else if (d->m_progressiveOutput
|| !(d->m_flags & SuppressStdErr)) {
process.setStdErrBufferedSignalsEnabled(true);
connect(&process, &Utils::SynchronousProcess::stdErrBuffered,
this, [this, proxy](const QString &text)
{
if (!(d->m_flags & SuppressStdErr))
proxy->appendError(text);
if (d->m_progressiveOutput)
emit stdErrText(text);
});
}
// connect stdout to the output window if desired
if (d->m_progressParser || d->m_progressiveOutput || (d->m_flags & ShowStdOut)) {
process.setStdOutBufferedSignalsEnabled(true);
connect(&process, &Utils::SynchronousProcess::stdOutBuffered,
this, [this, proxy](const QString &text)
{
if (d->m_progressParser)
d->m_progressParser->parseProgress(text);
if (d->m_flags & ShowStdOut)
proxy->append(text);
if (d->m_progressiveOutput) {
emit stdOutText(text);
d->m_hadOutput = true;
}
});
}
process.setTimeOutMessageBoxEnabled(true);
// Run!
response = process.runBlocking(binary.toString(), arguments);
}
else
response = runSynchronous(binary, arguments, proxy.data(), timeoutS, dir, interpreter);
if (!d->m_aborted) {
// Success/Fail message in appropriate window?
......@@ -454,6 +405,64 @@ Utils::SynchronousProcessResponse ShellCommand::runFullySynchronous(const Utils:
return response;
}
SynchronousProcessResponse ShellCommand::runSynchronous(const FileName &binary,
const QStringList &arguments,
OutputProxy *proxy,
int timeoutS,
const QString &workingDirectory,
const ExitCodeInterpreter &interpreter)
{
Utils::SynchronousProcess process;
process.setExitCodeInterpreter(interpreter);
connect(this, &ShellCommand::terminate, &process, &Utils::SynchronousProcess::terminate);
process.setWorkingDirectory(workingDirectory);
process.setProcessEnvironment(processEnvironment());
process.setTimeoutS(timeoutS);
if (d->m_codec)
process.setCodec(d->m_codec);
process.setFlags(processFlags());
// connect stderr to the output window if desired
if (d->m_flags & MergeOutputChannels) {
process.setProcessChannelMode(QProcess::MergedChannels);
} else if (d->m_progressiveOutput
|| !(d->m_flags & SuppressStdErr)) {
process.setStdErrBufferedSignalsEnabled(true);
connect(&process, &Utils::SynchronousProcess::stdErrBuffered,
this, [this, proxy](const QString &text)
{
if (!(d->m_flags & SuppressStdErr))
proxy->appendError(text);
if (d->m_progressiveOutput)
emit stdErrText(text);
});
}
// connect stdout to the output window if desired
if (d->m_progressParser || d->m_progressiveOutput || (d->m_flags & ShowStdOut)) {
process.setStdOutBufferedSignalsEnabled(true);
connect(&process, &Utils::SynchronousProcess::stdOutBuffered,
this, [this, proxy](const QString &text)
{
if (d->m_progressParser)
d->m_progressParser->parseProgress(text);
if (d->m_flags & ShowStdOut)
proxy->append(text);
if (d->m_progressiveOutput) {
emit stdOutText(text);
d->m_hadOutput = true;
}
});
}
process.setTimeOutMessageBoxEnabled(true);
// Run!
return process.runBlocking(binary.toString(), arguments);
}
const QVariant &ShellCommand::cookie() const
{
return d->m_cookie;
......
......@@ -166,6 +166,10 @@ private:
OutputProxy *proxy,
int timeoutS, const QString &workingDirectory,
const ExitCodeInterpreter &interpreter = defaultExitCodeInterpreter);
SynchronousProcessResponse runSynchronous(const FileName &binary, const QStringList &arguments,
OutputProxy *proxy,
int timeoutS, const QString &workingDirectory,
const ExitCodeInterpreter &interpreter = defaultExitCodeInterpreter);
class Internal::ShellCommandPrivate *const d;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment