2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "abstractprocessstep.h"
|
2018-04-27 12:34:13 +02:00
|
|
|
#include "buildconfiguration.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "buildstep.h"
|
2018-11-17 21:19:04 +02:00
|
|
|
#include "processparameters.h"
|
2019-10-07 14:29:03 +03:00
|
|
|
#include "projectexplorer.h"
|
|
|
|
|
#include "projectexplorersettings.h"
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2018-11-17 21:19:04 +02:00
|
|
|
#include <utils/fileutils.h>
|
2020-04-16 13:53:05 +02:00
|
|
|
#include <utils/outputformatter.h>
|
2009-12-09 13:54:46 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2018-11-17 21:19:04 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2009-12-09 13:54:46 +01:00
|
|
|
|
2020-03-31 14:34:08 +02:00
|
|
|
#include <QTextDecoder>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2018-03-28 12:37:19 +02:00
|
|
|
#include <algorithm>
|
2018-11-17 21:19:04 +02:00
|
|
|
#include <memory>
|
2018-03-28 12:37:19 +02:00
|
|
|
|
2019-05-28 18:59:45 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2018-11-17 21:19:04 +02:00
|
|
|
namespace ProjectExplorer {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
|
2018-11-17 21:19:04 +02:00
|
|
|
class AbstractProcessStep::Private
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-11-17 22:46:45 +02:00
|
|
|
Private(AbstractProcessStep *q) : q(q) {}
|
|
|
|
|
|
2021-09-20 14:35:37 +02:00
|
|
|
void cleanUp(int exitCode, QProcess::ExitStatus status);
|
2020-07-28 07:52:22 +02:00
|
|
|
|
2018-11-17 22:46:45 +02:00
|
|
|
AbstractProcessStep *q;
|
2021-04-23 04:25:27 +02:00
|
|
|
std::unique_ptr<QtcProcess> m_process;
|
2018-11-17 21:19:04 +02:00
|
|
|
ProcessParameters m_param;
|
2022-12-02 13:59:33 +01:00
|
|
|
ProcessParameters *m_displayedParams = &m_param;
|
2020-08-13 12:20:41 +02:00
|
|
|
std::function<CommandLine()> m_commandLineProvider;
|
|
|
|
|
std::function<FilePath()> m_workingDirectoryProvider;
|
|
|
|
|
std::function<void(Environment &)> m_environmentModifier;
|
2018-11-17 21:19:04 +02:00
|
|
|
bool m_ignoreReturnValue = false;
|
2019-09-10 23:39:29 +03:00
|
|
|
bool m_lowPriority = false;
|
2020-03-31 14:34:08 +02:00
|
|
|
std::unique_ptr<QTextDecoder> stdoutStream;
|
|
|
|
|
std::unique_ptr<QTextDecoder> stderrStream;
|
2020-04-16 13:53:05 +02:00
|
|
|
OutputFormatter *outputFormatter = nullptr;
|
2018-11-17 21:19:04 +02:00
|
|
|
};
|
|
|
|
|
|
2021-04-23 04:25:27 +02:00
|
|
|
AbstractProcessStep::AbstractProcessStep(BuildStepList *bsl, Id id) :
|
2018-11-17 21:19:04 +02:00
|
|
|
BuildStep(bsl, id),
|
2018-11-17 22:46:45 +02:00
|
|
|
d(new Private(this))
|
2016-12-05 21:14:40 +01:00
|
|
|
{
|
|
|
|
|
}
|
2009-10-27 14:16:28 +01:00
|
|
|
|
2018-11-17 21:19:04 +02:00
|
|
|
AbstractProcessStep::~AbstractProcessStep()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-20 14:32:40 +02:00
|
|
|
void AbstractProcessStep::emitFaultyConfigurationMessage()
|
|
|
|
|
{
|
|
|
|
|
emit addOutput(tr("Configuration is faulty. Check the Issues view for details."),
|
2022-12-02 13:59:33 +01:00
|
|
|
OutputFormat::NormalMessage);
|
2014-06-20 14:32:40 +02:00
|
|
|
}
|
|
|
|
|
|
2020-07-28 07:52:22 +02:00
|
|
|
bool AbstractProcessStep::ignoreReturnValue() const
|
2011-09-22 12:59:31 +02:00
|
|
|
{
|
2018-11-17 21:19:04 +02:00
|
|
|
return d->m_ignoreReturnValue;
|
2011-09-22 12:59:31 +02:00
|
|
|
}
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-10-15 19:06:51 +02:00
|
|
|
void AbstractProcessStep::setIgnoreReturnValue(bool b)
|
2009-06-22 16:11:45 +02:00
|
|
|
{
|
2018-11-17 21:19:04 +02:00
|
|
|
d->m_ignoreReturnValue = b;
|
2009-06-22 16:11:45 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 12:20:41 +02:00
|
|
|
void AbstractProcessStep::setEnvironmentModifier(const std::function<void (Environment &)> &modifier)
|
|
|
|
|
{
|
|
|
|
|
d->m_environmentModifier = modifier;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractProcessStep::setUseEnglishOutput()
|
|
|
|
|
{
|
2021-05-20 11:57:21 +02:00
|
|
|
d->m_environmentModifier = [](Environment &env) { env.setupEnglishOutput(); };
|
2020-08-13 12:20:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractProcessStep::setCommandLineProvider(const std::function<CommandLine()> &provider)
|
|
|
|
|
{
|
|
|
|
|
d->m_commandLineProvider = provider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractProcessStep::setWorkingDirectoryProvider(const std::function<FilePath()> &provider)
|
|
|
|
|
{
|
|
|
|
|
d->m_workingDirectoryProvider = provider;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
|
2019-01-10 15:31:44 +01:00
|
|
|
bool AbstractProcessStep::init()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2020-09-14 17:17:55 +02:00
|
|
|
if (d->m_process)
|
|
|
|
|
return false;
|
|
|
|
|
|
2022-10-18 14:17:35 +02:00
|
|
|
if (!setupProcessParameters(processParameters()))
|
|
|
|
|
return false;
|
2020-09-14 17:17:55 +02:00
|
|
|
|
|
|
|
|
return true;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2020-04-16 13:53:05 +02:00
|
|
|
void AbstractProcessStep::setupOutputFormatter(OutputFormatter *formatter)
|
|
|
|
|
{
|
|
|
|
|
formatter->setDemoteErrorsToWarnings(d->m_ignoreReturnValue);
|
|
|
|
|
d->outputFormatter = formatter;
|
|
|
|
|
BuildStep::setupOutputFormatter(formatter);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
void AbstractProcessStep::doRun()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2021-04-29 09:20:07 +02:00
|
|
|
const FilePath wd = d->m_param.effectiveWorkingDirectory();
|
2014-10-22 12:29:41 +02:00
|
|
|
if (!wd.exists()) {
|
2021-04-29 09:20:07 +02:00
|
|
|
if (!wd.createDir()) {
|
|
|
|
|
emit addOutput(tr("Could not create directory \"%1\"").arg(wd.toUserOutput()),
|
2022-12-02 13:59:33 +01:00
|
|
|
OutputFormat::ErrorMessage);
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
finish(false);
|
2014-10-22 12:29:41 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-05 15:35:15 +02:00
|
|
|
const CommandLine effectiveCommand(d->m_param.effectiveCommand(),
|
|
|
|
|
d->m_param.effectiveArguments(),
|
|
|
|
|
CommandLine::Raw);
|
2021-04-29 09:20:07 +02:00
|
|
|
if (!effectiveCommand.executable().isExecutableFile()) {
|
2014-01-13 17:16:33 +01:00
|
|
|
processStartupFailed();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-31 14:34:08 +02:00
|
|
|
d->stdoutStream = std::make_unique<QTextDecoder>(buildEnvironment().hasKey("VSLANG")
|
|
|
|
|
? QTextCodec::codecForName("UTF-8") : QTextCodec::codecForLocale());
|
|
|
|
|
d->stderrStream = std::make_unique<QTextDecoder>(QTextCodec::codecForLocale());
|
|
|
|
|
|
2022-03-22 16:51:38 +01:00
|
|
|
d->m_process.reset(new QtcProcess);
|
2021-04-23 04:25:27 +02:00
|
|
|
d->m_process->setUseCtrlCStub(HostOsInfo::isWindowsHost());
|
2021-06-03 10:39:15 +02:00
|
|
|
d->m_process->setWorkingDirectory(wd);
|
2020-04-21 11:36:24 +02:00
|
|
|
// Enforce PWD in the environment because some build tools use that.
|
|
|
|
|
// PWD can be different from getcwd in case of symbolic links (getcwd resolves symlinks).
|
|
|
|
|
// For example Clang uses PWD for paths in debug info, see QTCREATORBUG-23788
|
|
|
|
|
Environment envWithPwd = d->m_param.environment();
|
2021-06-03 10:39:15 +02:00
|
|
|
envWithPwd.set("PWD", d->m_process->workingDirectory().path());
|
2020-04-21 11:36:24 +02:00
|
|
|
d->m_process->setEnvironment(envWithPwd);
|
2019-05-28 18:59:45 +02:00
|
|
|
d->m_process->setCommand(effectiveCommand);
|
2019-10-09 21:29:12 +03:00
|
|
|
if (d->m_lowPriority && ProjectExplorerPlugin::projectExplorerSettings().lowBuildPriority)
|
2019-09-10 23:39:29 +03:00
|
|
|
d->m_process->setLowPriority();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2022-12-02 12:40:12 +01:00
|
|
|
connect(d->m_process.get(), &QtcProcess::readyReadStandardOutput, this, [this] {
|
|
|
|
|
stdOutput(d->stdoutStream->toUnicode(d->m_process->readAllStandardOutput()));
|
|
|
|
|
});
|
|
|
|
|
connect(d->m_process.get(), &QtcProcess::readyReadStandardError, this, [this] {
|
|
|
|
|
stdError(d->stderrStream->toUnicode(d->m_process->readAllStandardError()));
|
|
|
|
|
});
|
2022-12-02 13:59:33 +01:00
|
|
|
connect(d->m_process.get(), &QtcProcess::started, this, [this] {
|
|
|
|
|
ProcessParameters *params = displayedParameters();
|
|
|
|
|
emit addOutput(tr("Starting: \"%1\" %2")
|
|
|
|
|
.arg(params->effectiveCommand().toUserOutput(), params->prettyArguments()),
|
|
|
|
|
OutputFormat::NormalMessage);
|
|
|
|
|
});
|
2022-04-06 12:54:14 +02:00
|
|
|
connect(d->m_process.get(), &QtcProcess::done,
|
2022-06-29 17:16:19 +02:00
|
|
|
this, &AbstractProcessStep::handleProcessDone);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2018-11-17 21:19:04 +02:00
|
|
|
d->m_process->start();
|
2019-01-28 09:59:24 +01:00
|
|
|
}
|
|
|
|
|
|
2019-10-09 21:29:12 +03:00
|
|
|
void AbstractProcessStep::setLowPriority()
|
2019-09-10 23:39:29 +03:00
|
|
|
{
|
2019-10-09 21:29:12 +03:00
|
|
|
d->m_lowPriority = true;
|
2019-09-10 23:39:29 +03:00
|
|
|
}
|
|
|
|
|
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
void AbstractProcessStep::doCancel()
|
2019-01-28 09:59:24 +01:00
|
|
|
{
|
2021-09-20 14:35:37 +02:00
|
|
|
d->cleanUp(-1, QProcess::CrashExit);
|
2018-11-17 21:19:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProcessParameters *AbstractProcessStep::processParameters()
|
|
|
|
|
{
|
|
|
|
|
return &d->m_param;
|
2013-02-12 12:56:02 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2022-10-18 14:17:35 +02:00
|
|
|
bool AbstractProcessStep::setupProcessParameters(ProcessParameters *params) const
|
2020-08-13 12:20:41 +02:00
|
|
|
{
|
|
|
|
|
params->setMacroExpander(macroExpander());
|
|
|
|
|
|
2021-04-23 04:25:27 +02:00
|
|
|
Environment env = buildEnvironment();
|
2020-08-13 12:20:41 +02:00
|
|
|
if (d->m_environmentModifier)
|
|
|
|
|
d->m_environmentModifier(env);
|
|
|
|
|
params->setEnvironment(env);
|
|
|
|
|
|
2022-10-18 14:17:35 +02:00
|
|
|
if (d->m_commandLineProvider)
|
|
|
|
|
params->setCommandLine(d->m_commandLineProvider());
|
|
|
|
|
|
|
|
|
|
FilePath workingDirectory;
|
2020-08-13 12:20:41 +02:00
|
|
|
if (d->m_workingDirectoryProvider)
|
2022-10-18 14:17:35 +02:00
|
|
|
workingDirectory = d->m_workingDirectoryProvider();
|
2020-08-13 12:20:41 +02:00
|
|
|
else
|
2022-10-18 14:17:35 +02:00
|
|
|
workingDirectory = buildDirectory();
|
2020-08-13 12:20:41 +02:00
|
|
|
|
2022-10-18 14:17:35 +02:00
|
|
|
const FilePath executable = params->effectiveCommand();
|
|
|
|
|
|
|
|
|
|
QTC_ASSERT(executable.ensureReachable(workingDirectory), return false);
|
|
|
|
|
params->setWorkingDirectory(workingDirectory.onDevice(executable));
|
|
|
|
|
|
|
|
|
|
return true;
|
2020-08-13 12:20:41 +02:00
|
|
|
}
|
|
|
|
|
|
2022-12-02 13:59:33 +01:00
|
|
|
ProcessParameters *AbstractProcessStep::displayedParameters() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_displayedParams;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractProcessStep::setDisplayedParameters(ProcessParameters *params)
|
|
|
|
|
{
|
|
|
|
|
d->m_displayedParams = params;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-20 14:35:37 +02:00
|
|
|
void AbstractProcessStep::Private::cleanUp(int exitCode, QProcess::ExitStatus status)
|
2013-02-12 12:56:02 +01:00
|
|
|
{
|
2022-12-02 13:59:33 +01:00
|
|
|
const QString command = q->displayedParameters()->effectiveCommand().toUserOutput();
|
2022-12-02 11:33:28 +01:00
|
|
|
if (status == QProcess::NormalExit && exitCode == 0) {
|
|
|
|
|
emit q->addOutput(tr("The process \"%1\" exited normally.").arg(command),
|
2022-12-02 13:59:33 +01:00
|
|
|
OutputFormat::NormalMessage);
|
2022-12-02 11:33:28 +01:00
|
|
|
} else if (status == QProcess::NormalExit) {
|
|
|
|
|
emit q->addOutput(tr("The process \"%1\" exited with code %2.")
|
|
|
|
|
.arg(command, QString::number(exitCode)),
|
2022-12-02 13:59:33 +01:00
|
|
|
OutputFormat::ErrorMessage);
|
2022-12-02 11:33:28 +01:00
|
|
|
} else {
|
|
|
|
|
emit q->addOutput(tr("The process \"%1\" crashed.").arg(command),
|
2022-12-02 13:59:33 +01:00
|
|
|
OutputFormat::ErrorMessage);
|
2022-12-02 11:33:28 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2022-12-02 11:33:28 +01:00
|
|
|
const bool success = exitCode == 0 && status == QProcess::NormalExit
|
|
|
|
|
&& !outputFormatter->hasFatalErrors();
|
|
|
|
|
q->processFinished(success);
|
2022-04-04 14:31:21 +02:00
|
|
|
if (m_process)
|
|
|
|
|
m_process.release()->deleteLater();
|
2022-12-02 11:33:28 +01:00
|
|
|
q->finish(success || 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
|
|
|
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
|
|
|
*/
|
|
|
|
|
|
2022-12-02 11:33:28 +01:00
|
|
|
void AbstractProcessStep::processFinished(bool success)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2022-12-02 11:33:28 +01:00
|
|
|
Q_UNUSED(success)
|
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()
|
|
|
|
|
{
|
2022-12-02 13:59:33 +01:00
|
|
|
ProcessParameters *params = displayedParameters();
|
2021-06-07 12:33:45 +02:00
|
|
|
emit addOutput(tr("Could not start process \"%1\" %2.")
|
2022-12-02 13:59:33 +01:00
|
|
|
.arg(params->effectiveCommand().toUserOutput(), params->prettyArguments()),
|
2021-06-07 12:33:45 +02:00
|
|
|
OutputFormat::ErrorMessage);
|
|
|
|
|
|
|
|
|
|
QString err = d->m_process ? d->m_process->errorString() : QString();
|
|
|
|
|
if (!err.isEmpty())
|
|
|
|
|
emit addOutput(err, OutputFormat::ErrorMessage);
|
2022-04-06 12:54:14 +02:00
|
|
|
finish(false);
|
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 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-03-31 14:34:08 +02:00
|
|
|
void AbstractProcessStep::stdOutput(const QString &output)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2022-12-02 13:59:33 +01:00
|
|
|
emit addOutput(output, OutputFormat::Stdout, DontAppendNewline);
|
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 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
|
|
|
*/
|
|
|
|
|
|
2020-03-31 14:34:08 +02:00
|
|
|
void AbstractProcessStep::stdError(const QString &output)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2022-12-02 13:59:33 +01:00
|
|
|
emit addOutput(output, OutputFormat::Stderr, DontAppendNewline);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
void AbstractProcessStep::finish(bool success)
|
2013-02-15 16:18:49 +01:00
|
|
|
{
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
emit finished(success);
|
2013-02-15 16:18:49 +01:00
|
|
|
}
|
|
|
|
|
|
2022-06-29 17:16:19 +02:00
|
|
|
void AbstractProcessStep::handleProcessDone()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2021-09-20 14:35:37 +02:00
|
|
|
QTC_ASSERT(d->m_process.get(), return);
|
2022-04-06 12:54:14 +02:00
|
|
|
if (d->m_process->error() == QProcess::FailedToStart) {
|
|
|
|
|
processStartupFailed();
|
2022-06-29 17:16:19 +02:00
|
|
|
d->m_process.release()->deleteLater();
|
2022-04-06 12:54:14 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2021-09-20 14:35:37 +02:00
|
|
|
d->cleanUp(d->m_process->exitCode(), d->m_process->exitStatus());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2018-03-28 12:37:19 +02:00
|
|
|
|
2018-11-17 21:19:04 +02:00
|
|
|
} // namespace ProjectExplorer
|