Utils: Simplify QtcProcess::exitMessage() interface

This was requiring parameters the process object already knows.

This is a slight behavior change in most cases, it now includes
always the command line arguments, which previously only happened
in gcctoolchain.cpp and iarewtoolchain.cpp.

Change-Id: Id25a68c397e2f1d8bf52ab29210e215b1de46c6d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2021-05-14 13:12:46 +02:00
parent 3113b0e6d6
commit b2dc771d80
18 changed files with 28 additions and 31 deletions

View File

@@ -132,7 +132,7 @@ QString BuildableHelperLibrary::qtVersionForQMake(const QString &qmakePath)
qmake.setTimeoutS(5);
qmake.runBlocking({qmakePath, {"--version"}});
if (qmake.result() != QtcProcess::Finished) {
qWarning() << qmake.exitMessage(qmakePath, 5);
qWarning() << qmake.exitMessage();
return QString();
}

View File

@@ -608,20 +608,22 @@ void SynchronousProcessResponse::clear()
rawStdErr.clear();
}
QString QtcProcess::exitMessage(const QString &binary, int timeoutS) const
QString QtcProcess::exitMessage()
{
const QString fullCmd = commandLine().toUserOutput();
switch (result()) {
case Finished:
return QtcProcess::tr("The command \"%1\" finished successfully.").arg(QDir::toNativeSeparators(binary));
return QtcProcess::tr("The command \"%1\" finished successfully.").arg(fullCmd);
case FinishedError:
return QtcProcess::tr("The command \"%1\" terminated with exit code %2.").arg(QDir::toNativeSeparators(binary)).arg(exitCode());
return QtcProcess::tr("The command \"%1\" terminated with exit code %2.")
.arg(fullCmd).arg(exitCode());
case TerminatedAbnormally:
return QtcProcess::tr("The command \"%1\" terminated abnormally.").arg(QDir::toNativeSeparators(binary));
return QtcProcess::tr("The command \"%1\" terminated abnormally.").arg(fullCmd);
case StartFailed:
return QtcProcess::tr("The command \"%1\" could not be started.").arg(QDir::toNativeSeparators(binary));
return QtcProcess::tr("The command \"%1\" could not be started.").arg(fullCmd);
case Hang:
return QtcProcess::tr("The command \"%1\" did not respond within the timeout limit (%2 s).")
.arg(QDir::toNativeSeparators(binary)).arg(timeoutS);
.arg(fullCmd).arg(d->m_hangTimerCount);
}
return QString();
}

View File

@@ -118,9 +118,7 @@ public:
int exitCode() const;
// Helper to format an exit message.
QString exitMessage(const QString &binary, int timeoutS) const;
QString exitMessage();
// Helpers to find binaries. Do not use it for other path variables
// and file types.

View File

@@ -338,9 +338,9 @@ void ShellCommand::runCommand(SynchronousProcess &proc,
// Success/Fail message in appropriate window?
if (proc.result() == QtcProcess::Finished) {
if (d->m_flags & ShowSuccessMessage)
emit proxy->appendMessage(proc.exitMessage(command.executable().toUserOutput(), timeoutS));
emit proxy->appendMessage(proc.exitMessage());
} else if (!(d->m_flags & SuppressFailMessage)) {
emit proxy->appendError(proc.exitMessage(command.executable().toUserOutput(), timeoutS));
emit proxy->appendError(proc.exitMessage());
}
}
}

View File

@@ -202,8 +202,7 @@ void AndroidCreateKeystoreCertificate::buttonBoxAccepted()
if (genKeyCertProc.result() != QtcProcess::Finished || genKeyCertProc.exitCode() != 0) {
QMessageBox::critical(this, tr("Error"),
genKeyCertProc.exitMessage(command.executable().toString(), 15)
+ '\n' + genKeyCertProc.allOutput());
genKeyCertProc.exitMessage() + '\n' + genKeyCertProc.allOutput());
return;
}
accept();

View File

@@ -481,9 +481,10 @@ void AndroidDeployQtStep::runCommand(const CommandLine &command)
buildProc.setTimeoutS(2 * 60);
emit addOutput(tr("Package deploy: Running command \"%1\".").arg(command.toUserOutput()),
OutputFormat::NormalMessage);
buildProc.run(command);
if (buildProc.result() != QtcProcess::Finished || buildProc.exitCode() != 0) {
const QString error = buildProc.exitMessage(command.executable().toString(), 2 * 60);
const QString error = buildProc.exitMessage();
emit addOutput(error, OutputFormat::ErrorMessage);
TaskHub::addTask(DeploymentTask(Task::Error, error));
}

View File

@@ -730,7 +730,7 @@ SdkToolResult AndroidManager::runCommand(const CommandLine &command,
<< "Success:" << cmdResult.m_success
<< "Output:" << cmdProc.allRawOutput();
if (!cmdResult.success())
cmdResult.m_exitMessage = cmdProc.exitMessage(command.executable().toString(), timeoutS);
cmdResult.m_exitMessage = cmdProc.exitMessage();
return cmdResult;
}

View File

