2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "abstractprocessstep.h"
|
2013-02-06 16:28:38 +01:00
|
|
|
#include "ansifilterparser.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "buildstep.h"
|
|
|
|
|
#include "project.h"
|
2011-08-18 13:46:52 +02:00
|
|
|
#include "task.h"
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2016-12-05 21:14:40 +01:00
|
|
|
#include <coreplugin/reaper.h>
|
|
|
|
|
|
2009-12-09 13:54:46 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QDir>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
|
|
|
|
\class ProjectExplorer::AbstractProcessStep
|
|
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The AbstractProcessStep class is a convenience class that can be
|
|
|
|
|
used as a base class instead of BuildStep.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
|
|
|
|
It should be used as a base class if your buildstep just needs to run a process.
|
|
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
|
\list
|
2013-02-06 08:50:23 +01:00
|
|
|
\li Use processParameters() to configure the process you want to run
|
2011-04-14 12:58:14 +02:00
|
|
|
(you need to do that before calling AbstractProcessStep::init()).
|
2013-02-06 08:50:23 +01:00
|
|
|
\li Inside YourBuildStep::init() call AbstractProcessStep::init().
|
|
|
|
|
\li Inside YourBuildStep::run() call AbstractProcessStep::run(), which automatically starts the process
|
2011-04-14 12:58:14 +02:00
|
|
|
and by default adds the output on stdOut and stdErr to the OutputWindow.
|
2013-02-06 08:50:23 +01:00
|
|
|
\li If you need to process the process output override stdOut() and/or stdErr.
|
2011-04-14 12:58:14 +02:00
|
|
|
\endlist
|
|
|
|
|
|
|
|
|
|
The two functions processStarted() and processFinished() are called after starting/finishing the process.
|
|
|
|
|
By default they add a message to the output window.
|
|
|
|
|
|
|
|
|
|
Use setEnabled() to control whether the BuildStep needs to run. (A disabled BuildStep immediately returns true,
|
|
|
|
|
from the run function.)
|
|
|
|
|
|
|
|
|
|
\sa ProjectExplorer::ProcessParameters
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn void ProjectExplorer::AbstractProcessStep::setEnabled(bool b)
|
|
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
Enables or disables a BuildStep.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2013-10-07 13:34:40 +02:00
|
|
|
Disabled BuildSteps immediately return true from their run function.
|
2013-09-10 17:16:10 +02:00
|
|
|
Should be called from init().
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn ProcessParameters *ProjectExplorer::AbstractProcessStep::processParameters()
|
|
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
Obtains a reference to the parameters for the actual process to run.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
Should be used in init().
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
AbstractProcessStep::AbstractProcessStep(BuildStepList *bsl, Core::Id id) :
|
2016-04-13 15:52:14 +02:00
|
|
|
BuildStep(bsl, id)
|
2016-12-05 21:14:40 +01:00
|
|
|
{
|
|
|
|
|
m_timer.setInterval(500);
|
|
|
|
|
connect(&m_timer, &QTimer::timeout, this, &AbstractProcessStep::checkForCancel);
|
|
|
|
|
}
|
2009-10-27 14:16:28 +01:00
|
|
|
|
2010-07-16 14:00:41 +02:00
|
|
|
AbstractProcessStep::AbstractProcessStep(BuildStepList *bsl,
|
2010-01-14 17:41:29 +01:00
|
|
|
AbstractProcessStep *bs) :
|
2016-04-13 15:52:14 +02:00
|
|
|
BuildStep(bsl, bs), m_ignoreReturnValue(bs->m_ignoreReturnValue)
|
|
|
|
|
{ }
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Deletes all existing output parsers and starts a new chain with the
|
2011-04-14 12:58:14 +02:00
|
|
|
given parser.
|
|
|
|
|
|
|
|
|
|
Derived classes need to call this function.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-10-13 22:37:28 +03:00
|
|
|
void AbstractProcessStep::setOutputParser(IOutputParser *parser)
|
2009-12-09 13:54:46 +01:00
|
|
|
{
|
2016-12-05 21:14:40 +01:00
|
|
|
m_outputParserChain.reset(new AnsiFilterParser);
|
2013-02-06 16:28:38 +01:00
|
|
|
m_outputParserChain->appendOutputParser(parser);
|
2009-12-09 13:54:46 +01:00
|
|
|
|
2016-12-05 21:14:40 +01:00
|
|
|
connect(m_outputParserChain.get(), &IOutputParser::addOutput, this, &AbstractProcessStep::outputAdded);
|
|
|
|
|
connect(m_outputParserChain.get(), &IOutputParser::addTask, this, &AbstractProcessStep::taskAdded);
|
2009-12-09 13:54:46 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Appends the given output parser to the existing chain of parsers.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
2014-10-13 22:37:28 +03:00
|
|
|
void AbstractProcessStep::appendOutputParser(IOutputParser *parser)
|
2009-12-09 13:54:46 +01:00
|
|
|
{
|
|
|
|
|
if (!parser)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QTC_ASSERT(m_outputParserChain, return);
|
|
|
|
|
m_outputParserChain->appendOutputParser(parser);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-13 22:37:28 +03:00
|
|
|
IOutputParser *AbstractProcessStep::outputParser() const
|
2009-12-09 13:54:46 +01:00
|
|
|
{
|
2016-12-05 21:14:40 +01:00
|
|
|
return m_outputParserChain.get();
|
2009-12-09 13:54:46 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-20 14:32:40 +02:00
|
|
|
void AbstractProcessStep::emitFaultyConfigurationMessage()
|
|
|
|
|
{
|
|
|
|
|
emit addOutput(tr("Configuration is faulty. Check the Issues view for details."),
|
2017-01-12 10:59:12 +01:00
|
|
|
BuildStep::OutputFormat::NormalMessage);
|
2014-06-20 14:32:40 +02:00
|
|
|
}
|
|
|
|
|
|
2011-09-22 12:59:31 +02:00
|
|
|
bool AbstractProcessStep::ignoreReturnValue()
|
|
|
|
|
{
|
|
|
|
|
return m_ignoreReturnValue;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
If \a ignoreReturnValue is set to true, then the abstractprocess step will
|
2011-04-14 12:58:14 +02:00
|
|
|
return success even if the return value indicates otherwise.
|
|
|
|
|
|
|
|
|
|
Should be called from init.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-10-15 19:06:51 +02:00
|
|
|
void AbstractProcessStep::setIgnoreReturnValue(bool b)
|
2009-06-22 16:11:45 +02:00
|
|
|
{
|
2009-10-15 19:06:51 +02:00
|
|
|
m_ignoreReturnValue = b;
|
2009-06-22 16:11:45 +02:00
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Reimplemented from BuildStep::init(). You need to call this from
|
|
|
|
|
YourBuildStep::init().
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
2015-11-13 12:19:35 +01:00
|
|
|
bool AbstractProcessStep::init(QList<const BuildStep *> &earlierSteps)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2015-11-13 12:19:35 +01:00
|
|
|
Q_UNUSED(earlierSteps);
|
2008-12-02 12:01:29 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Reimplemented from BuildStep::init(). You need to call this from
|
|
|
|
|
YourBuildStep::run().
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
2009-12-09 13:54:46 +01:00
|
|
|
void AbstractProcessStep::run(QFutureInterface<bool> &fi)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-11-12 17:23:55 +01:00
|
|
|
QDir wd(m_param.effectiveWorkingDirectory());
|
2014-10-22 12:29:41 +02:00
|
|
|
if (!wd.exists()) {
|
|
|
|
|
if (!wd.mkpath(wd.absolutePath())) {
|
|
|
|
|
emit addOutput(tr("Could not create directory \"%1\"")
|
|
|
|
|
.arg(QDir::toNativeSeparators(wd.absolutePath())),
|
2017-01-12 10:59:12 +01:00
|
|
|
BuildStep::OutputFormat::ErrorMessage);
|
2016-04-20 12:49:25 +02:00
|
|
|
reportRunResult(fi, false);
|
2014-10-22 12:29:41 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-13 17:16:33 +01:00
|
|
|
QString effectiveCommand = m_param.effectiveCommand();
|
2014-10-24 10:28:28 +02:00
|
|
|
if (!QFileInfo::exists(effectiveCommand)) {
|
2014-01-13 17:16:33 +01:00
|
|
|
processStartupFailed();
|
2016-04-20 12:49:25 +02:00
|
|
|
reportRunResult(fi, false);
|
2014-01-13 17:16:33 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-08 15:06:35 +01:00
|
|
|
m_futureInterface = &fi;
|
2016-12-05 21:14:40 +01:00
|
|
|
|
|
|
|
|
m_process.reset(new Utils::QtcProcess());
|
|
|
|
|
m_process->setUseCtrlCStub(Utils::HostOsInfo::isWindowsHost());
|
2010-10-06 16:11:07 +02:00
|
|
|
m_process->setWorkingDirectory(wd.absolutePath());
|
2010-11-12 17:23:55 +01:00
|
|
|
m_process->setEnvironment(m_param.environment());
|
2016-12-05 21:14:40 +01:00
|
|
|
m_process->setCommand(effectiveCommand, m_param.effectiveArguments());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-12-05 21:14:40 +01:00
|
|
|
connect(m_process.get(), &QProcess::readyReadStandardOutput,
|
2016-01-29 16:38:37 +02:00
|
|
|
this, &AbstractProcessStep::processReadyReadStdOutput);
|
2016-12-05 21:14:40 +01:00
|
|
|
connect(m_process.get(), &QProcess::readyReadStandardError,
|
2016-01-29 16:38:37 +02:00
|
|
|
this, &AbstractProcessStep::processReadyReadStdError);
|
2016-12-05 21:14:40 +01:00
|
|
|
connect(m_process.get(), static_cast<void (QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished),
|
2016-01-29 16:38:37 +02:00
|
|
|
this, &AbstractProcessStep::slotProcessFinished);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-10-19 11:14:03 +02:00
|
|
|
m_process->start();
|
2008-12-09 11:07:24 +01:00
|
|
|
if (!m_process->waitForStarted()) {
|
2008-12-02 12:01:29 +01:00
|
|
|
processStartupFailed();
|
2016-12-05 21:14:40 +01:00
|
|
|
m_process.reset();
|
2016-04-20 12:49:25 +02:00
|
|
|
reportRunResult(fi, false);
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
processStarted();
|
2016-12-05 21:14:40 +01:00
|
|
|
m_timer.start();
|
2013-02-12 12:56:02 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2017-01-16 12:26:27 +01:00
|
|
|
void AbstractProcessStep::cleanUp(QProcess *process)
|
2013-02-12 12:56:02 +01:00
|
|
|
{
|
2008-12-02 12:01:29 +01:00
|
|
|
// The process has finished, leftover data is read in processFinished
|
2017-01-16 12:26:27 +01:00
|
|
|
processFinished(process->exitCode(), process->exitStatus());
|
2017-01-20 10:47:35 +01:00
|
|
|
const bool returnValue = processSucceeded(process->exitCode(), process->exitStatus()) || m_ignoreReturnValue;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-12-05 21:14:40 +01:00
|
|
|
m_outputParserChain.reset();
|
|
|
|
|
m_process.reset();
|
2013-02-12 12:56:02 +01:00
|
|
|
|
2016-04-20 12:49:25 +02:00
|
|
|
// Report result
|
2016-12-08 15:06:35 +01:00
|
|
|
reportRunResult(*m_futureInterface, returnValue);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Called after the process is started.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
The default implementation adds a process-started message to the output
|
|
|
|
|
message.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void AbstractProcessStep::processStarted()
|
|
|
|
|
{
|
2011-03-31 18:22:22 +02:00
|
|
|
emit addOutput(tr("Starting: \"%1\" %2")
|
2010-11-12 17:23:55 +01:00
|
|
|
.arg(QDir::toNativeSeparators(m_param.effectiveCommand()),
|
|
|
|
|
m_param.prettyArguments()),
|
2017-01-12 10:59:12 +01:00
|
|
|
BuildStep::OutputFormat::NormalMessage);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Called after the process is finished.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
The default implementation adds a line to the output window.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
2010-04-09 13:10:59 +02:00
|
|
|
void AbstractProcessStep::processFinished(int exitCode, QProcess::ExitStatus status)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-05-03 16:08:00 +02:00
|
|
|
if (m_outputParserChain)
|
|
|
|
|
m_outputParserChain->flush();
|
|
|
|
|
|
2010-11-12 17:23:55 +01:00
|
|
|
QString command = QDir::toNativeSeparators(m_param.effectiveCommand());
|
2010-06-08 15:04:42 +02:00
|
|
|
if (status == QProcess::NormalExit && exitCode == 0) {
|
2010-11-09 11:55:04 +01:00
|
|
|
emit addOutput(tr("The process \"%1\" exited normally.").arg(command),
|
2017-01-12 10:59:12 +01:00
|
|
|
BuildStep::OutputFormat::NormalMessage);
|
2010-06-08 15:04:42 +02:00
|
|
|
} else if (status == QProcess::NormalExit) {
|
2010-07-15 10:29:38 +02:00
|
|
|
emit addOutput(tr("The process \"%1\" exited with code %2.")
|
2017-02-10 10:47:44 +01:00
|
|
|
.arg(command, QString::number(exitCode)),
|
2017-01-12 10:59:12 +01:00
|
|
|
BuildStep::OutputFormat::ErrorMessage);
|
2010-06-08 15:04:42 +02:00
|
|
|
} else {
|
2017-01-12 10:59:12 +01:00
|
|
|
emit addOutput(tr("The process \"%1\" crashed.").arg(command), BuildStep::OutputFormat::ErrorMessage);
|
2010-06-08 15:04:42 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Called if the process could not be started.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
By default, adds a message to the output window.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void AbstractProcessStep::processStartupFailed()
|
|
|
|
|
{
|
2010-10-19 11:14:03 +02:00
|
|
|
emit addOutput(tr("Could not start process \"%1\" %2")
|
2010-11-12 17:23:55 +01:00
|
|
|
.arg(QDir::toNativeSeparators(m_param.effectiveCommand()),
|
|
|
|
|
m_param.prettyArguments()),
|
2017-01-12 10:59:12 +01:00
|
|
|
BuildStep::OutputFormat::ErrorMessage);
|
2016-12-05 21:14:40 +01:00
|
|
|
m_timer.stop();
|
2010-04-09 13:10:59 +02:00
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Called to test whether a process succeeded or not.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
2010-04-09 13:10:59 +02:00
|
|
|
bool AbstractProcessStep::processSucceeded(int exitCode, QProcess::ExitStatus status)
|
|
|
|
|
{
|
2013-08-21 11:40:00 +02:00
|
|
|
if (outputParser() && outputParser()->hasFatalErrors())
|
|
|
|
|
return false;
|
|
|
|
|
|
2010-04-09 13:10:59 +02:00
|
|
|
return exitCode == 0 && status == QProcess::NormalExit;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractProcessStep::processReadyReadStdOutput()
|
|
|
|
|
{
|
2017-01-16 12:26:27 +01:00
|
|
|
if (!m_process)
|
|
|
|
|
return;
|
2008-12-02 12:01:29 +01:00
|
|
|
m_process->setReadChannel(QProcess::StandardOutput);
|
2008-12-09 11:07:24 +01:00
|
|
|
while (m_process->canReadLine()) {
|
2010-03-23 15:22:05 +01:00
|
|
|
QString line = QString::fromLocal8Bit(m_process->readLine());
|
2009-12-09 13:54:46 +01:00
|
|
|
stdOutput(line);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Called for each line of output on stdOut().
|
2011-04-14 12:58:14 +02:00
|
|
|
|
|
|
|
|
The default implementation adds the line to the application output window.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-12-09 13:54:46 +01:00
|
|
|
void AbstractProcessStep::stdOutput(const QString &line)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-12-09 13:54:46 +01:00
|
|
|
if (m_outputParserChain)
|
|
|
|
|
m_outputParserChain->stdOutput(line);
|
2017-01-12 10:59:12 +01:00
|
|
|
emit addOutput(line, BuildStep::OutputFormat::Stdout, BuildStep::DontAppendNewline);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractProcessStep::processReadyReadStdError()
|
|
|
|
|
{
|
2017-01-16 12:26:27 +01:00
|
|
|
if (!m_process)
|
|
|
|
|
return;
|
2008-12-02 12:01:29 +01:00
|
|
|
m_process->setReadChannel(QProcess::StandardError);
|
2008-12-09 11:07:24 +01:00
|
|
|
while (m_process->canReadLine()) {
|
2010-03-23 15:22:05 +01:00
|
|
|
QString line = QString::fromLocal8Bit(m_process->readLine());
|
2008-12-02 12:01:29 +01:00
|
|
|
stdError(line);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Called for each line of output on StdErrror().
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
The default implementation adds the line to the application output window.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void AbstractProcessStep::stdError(const QString &line)
|
|
|
|
|
{
|
2009-12-09 13:54:46 +01:00
|
|
|
if (m_outputParserChain)
|
|
|
|
|
m_outputParserChain->stdError(line);
|
2017-01-12 10:59:12 +01:00
|
|
|
emit addOutput(line, BuildStep::OutputFormat::Stderr, BuildStep::DontAppendNewline);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-02-15 16:18:49 +01:00
|
|
|
QFutureInterface<bool> *AbstractProcessStep::futureInterface() const
|
|
|
|
|
{
|
2016-12-08 15:06:35 +01:00
|
|
|
return m_futureInterface;
|
2013-02-15 16:18:49 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void AbstractProcessStep::checkForCancel()
|
|
|
|
|
{
|
2016-12-05 21:14:40 +01:00
|
|
|
if (m_futureInterface->isCanceled() && m_timer.isActive()) {
|
|
|
|
|
m_timer.stop();
|
2017-01-16 12:26:27 +01:00
|
|
|
|
2016-12-05 21:14:40 +01:00
|
|
|
Core::Reaper::reap(m_process.release());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-20 17:13:45 +02:00
|
|
|
void AbstractProcessStep::taskAdded(const Task &task, int linkedOutputLines, int skipLines)
|
2009-12-09 13:54:46 +01:00
|
|
|
{
|
2010-04-09 13:10:59 +02:00
|
|
|
// Do not bother to report issues if we do not care about the results of
|
|
|
|
|
// the buildstep anyway:
|
|
|
|
|
if (m_ignoreReturnValue)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-05-03 16:08:00 +02:00
|
|
|
// flush out any pending tasks before proceeding:
|
|
|
|
|
if (!m_skipFlush && m_outputParserChain) {
|
|
|
|
|
m_skipFlush = true;
|
|
|
|
|
m_outputParserChain->flush();
|
|
|
|
|
m_skipFlush = false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-12 13:53:00 +01:00
|
|
|
Task editable(task);
|
2012-01-26 13:38:25 +01:00
|
|
|
QString filePath = task.file.toString();
|
2009-12-09 13:54:46 +01:00
|
|
|
if (!filePath.isEmpty() && !QDir::isAbsolutePath(filePath)) {
|
|
|
|
|
// We have no save way to decide which file in which subfolder
|
|
|
|
|
// is meant. Therefore we apply following heuristics:
|
|
|
|
|
// 1. Check if file is unique in whole project
|
|
|
|
|
// 2. Otherwise try again without any ../
|
|
|
|
|
// 3. give up.
|
|
|
|
|
|
|
|
|
|
QList<QFileInfo> possibleFiles;
|
2015-01-10 23:40:32 +02:00
|
|
|
QString fileName = Utils::FileName::fromString(filePath).fileName();
|
2014-10-13 22:37:28 +03:00
|
|
|
foreach (const QString &file, project()->files(Project::AllFiles)) {
|
2009-12-09 13:54:46 +01:00
|
|
|
QFileInfo candidate(file);
|
|
|
|
|
if (candidate.fileName() == fileName)
|
|
|
|
|
possibleFiles << candidate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (possibleFiles.count() == 1) {
|
2012-01-26 13:38:25 +01:00
|
|
|
editable.file = Utils::FileName(possibleFiles.first());
|
2009-12-09 13:54:46 +01:00
|
|
|
} else {
|
|
|
|
|
// More then one filename, so do a better compare
|
|
|
|
|
// Chop of any "../"
|
2010-02-01 12:43:56 +01:00
|
|
|
while (filePath.startsWith(QLatin1String("../")))
|
|
|
|
|
filePath.remove(0, 3);
|
2009-12-09 13:54:46 +01:00
|
|
|
int count = 0;
|
|
|
|
|
QString possibleFilePath;
|
2012-11-28 20:44:03 +02:00
|
|
|
foreach (const QFileInfo &fi, possibleFiles) {
|
2009-12-09 13:54:46 +01:00
|
|
|
if (fi.filePath().endsWith(filePath)) {
|
|
|
|
|
possibleFilePath = fi.filePath();
|
|
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (count == 1)
|
2012-01-26 13:38:25 +01:00
|
|
|
editable.file = Utils::FileName::fromString(possibleFilePath);
|
2009-12-09 13:54:46 +01:00
|
|
|
else
|
|
|
|
|
qWarning() << "Could not find absolute location of file " << filePath;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-04-20 17:13:45 +02:00
|
|
|
emit addTask(editable, linkedOutputLines, skipLines);
|
2009-12-09 13:54:46 +01:00
|
|
|
}
|
|
|
|
|
|
2014-10-13 22:37:28 +03:00
|
|
|
void AbstractProcessStep::outputAdded(const QString &string, BuildStep::OutputFormat format)
|
2009-12-09 13:54:46 +01:00
|
|
|
{
|
2011-03-31 18:22:22 +02:00
|
|
|
emit addOutput(string, format, BuildStep::DontAppendNewline);
|
2009-12-09 13:54:46 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void AbstractProcessStep::slotProcessFinished(int, QProcess::ExitStatus)
|
|
|
|
|
{
|
2016-12-05 21:14:40 +01:00
|
|
|
m_timer.stop();
|
2013-02-12 12:56:02 +01:00
|
|
|
|
2017-01-16 12:26:27 +01:00
|
|
|
QProcess *process = m_process.get();
|
|
|
|
|
if (!process) // Happens when the process was canceled and handed over to the Reaper.
|
|
|
|
|
process = qobject_cast<QProcess *>(sender()); // The process was canceled!
|
|
|
|
|
|
|
|
|
|
const QString stdErrLine = process ? QString::fromLocal8Bit(process->readAllStandardError()) : QString();
|
|
|
|
|
for (const QString &l : stdErrLine.split('\n'))
|
|
|
|
|
stdError(l);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2017-01-16 12:26:27 +01:00
|
|
|
const QString stdOutLine = process ? QString::fromLocal8Bit(process->readAllStandardOutput()) : QString();
|
|
|
|
|
for (const QString &l : stdOutLine.split('\n'))
|
|
|
|
|
stdError(l);
|
2008-12-09 11:07:24 +01:00
|
|
|
|
2017-01-16 12:26:27 +01:00
|
|
|
cleanUp(process);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|