forked from qt-creator/qt-creator
Handle environment variables in customprocessstep
Reviewed-by: dt
This commit is contained in:
@@ -71,6 +71,11 @@ void AbstractProcessStep::setCommand(const QString &cmd)
|
||||
m_command = cmd;
|
||||
}
|
||||
|
||||
QString AbstractProcessStep::command() const
|
||||
{
|
||||
return m_command;
|
||||
}
|
||||
|
||||
QString AbstractProcessStep::workingDirectory() const
|
||||
{
|
||||
return m_workingDirectory;
|
||||
@@ -114,6 +119,11 @@ void AbstractProcessStep::setArguments(const QStringList &arguments)
|
||||
m_arguments = arguments;
|
||||
}
|
||||
|
||||
QStringList AbstractProcessStep::arguments() const
|
||||
{
|
||||
return m_arguments;
|
||||
}
|
||||
|
||||
void AbstractProcessStep::setEnabled(bool b)
|
||||
{
|
||||
m_enabled = b;
|
||||
@@ -131,11 +141,6 @@ void AbstractProcessStep::setEnvironment(Utils::Environment env)
|
||||
|
||||
bool AbstractProcessStep::init()
|
||||
{
|
||||
if (QFileInfo(m_command).isRelative()) {
|
||||
QString searchInPath = m_environment.searchInPath(m_command);
|
||||
if (!searchInPath.isEmpty())
|
||||
m_command = searchInPath;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -146,12 +151,13 @@ void AbstractProcessStep::run(QFutureInterface<bool> &fi)
|
||||
fi.reportResult(true);
|
||||
return;
|
||||
}
|
||||
QDir wd(m_workingDirectory);
|
||||
QString workDir = m_environment.expandVariables(m_workingDirectory);
|
||||
QDir wd(workDir);
|
||||
if (!wd.exists())
|
||||
wd.mkpath(wd.absolutePath());
|
||||
|
||||
m_process = new QProcess();
|
||||
m_process->setWorkingDirectory(m_workingDirectory);
|
||||
m_process->setWorkingDirectory(workDir);
|
||||
m_process->setEnvironment(m_environment.toStringList());
|
||||
|
||||
connect(m_process, SIGNAL(readyReadStandardOutput()),
|
||||
@@ -165,7 +171,7 @@ void AbstractProcessStep::run(QFutureInterface<bool> &fi)
|
||||
this, SLOT(slotProcessFinished(int, QProcess::ExitStatus)),
|
||||
Qt::DirectConnection);
|
||||
|
||||
m_process->start(m_command, m_arguments);
|
||||
m_process->start(expandedCommand(), m_environment.expandVariables(m_arguments));
|
||||
if (!m_process->waitForStarted()) {
|
||||
processStartupFailed();
|
||||
delete m_process;
|
||||
@@ -205,27 +211,34 @@ void AbstractProcessStep::run(QFutureInterface<bool> &fi)
|
||||
|
||||
void AbstractProcessStep::processStarted()
|
||||
{
|
||||
emit addOutput(tr("Starting: \"%1\" %2\n").arg(QDir::toNativeSeparators(m_command), m_arguments.join(" ")), BuildStep::MessageOutput);
|
||||
emit addOutput(tr("Starting: \"%1\" %2\n")
|
||||
.arg(QDir::toNativeSeparators(expandedCommand()),
|
||||
m_environment.expandVariables(m_arguments).join(QChar(' '))),
|
||||
BuildStep::MessageOutput);
|
||||
}
|
||||
|
||||
void AbstractProcessStep::processFinished(int exitCode, QProcess::ExitStatus status)
|
||||
{
|
||||
QString command = expandedCommand();
|
||||
if (status == QProcess::NormalExit && exitCode == 0) {
|
||||
emit addOutput(tr("The process \"%1\" exited normally.")
|
||||
.arg(QDir::toNativeSeparators(m_command)),
|
||||
.arg(QDir::toNativeSeparators(command)),
|
||||
BuildStep::MessageOutput);
|
||||
} else if (status == QProcess::NormalExit) {
|
||||
emit addOutput(tr("The process \"%1\" exited with code %2.")
|
||||
.arg(QDir::toNativeSeparators(m_command), QString::number(m_process->exitCode())),
|
||||
.arg(QDir::toNativeSeparators(command), QString::number(m_process->exitCode())),
|
||||
BuildStep::ErrorMessageOutput);
|
||||
} else {
|
||||
emit addOutput(tr("The process \"%1\" crashed.").arg(QDir::toNativeSeparators(m_command)), BuildStep::ErrorMessageOutput);
|
||||
emit addOutput(tr("The process \"%1\" crashed.").arg(QDir::toNativeSeparators(command)), BuildStep::ErrorMessageOutput);
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractProcessStep::processStartupFailed()
|
||||
{
|
||||
emit addOutput(tr("Could not start process \"%1\"").arg(QDir::toNativeSeparators(m_command)), BuildStep::ErrorMessageOutput);
|
||||
emit addOutput(tr("Could not start process \"%1\" %2").
|
||||
arg(QDir::toNativeSeparators(expandedCommand()),
|
||||
m_environment.expandVariables(m_arguments).join(QChar(' '))),
|
||||
BuildStep::ErrorMessageOutput);
|
||||
}
|
||||
|
||||
bool AbstractProcessStep::processSucceeded(int exitCode, QProcess::ExitStatus status)
|
||||
@@ -340,3 +353,11 @@ void AbstractProcessStep::slotProcessFinished(int, QProcess::ExitStatus)
|
||||
|
||||
m_eventLoop->exit(0);
|
||||
}
|
||||
|
||||
QString AbstractProcessStep::expandedCommand() const
|
||||
{
|
||||
QString command = m_environment.searchInPath(m_command, QStringList() << workingDirectory());
|
||||
if (command.isEmpty())
|
||||
command = m_command;
|
||||
return command;
|
||||
}
|
||||
|
||||
@@ -85,6 +85,7 @@ public:
|
||||
/// setCommand() sets the executable to run in the \p buildConfiguration
|
||||
/// should be called from init()
|
||||
void setCommand(const QString &cmd);
|
||||
QString command() const;
|
||||
|
||||
/// sets the workingDirectory for the process for a buildConfiguration
|
||||
/// should be called from init()
|
||||
@@ -93,6 +94,7 @@ public:
|
||||
/// sets the command line arguments used by the process for a \p buildConfiguration
|
||||
/// should be called from init()
|
||||
void setArguments(const QStringList &arguments);
|
||||
QStringList arguments() const;
|
||||
|
||||
/// enables or disables a BuildStep
|
||||
/// Disabled BuildSteps immediately return true from their run method
|
||||
@@ -121,6 +123,9 @@ protected:
|
||||
AbstractProcessStep(BuildStepList *bsl, const QString &id);
|
||||
AbstractProcessStep(BuildStepList *bsl, AbstractProcessStep *bs);
|
||||
|
||||
/// Get the fully expanded command name to run:
|
||||
QString expandedCommand() const;
|
||||
|
||||
/// Called after the process is started
|
||||
/// the default implementation adds a process started message to the output message
|
||||
virtual void processStarted();
|
||||
@@ -151,6 +156,7 @@ private slots:
|
||||
|
||||
void outputAdded(const QString &string, ProjectExplorer::BuildStep::OutputFormat format);
|
||||
private:
|
||||
|
||||
QTimer *m_timer;
|
||||
QFutureInterface<bool> *m_futureInterface;
|
||||
QString m_workingDirectory;
|
||||
|
||||
@@ -77,6 +77,8 @@ void ProcessStep::ctor()
|
||||
{
|
||||
//: Default ProcessStep display name
|
||||
setDefaultDisplayName(tr("Custom Process Step"));
|
||||
if (m_workingDirectory.isEmpty())
|
||||
m_workingDirectory = QLatin1String("$BUILDDIR");
|
||||
}
|
||||
|
||||
ProcessStep::~ProcessStep()
|
||||
@@ -87,11 +89,8 @@ bool ProcessStep::init()
|
||||
{
|
||||
BuildConfiguration *bc = buildConfiguration();
|
||||
setEnvironment(bc->environment());
|
||||
QString wd = workingDirectory();
|
||||
if (wd.isEmpty())
|
||||
wd = "$BUILDDIR";
|
||||
|
||||
AbstractProcessStep::setWorkingDirectory(wd.replace("$BUILDDIR", bc->buildDirectory()));
|
||||
AbstractProcessStep::setWorkingDirectory(workingDirectory());
|
||||
AbstractProcessStep::setCommand(m_command);
|
||||
AbstractProcessStep::setEnabled(m_enabled);
|
||||
AbstractProcessStep::setArguments(m_arguments);
|
||||
@@ -151,6 +150,9 @@ void ProcessStep::setEnabled(bool enabled)
|
||||
|
||||
void ProcessStep::setWorkingDirectory(const QString &workingDirectory)
|
||||
{
|
||||
if (workingDirectory.isEmpty())
|
||||
m_workingDirectory = QLatin1String("$BUILDDIR");
|
||||
else
|
||||
m_workingDirectory = workingDirectory;
|
||||
}
|
||||
|
||||
@@ -249,7 +251,7 @@ ProcessStepConfigWidget::ProcessStepConfigWidget(ProcessStep *step)
|
||||
: m_step(step)
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
m_ui.command->setExpectedKind(Utils::PathChooser::Command);
|
||||
m_ui.command->setExpectedKind(Utils::PathChooser::ExistingCommand);
|
||||
connect(m_ui.command, SIGNAL(changed(QString)),
|
||||
this, SLOT(commandLineEditTextEdited()));
|
||||
connect(m_ui.workingDirectory, SIGNAL(changed(QString)),
|
||||
@@ -281,12 +283,11 @@ QString ProcessStepConfigWidget::displayName() const
|
||||
|
||||
void ProcessStepConfigWidget::init()
|
||||
{
|
||||
m_ui.command->setEnvironment(m_step->buildConfiguration()->environment());
|
||||
m_ui.command->setPath(m_step->command());
|
||||
|
||||
QString workingDirectory = m_step->workingDirectory();
|
||||
if (workingDirectory.isEmpty())
|
||||
workingDirectory = "$BUILDDIR";
|
||||
m_ui.workingDirectory->setPath(workingDirectory);
|
||||
m_ui.workingDirectory->setEnvironment(m_step->buildConfiguration()->environment());
|
||||
m_ui.workingDirectory->setPath(m_step->workingDirectory());
|
||||
|
||||
m_ui.commandArgumentsLineEdit->setText(m_step->arguments().join(QString(QLatin1Char(' '))));
|
||||
m_ui.enabledCheckBox->setChecked(m_step->enabled());
|
||||
@@ -301,13 +302,13 @@ QString ProcessStepConfigWidget::summaryText() const
|
||||
|
||||
void ProcessStepConfigWidget::commandLineEditTextEdited()
|
||||
{
|
||||
m_step->setCommand(m_ui.command->path());
|
||||
m_step->setCommand(m_ui.command->rawPath());
|
||||
updateDetails();
|
||||
}
|
||||
|
||||
void ProcessStepConfigWidget::workingDirectoryLineEditTextEdited()
|
||||
{
|
||||
m_step->setWorkingDirectory(m_ui.workingDirectory->path());
|
||||
m_step->setWorkingDirectory(m_ui.workingDirectory->rawPath());
|
||||
}
|
||||
|
||||
void ProcessStepConfigWidget::commandArgumentsLineEditTextEdited()
|
||||
|
||||
Reference in New Issue
Block a user