@@ -113,7 +113,7 @@ static Macros dumpPredefinedMacros(const FilePath &compiler, const QStringList &
cpp.runBlocking(cmd);
if (cpp.result() != QtcProcess::Finished || cpp.exitCode() != 0) {
qWarning() << cpp.exitMessage(cmd.toUserOutput(), 10);
qWarning() << cpp.exitMessage();
return {};
}

View File

@@ -288,7 +288,7 @@ static Macros dumpArmPredefinedMacros(const FilePath &compiler, const QStringLis
cpp.runBlocking(cmd);
if (cpp.result() != QtcProcess::Finished || cpp.exitCode() != 0) {
qWarning() << cpp.exitMessage(compiler.toString(), 10);
qWarning() << cpp.exitMessage();
return {};
}

View File

@@ -95,7 +95,7 @@ static Macros dumpPredefinedMacros(const FilePath &compiler, const Environment &
cpp.runBlocking(cmd);
if (cpp.result() != QtcProcess::Finished || cpp.exitCode() != 0) {
qWarning() << cpp.exitMessage(compiler.toString(), 10);
qWarning() << cpp.exitMessage();
return {};
}
@@ -117,7 +117,7 @@ static HeaderPaths dumpHeaderPaths(const FilePath &compiler, const Environment &
cpp.runBlocking(cmd);
if (cpp.result() != QtcProcess::Finished || cpp.exitCode() != 0) {
qWarning() << cpp.exitMessage(compiler.toString(), 10);
qWarning() << cpp.exitMessage();
return {};
}

View File

@@ -59,7 +59,7 @@ static QString runExecutable(const Utils::CommandLine &commandLine,
if (cpp.result() != QtcProcess::Finished
&& (failSilently == FailSilently::No
|| cpp.result() != QtcProcess::FinishedError)) {
Core::MessageManager::writeFlashing(cpp.exitMessage(commandLine.toUserOutput(), 10));
Core::MessageManager::writeFlashing(cpp.exitMessage());
Core::MessageManager::writeFlashing(QString::fromUtf8(cpp.allRawOutput()));
return {};
}

View File

@@ -1676,7 +1676,7 @@ ClearCasePluginPrivate::runCleartool(const QString &workingDir,
response.error = proc.result() != QtcProcess::Finished;
if (response.error)
response.message = proc.exitMessage(executable, timeOutS);
response.message = proc.exitMessage();
response.stdErr = proc.stdErr();
response.stdOut = proc.stdOut();
return response;

View File

@@ -1470,7 +1470,7 @@ CvsResponse CvsPluginPrivate::runCvs(const QString &workingDirectory,
}
if (response.result != CvsResponse::Ok)
response.message = proc.exitMessage(executable.toString(), timeOutS);
response.message = proc.exitMessage();
return response;
}

View File

@@ -114,8 +114,7 @@ static bool
qPrintable(cmd.toUserOutput()));
process.run(cmd);
if (process.result() != Utils::QtcProcess::Finished) {
*errorMessage = QString::fromLatin1("Generator script failed: %1")
.arg(process.exitMessage(binary, 30));
*errorMessage = QString("Generator script failed: %1").arg(process.exitMessage());
const QString stdErr = process.stdErr();
if (!stdErr.isEmpty()) {
errorMessage->append(QLatin1Char('\n'));

View File

@@ -91,7 +91,7 @@ static QByteArray runGcc(const FilePath &gcc, const QStringList &arguments, cons
cpp.runBlocking(cmdLine);
if (cpp.result() != QtcProcess::Finished || cpp.exitCode() != 0) {
Core::MessageManager::writeFlashing({"Compiler feature detection failure!",
cpp.exitMessage(cmdLine.toUserOutput(), 10),
cpp.exitMessage(),
QString::fromUtf8(cpp.allRawOutput())});
return QByteArray();
}

View File

@@ -2024,9 +2024,7 @@ Utils::optional<QString> MsvcToolChain::generateEnvironmentSettings(const Utils:
run.runBlocking(cmd);
if (run.result() != QtcProcess::Finished) {
const QString message = !run.stdErr().isEmpty()
? run.stdErr()
: run.exitMessage(cmdPath.toString(), 10);
const QString message = !run.stdErr().isEmpty() ? run.stdErr() : run.exitMessage();
qWarning().noquote() << message;
QString command = QDir::toNativeSeparators(batchFile);
if (!batchArgs.isEmpty())

View File

@@ -1031,7 +1031,7 @@ SubversionResponse SubversionPluginPrivate::runSvn(const QString &workingDir,
response.error = proc.result() != QtcProcess::Finished;
if (response.error)
response.message = proc.exitMessage(m_settings.binaryPath.value(), timeOutS);
response.message = proc.exitMessage();
response.stdErr = proc.stdErr();
response.stdOut = proc.stdOut();
return response;

View File

@@ -93,7 +93,7 @@ static FormatTask format(FormatTask task)
process.runBlocking({executable, options});
if (process.result() != QtcProcess::Finished) {
task.error = QString(QT_TRANSLATE_NOOP("TextEditor", "Failed to format: %1."))
.arg(process.exitMessage(executable, 5));
.arg(process.exitMessage());
return task;
}
const QString output = process.stdErr();