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.setTimeoutS(5);
qmake.runBlocking({qmakePath, {"--version"}}); qmake.runBlocking({qmakePath, {"--version"}});
if (qmake.result() != QtcProcess::Finished) { if (qmake.result() != QtcProcess::Finished) {
qWarning() << qmake.exitMessage(qmakePath, 5); qWarning() << qmake.exitMessage();
return QString(); return QString();
} }

View File

@@ -608,20 +608,22 @@ void SynchronousProcessResponse::clear()
rawStdErr.clear(); rawStdErr.clear();
} }
QString QtcProcess::exitMessage(const QString &binary, int timeoutS) const QString QtcProcess::exitMessage()
{ {
const QString fullCmd = commandLine().toUserOutput();
switch (result()) { switch (result()) {
case Finished: 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: 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: 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: 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: case Hang:
return QtcProcess::tr("The command \"%1\" did not respond within the timeout limit (%2 s).") 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(); return QString();
} }

View File

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

View File

@@ -338,9 +338,9 @@ void ShellCommand::runCommand(SynchronousProcess &proc,
// Success/Fail message in appropriate window? // Success/Fail message in appropriate window?
if (proc.result() == QtcProcess::Finished) { if (proc.result() == QtcProcess::Finished) {
if (d->m_flags & ShowSuccessMessage) 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)) { } 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) { if (genKeyCertProc.result() != QtcProcess::Finished || genKeyCertProc.exitCode() != 0) {
QMessageBox::critical(this, tr("Error"), QMessageBox::critical(this, tr("Error"),
genKeyCertProc.exitMessage(command.executable().toString(), 15) genKeyCertProc.exitMessage() + '\n' + genKeyCertProc.allOutput());
+ '\n' + genKeyCertProc.allOutput());
return; return;
} }
accept(); accept();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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