diff options
| author | Tobias Hunger <tobias.hunger@digia.com> | 2012-12-15 12:59:05 +0100 |
|---|---|---|
| committer | Christian Kandeler <christian.kandeler@digia.com> | 2013-01-11 11:49:26 +0100 |
| commit | 7db3e4c0e950fa7a3bd08b65719c36f0ca63e5d6 (patch) | |
| tree | 0db575fc623f97058a15e1493407af22d0b799a7 /src/lib/buildgraph/processcommandexecutor.cpp | |
| parent | 340f18159840c156be542efdc87a56c122d378f1 (diff) | |
| download | qbs-7db3e4c0e950fa7a3bd08b65719c36f0ca63e5d6.tar.gz | |
Do not write directly into logger
Pass information up to the client instead so that it can
decide how to handle it.
This allows e.g. creator to parse compile output for build
issues.
Change-Id: I76be4eaeb289b211b7d2527b555536b556655492
Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
Diffstat (limited to 'src/lib/buildgraph/processcommandexecutor.cpp')
| -rw-r--r-- | src/lib/buildgraph/processcommandexecutor.cpp | 78 |
1 files changed, 48 insertions, 30 deletions
diff --git a/src/lib/buildgraph/processcommandexecutor.cpp b/src/lib/buildgraph/processcommandexecutor.cpp index c0ae199f6..05ee07b0f 100644 --- a/src/lib/buildgraph/processcommandexecutor.cpp +++ b/src/lib/buildgraph/processcommandexecutor.cpp @@ -36,8 +36,11 @@ #include <language/language.h> #include <logging/logger.h> +#include <logging/translator.h> +#include <tools/error.h> #include <tools/fileinfo.h> #include <tools/hostosinfo.h> +#include <tools/processresult.h> #include <QDir> #include <QScriptEngine> @@ -129,8 +132,8 @@ void ProcessCommandExecutor::doStart() responseFile.setAutoRemove(false); responseFile.setFileTemplate(QDir::tempPath() + "/qbsresp"); if (!responseFile.open()) { - QString errorMessage = "Cannot create response file."; - emit error(errorMessage); + emit error(Error(Tr::tr("Cannot create response file '%1'.") + .arg(responseFile.fileName()))); return; } for (int i = 0; i < cmd->arguments().count(); ++i) { @@ -169,8 +172,8 @@ QString ProcessCommandExecutor::filterProcessOutput(const QByteArray &_output, QScriptValue filterFunction = scriptEngine()->evaluate("var f = " + filterFunctionSource + "; f"); if (!filterFunction.isFunction()) { - emit error(QString("Error in filter function: %1.\n%2") - .arg(filterFunctionSource, filterFunction.toString())); + emit error(Error(Tr::tr("Error in filter function: %1.\n%2") + .arg(filterFunctionSource, filterFunction.toString()))); return output; } @@ -178,71 +181,86 @@ QString ProcessCommandExecutor::filterProcessOutput(const QByteArray &_output, outputArg.setProperty(0, scriptEngine()->toScriptValue(output)); QScriptValue filteredOutput = filterFunction.call(scriptEngine()->undefinedValue(), outputArg); if (filteredOutput.isError()) { - emit error(QString("Error when calling ouput filter function: %1") - .arg(filteredOutput.toString())); + emit error(Error(Tr::tr("Error when calling output filter function: %1") + .arg(filteredOutput.toString()))); return output; } return filteredOutput.toString(); } -void ProcessCommandExecutor::sendProcessOutput(bool dueToError) +void ProcessCommandExecutor::sendProcessOutput(bool success) { - const QString processStdOut = filterProcessOutput(m_process.readAllStandardOutput(), - processCommand()->stdoutFilterFunction()); - const QString processStdErr = filterProcessOutput(m_process.readAllStandardError(), - processCommand()->stderrFilterFunction()); - const bool processOutputEmpty = processStdOut.isEmpty() && processStdErr.isEmpty(); - if (processOutputEmpty && !dueToError) - return; - (dueToError ? qbsError() : qbsInfo()) - << DontPrintLogLevel - << m_program << commandArgsToString(m_arguments) - << (processOutputEmpty ? QString() : QString::fromLatin1("\n")) - << processStdOut << processStdErr; + ProcessResult result; + result.binary = m_program; + result.arguments = m_arguments; + result.workingDirectory = m_process.workingDirectory(); + if (result.workingDirectory.isEmpty()) + result.workingDirectory = QDir::currentPath(); + result.exitCode = m_process.exitCode(); + result.exitStatus = m_process.exitStatus(); + result.success = success; + + QString tmp = filterProcessOutput(m_process.readAllStandardOutput(), + processCommand()->stdoutFilterFunction()); + if (!tmp.isEmpty()) { + if (tmp.endsWith(QLatin1Char('\n'))) + tmp.chop(1); + result.stdOut = tmp.split(QLatin1Char('\n')); + } + tmp = filterProcessOutput(m_process.readAllStandardError(), + processCommand()->stderrFilterFunction()); + if (!tmp.isEmpty()) { + if (tmp.endsWith(QLatin1Char('\n'))) + tmp.chop(1); + result.stdErr = tmp.split(QLatin1Char('\n')); + } + + emit reportProcessResult(result); } void ProcessCommandExecutor::onProcessError() { + sendProcessOutput(false); removeResponseFile(); - sendProcessOutput(true); QString errorMessage; const QString binary = QDir::toNativeSeparators(processCommand()->program()); switch (m_process.error()) { case QProcess::FailedToStart: - errorMessage = QString::fromLatin1("The process '%1' could not be started: %2"). + errorMessage = Tr::tr("The process '%1' could not be started: %2"). arg(binary, m_process.errorString()); break; case QProcess::Crashed: - errorMessage = QString::fromLatin1("The process '%1' crashed.").arg(binary); + errorMessage = Tr::tr("The process '%1' crashed.").arg(binary); break; case QProcess::Timedout: - errorMessage = QString::fromLatin1("The process '%1' timed out.").arg(binary); + errorMessage = Tr::tr("The process '%1' timed out.").arg(binary); break; case QProcess::ReadError: - errorMessage = QString::fromLatin1("Error reading process output from '%1'.").arg(binary); + errorMessage = Tr::tr("Error reading process output from '%1'.").arg(binary); break; case QProcess::WriteError: - errorMessage = QString::fromLatin1("Error writing to process '%1'.").arg(binary); + errorMessage = Tr::tr("Error writing to process '%1'.").arg(binary); break; default: - errorMessage = QString::fromLatin1("Unknown process error running '%1'.").arg(binary); + errorMessage = Tr::tr("Unknown process error running '%1'.").arg(binary); break; } - emit error(errorMessage); + emit error(Error(errorMessage)); } void ProcessCommandExecutor::onProcessFinished(int exitCode) { removeResponseFile(); const bool errorOccurred = exitCode > processCommand()->maxExitCode(); - sendProcessOutput(errorOccurred); + sendProcessOutput(!errorOccurred); + if (errorOccurred) { - QString msg = "Process failed with exit code %1."; - emit error(msg.arg(exitCode)); + emit error(Error(Tr::tr("Process failed with exit code %1.").arg(exitCode))); return; } + emit finished(); } |
