Utils: Simplify internal ShellCommand::run* function interface

No need to pass some QtcProcess properties in parallel with a
QtcProcess object.

Change-Id: I0c04e5d7db5fd27d8855e661547ec45f417f0fd5
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2021-05-14 12:46:08 +02:00
parent b1dbeafd44
commit 286efd58e8
2 changed files with 9 additions and 18 deletions

View File

@@ -323,12 +323,15 @@ void ShellCommand::runCommand(SynchronousProcess &proc,
if (!(d->m_flags & SuppressCommandLogging)) if (!(d->m_flags & SuppressCommandLogging))
emit proxy->appendCommand(dir, command); emit proxy->appendCommand(dir, command);
proc.setTimeoutS(timeoutS);
proc.setExitCodeInterpreter(interpreter);
if ((d->m_flags & FullySynchronously) if ((d->m_flags & FullySynchronously)
|| (!(d->m_flags & NoFullySync) || (!(d->m_flags & NoFullySync)
&& QThread::currentThread() == QCoreApplication::instance()->thread())) { && QThread::currentThread() == QCoreApplication::instance()->thread())) {
runFullySynchronous(proc, command, proxy, timeoutS, dir, interpreter); runFullySynchronous(proc, command, proxy, dir);
} else { } else {
runSynchronous(proc, command, proxy, timeoutS, dir, interpreter); runSynchronous(proc, command, proxy, dir);
} }
if (!d->m_aborted) { if (!d->m_aborted) {
@@ -345,9 +348,7 @@ void ShellCommand::runCommand(SynchronousProcess &proc,
void ShellCommand::runFullySynchronous(SynchronousProcess &process, void ShellCommand::runFullySynchronous(SynchronousProcess &process,
const CommandLine &cmd, const CommandLine &cmd,
QSharedPointer<OutputProxy> proxy, QSharedPointer<OutputProxy> proxy,
int timeoutS, const QString &workingDirectory)
const QString &workingDirectory,
const ExitCodeInterpreter &interpreter)
{ {
// Set up process // Set up process
if (d->m_disableUnixTerminal) if (d->m_disableUnixTerminal)
@@ -360,8 +361,6 @@ void ShellCommand::runFullySynchronous(SynchronousProcess &process,
process.setProcessChannelMode(QProcess::MergedChannels); process.setProcessChannelMode(QProcess::MergedChannels);
if (d->m_codec) if (d->m_codec)
process.setCodec(d->m_codec); process.setCodec(d->m_codec);
process.setTimeoutS(timeoutS);
process.setExitCodeInterpreter(interpreter);
process.runBlocking(cmd); process.runBlocking(cmd);
@@ -383,14 +382,10 @@ void ShellCommand::runFullySynchronous(SynchronousProcess &process,
void ShellCommand::runSynchronous(SynchronousProcess &process, void ShellCommand::runSynchronous(SynchronousProcess &process,
const CommandLine &cmd, const CommandLine &cmd,
QSharedPointer<OutputProxy> proxy, QSharedPointer<OutputProxy> proxy,
int timeoutS, const QString &workingDirectory)
const QString &workingDirectory,
const ExitCodeInterpreter &interpreter)
{ {
process.setExitCodeInterpreter(interpreter);
connect(this, &ShellCommand::terminate, &process, &SynchronousProcess::stopProcess); connect(this, &ShellCommand::terminate, &process, &SynchronousProcess::stopProcess);
process.setEnvironment(processEnvironment()); process.setEnvironment(processEnvironment());
process.setTimeoutS(timeoutS);
if (d->m_codec) if (d->m_codec)
process.setCodec(d->m_codec); process.setCodec(d->m_codec);
if (d->m_disableUnixTerminal) if (d->m_disableUnixTerminal)
@@ -430,8 +425,6 @@ void ShellCommand::runSynchronous(SynchronousProcess &process,
if (d->m_codec) if (d->m_codec)
process.setCodec(d->m_codec); process.setCodec(d->m_codec);
process.setTimeoutS(timeoutS);
process.setExitCodeInterpreter(interpreter);
process.run(cmd); process.run(cmd);
} }

View File

@@ -171,14 +171,12 @@ private:
void runFullySynchronous(SynchronousProcess &proc, void runFullySynchronous(SynchronousProcess &proc,
const CommandLine &cmd, const CommandLine &cmd,
QSharedPointer<OutputProxy> proxy, QSharedPointer<OutputProxy> proxy,
int timeoutS, const QString &workingDirectory, const QString &workingDirectory);
const ExitCodeInterpreter &interpreter = {});
// Run with an event loop. Signals will be delivered. // Run with an event loop. Signals will be delivered.
void runSynchronous(SynchronousProcess &proc, void runSynchronous(SynchronousProcess &proc,
const CommandLine &cmd, const CommandLine &cmd,
QSharedPointer<OutputProxy> proxy, QSharedPointer<OutputProxy> proxy,
int timeoutS, const QString &workingDirectory, const QString &workingDirectory);
const ExitCodeInterpreter &interpreter = {});
class Internal::ShellCommandPrivate *const d; class Internal::ShellCommandPrivate *const d;
}; };