2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 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"
|
2023-01-13 12:38:22 +01:00
|
|
|
|
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"
|
2023-01-13 12:38:22 +01:00
|
|
|
#include "projectexplorertr.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>
|
2023-05-03 17:05:35 +02:00
|
|
|
#include <utils/process.h>
|
2009-12-09 13:54:46 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
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
|
|
|
|
2023-05-10 19:54:52 +02:00
|
|
|
using namespace Tasking;
|
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;
|
2023-05-03 16:00:22 +02:00
|
|
|
std::unique_ptr<Process> m_process;
|
2022-12-06 06:49:30 +01:00
|
|
|
std::unique_ptr<TaskTree> m_taskTree;
|
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()
|
|
|
|
|
{
|
2023-01-13 12:38:22 +01:00
|
|
|
emit addOutput(Tr::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
|
|
|
{
|
2022-12-06 06:49:30 +01:00
|
|
|
if (d->m_process || d->m_taskTree)
|
2020-09-14 17:17:55 +02:00
|
|
|
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()
|
2022-12-06 06:49:30 +01:00
|
|
|
{
|
|
|
|
|
if (!checkWorkingDirectory())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!d->m_param.effectiveCommand().isExecutableFile()) {
|
|
|
|
|
processStartupFailed();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setupStreams();
|
|
|
|
|
|
2023-05-03 16:00:22 +02:00
|
|
|
d->m_process.reset(new Process);
|
2022-12-06 06:49:30 +01:00
|
|
|
setupProcess(d->m_process.get());
|
2023-05-03 16:00:22 +02:00
|
|
|
connect(d->m_process.get(), &Process::done, this, &AbstractProcessStep::handleProcessDone);
|
2022-12-06 06:49:30 +01:00
|
|
|
d->m_process->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AbstractProcessStep::checkWorkingDirectory()
|
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()) {
|
2023-01-13 12:38:22 +01:00
|
|
|
emit addOutput(Tr::tr("Could not create directory \"%1\"").arg(wd.toUserOutput()),
|
2022-12-02 13:59:33 +01:00
|
|
|
OutputFormat::ErrorMessage);
|
2022-12-02 17:37:10 +01:00
|
|
|
finish(ProcessResult::StartFailed);
|
2022-12-06 06:49:30 +01:00
|
|
|
return false;
|
2014-10-22 12:29:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
2022-12-06 06:49:30 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2014-10-22 12:29:41 +02:00
|
|
|
|
2022-12-06 06:49:30 +01:00
|
|
|
void AbstractProcessStep::setupStreams()
|
|
|
|
|
{
|
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-12-06 06:49:30 +01:00
|
|
|
}
|
2020-03-31 14:34:08 +02:00
|
|
|
|
2023-05-03 16:00:22 +02:00
|
|
|
void AbstractProcessStep::setupProcess(Process *process)
|
2022-12-06 06:49:30 +01:00
|
|
|
{
|
|
|
|
|
process->setUseCtrlCStub(HostOsInfo::isWindowsHost());
|
|
|
|
|
process->setWorkingDirectory(d->m_param.effectiveWorkingDirectory());
|
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();
|
2022-12-06 06:49:30 +01:00
|
|
|
envWithPwd.set("PWD", process->workingDirectory().path());
|
|
|
|
|
process->setEnvironment(envWithPwd);
|
|
|
|
|
process->setCommand({d->m_param.effectiveCommand(), d->m_param.effectiveArguments(),
|
|
|
|
|
CommandLine::Raw});
|
2019-10-09 21:29:12 +03:00
|
|
|
if (d->m_lowPriority && ProjectExplorerPlugin::projectExplorerSettings().lowBuildPriority)
|
2022-12-06 06:49:30 +01:00
|
|
|
process->setLowPriority();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2023-05-03 16:00:22 +02:00
|
|
|
connect(process, &Process::readyReadStandardOutput, this, [this, process] {
|
2023-01-05 17:55:04 +01:00
|
|
|
emit addOutput(d->stdoutStream->toUnicode(process->readAllRawStandardOutput()),
|
2022-12-02 15:27:22 +01:00
|
|
|
OutputFormat::Stdout, DontAppendNewline);
|
2022-12-02 12:40:12 +01:00
|
|
|
});
|
2023-05-03 16:00:22 +02:00
|
|
|
connect(process, &Process::readyReadStandardError, this, [this, process] {
|
2023-01-05 17:55:04 +01:00
|
|
|
emit addOutput(d->stderrStream->toUnicode(process->readAllRawStandardError()),
|
2022-12-02 15:27:22 +01:00
|
|
|
OutputFormat::Stderr, DontAppendNewline);
|
2022-12-02 12:40:12 +01:00
|
|
|
});
|
2023-05-03 16:00:22 +02:00
|
|
|
connect(process, &Process::started, this, [this] {
|
2022-12-02 13:59:33 +01:00
|
|
|
ProcessParameters *params = displayedParameters();
|
2023-01-13 12:38:22 +01:00
|
|
|
emit addOutput(Tr::tr("Starting: \"%1\" %2")
|
2022-12-02 13:59:33 +01:00
|
|
|
.arg(params->effectiveCommand().toUserOutput(), params->prettyArguments()),
|
|
|
|
|
OutputFormat::NormalMessage);
|
|
|
|
|
});
|
2022-12-06 06:49:30 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2023-05-10 19:54:52 +02:00
|
|
|
void AbstractProcessStep::runTaskTree(const Group &recipe)
|
2022-12-06 06:49:30 +01:00
|
|
|
{
|
|
|
|
|
setupStreams();
|
|
|
|
|
|
|
|
|
|
d->m_taskTree.reset(new TaskTree(recipe));
|
|
|
|
|
connect(d->m_taskTree.get(), &TaskTree::progressValueChanged, this, [this](int value) {
|
2023-01-30 09:46:20 +02:00
|
|
|
emit progress(qRound(double(value) * 100 / std::max(d->m_taskTree->progressMaximum(), 1)), {});
|
2022-12-06 06:49:30 +01:00
|
|
|
});
|
|
|
|
|
connect(d->m_taskTree.get(), &TaskTree::done, this, [this] {
|
|
|
|
|
emit finished(true);
|
|
|
|
|
d->m_taskTree.release()->deleteLater();
|
|
|
|
|
});
|
|
|
|
|
connect(d->m_taskTree.get(), &TaskTree::errorOccurred, this, [this] {
|
|
|
|
|
emit finished(false);
|
|
|
|
|
d->m_taskTree.release()->deleteLater();
|
|
|
|
|
});
|
|
|
|
|
d->m_taskTree->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
|
|
|
{
|
2022-12-06 06:49:30 +01:00
|
|
|
if (d->m_process) {
|
|
|
|
|
d->cleanUp(-1, QProcess::CrashExit);
|
|
|
|
|
}
|
|
|
|
|
if (d->m_taskTree) {
|
|
|
|
|
d->m_taskTree.reset();
|
2023-01-13 12:38:22 +01:00
|
|
|
emit addOutput(Tr::tr("The build step was ended forcefully."), OutputFormat::ErrorMessage);
|
2022-12-06 06:49:30 +01:00
|
|
|
emit finished(false);
|
|
|
|
|
}
|
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();
|
|
|
|
|
|
2022-11-30 16:39:21 +01:00
|
|
|
// E.g. the QMakeStep doesn't have set up anything when this is called
|
|
|
|
|
// as it doesn't set a command line provider, so executable might be empty.
|
|
|
|
|
const bool looksGood = executable.isEmpty() || executable.ensureReachable(workingDirectory);
|
|
|
|
|
QTC_ASSERT(looksGood, return false);
|
|
|
|
|
|
2023-03-29 13:45:42 +02:00
|
|
|
params->setWorkingDirectory(executable.withNewPath(workingDirectory.path()));
|
2022-10-18 14:17:35 +02:00
|
|
|
|
|
|
|
|
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) {
|
2023-01-13 12:38:22 +01:00
|
|
|
emit q->addOutput(Tr::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) {
|
2023-01-13 12:38:22 +01:00
|
|
|
emit q->addOutput(Tr::tr("The process \"%1\" exited with code %2.")
|
2022-12-02 11:33:28 +01:00
|
|
|
.arg(command, QString::number(exitCode)),
|
2022-12-02 13:59:33 +01:00
|
|
|
OutputFormat::ErrorMessage);
|
2022-12-02 11:33:28 +01:00
|
|
|
} else {
|
2023-01-13 12:38:22 +01:00
|
|
|
emit q->addOutput(Tr::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-04-04 14:31:21 +02:00
|
|
|
if (m_process)
|
|
|
|
|
m_process.release()->deleteLater();
|
2022-12-02 17:37:10 +01:00
|
|
|
const ProcessResult result = (status == QProcess::NormalExit && exitCode == 0
|
|
|
|
|
&& !outputFormatter->hasFatalErrors())
|
|
|
|
|
? ProcessResult::FinishedWithSuccess : ProcessResult::FinishedWithError;
|
|
|
|
|
q->finish(result);
|
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();
|
2023-01-13 12:38:22 +01:00
|
|
|
emit addOutput(Tr::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);
|
|
|
|
|
|
2022-12-06 06:49:30 +01:00
|
|
|
const QString err = d->m_process ? d->m_process->errorString() : QString();
|
2021-06-07 12:33:45 +02:00
|
|
|
if (!err.isEmpty())
|
|
|
|
|
emit addOutput(err, OutputFormat::ErrorMessage);
|
2022-12-02 17:37:10 +01:00
|
|
|
finish(ProcessResult::StartFailed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AbstractProcessStep::isSuccess(ProcessResult result) const
|
|
|
|
|
{
|
|
|
|
|
return result == ProcessResult::FinishedWithSuccess
|
|
|
|
|
|| (result == ProcessResult::FinishedWithError && d->m_ignoreReturnValue);
|
2010-04-09 13:10:59 +02:00
|
|
|
}
|
|
|
|
|
|
2022-12-02 17:37:10 +01:00
|
|
|
void AbstractProcessStep::finish(ProcessResult result)
|
2013-02-15 16:18:49 +01:00
|
|
|
{
|
2022-12-02 17:37:10 +01:00
|
|
|
emit finished(isSuccess(result));
|
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
|