Skip to content
Snippets Groups Projects
Commit cfe21caf authored by Tobias Hunger's avatar Tobias Hunger
Browse files

CustomExecutableRC: Use environment variables

Expand environment variables in working directory, executable name
as well as arguments of the CustonExecutableRunConfiguration.

Reviewed-by: dt
parent 656c8691
No related branches found
No related tags found
No related merge requests found
...@@ -90,6 +90,7 @@ CustomExecutableConfigurationWidget::CustomExecutableConfigurationWidget(CustomE ...@@ -90,6 +90,7 @@ CustomExecutableConfigurationWidget::CustomExecutableConfigurationWidget(CustomE
layout->setMargin(0); layout->setMargin(0);
m_executableChooser = new Utils::PathChooser(this); m_executableChooser = new Utils::PathChooser(this);
m_executableChooser->setEnvironment(rc->environment());
m_executableChooser->setExpectedKind(Utils::PathChooser::Command); m_executableChooser->setExpectedKind(Utils::PathChooser::Command);
layout->addRow(tr("Executable:"), m_executableChooser); layout->addRow(tr("Executable:"), m_executableChooser);
...@@ -100,6 +101,7 @@ CustomExecutableConfigurationWidget::CustomExecutableConfigurationWidget(CustomE ...@@ -100,6 +101,7 @@ CustomExecutableConfigurationWidget::CustomExecutableConfigurationWidget(CustomE
m_workingDirectory = new CustomDirectoryPathChooser(this); m_workingDirectory = new CustomDirectoryPathChooser(this);
m_workingDirectory->setExpectedKind(Utils::PathChooser::Directory); m_workingDirectory->setExpectedKind(Utils::PathChooser::Directory);
m_workingDirectory->setBaseDirectory(rc->target()->project()->projectDirectory()); m_workingDirectory->setBaseDirectory(rc->target()->project()->projectDirectory());
m_workingDirectory->setEnvironment(rc->environment());
layout->addRow(tr("Working directory:"), m_workingDirectory); layout->addRow(tr("Working directory:"), m_workingDirectory);
m_useTerminalCheck = new QCheckBox(tr("Run in &Terminal"), this); m_useTerminalCheck = new QCheckBox(tr("Run in &Terminal"), this);
...@@ -242,7 +244,7 @@ void CustomExecutableConfigurationWidget::userEnvironmentChangesChanged() ...@@ -242,7 +244,7 @@ void CustomExecutableConfigurationWidget::userEnvironmentChangesChanged()
void CustomExecutableConfigurationWidget::executableEdited() void CustomExecutableConfigurationWidget::executableEdited()
{ {
m_ignoreChange = true; m_ignoreChange = true;
m_runConfiguration->setExecutable(QDir::fromNativeSeparators(m_executableChooser->path())); m_runConfiguration->setExecutable(m_executableChooser->rawPath());
m_ignoreChange = false; m_ignoreChange = false;
} }
void CustomExecutableConfigurationWidget::argumentsEdited(const QString &arguments) void CustomExecutableConfigurationWidget::argumentsEdited(const QString &arguments)
...@@ -254,7 +256,7 @@ void CustomExecutableConfigurationWidget::argumentsEdited(const QString &argumen ...@@ -254,7 +256,7 @@ void CustomExecutableConfigurationWidget::argumentsEdited(const QString &argumen
void CustomExecutableConfigurationWidget::workingDirectoryEdited() void CustomExecutableConfigurationWidget::workingDirectoryEdited()
{ {
m_ignoreChange = true; m_ignoreChange = true;
m_runConfiguration->setWorkingDirectory(m_workingDirectory->path()); m_runConfiguration->setWorkingDirectory(m_workingDirectory->rawPath());
m_ignoreChange = false; m_ignoreChange = false;
} }
...@@ -268,18 +270,19 @@ void CustomExecutableConfigurationWidget::termToggled(bool on) ...@@ -268,18 +270,19 @@ void CustomExecutableConfigurationWidget::termToggled(bool on)
void CustomExecutableConfigurationWidget::changed() void CustomExecutableConfigurationWidget::changed()
{ {
const QString &executable = m_runConfiguration->baseExecutable(); const QString &executable = m_runConfiguration->rawExecutable();
QString text = tr("No Executable specified."); QString text = tr("No Executable specified.");
if (!executable.isEmpty()) if (!executable.isEmpty())
text = tr("Running executable: <b>%1</b> %2"). text = tr("Running executable: <b>%1</b> %2").
arg(executable, arg(executable,
Utils::Environment::joinArgumentList(m_runConfiguration->commandLineArguments())); Utils::Environment::joinArgumentList(m_runConfiguration->commandLineArguments()));
// We triggered the change, don't update us // We triggered the change, don't update us
if (m_ignoreChange) if (m_ignoreChange)
return; return;
m_executableChooser->setPath(executable); m_executableChooser->setPath(executable);
m_commandLineArgumentsLineEdit->setText(Utils::Environment::joinArgumentList(m_runConfiguration->commandLineArguments())); m_commandLineArgumentsLineEdit->setText(Utils::Environment::joinArgumentList(m_runConfiguration->commandLineArguments()));
m_workingDirectory->setPath(m_runConfiguration->baseWorkingDirectory()); m_workingDirectory->setPath(m_runConfiguration->workingDirectory());
m_useTerminalCheck->setChecked(m_runConfiguration->runMode() == LocalApplicationRunConfiguration::Console); m_useTerminalCheck->setChecked(m_runConfiguration->runMode() == LocalApplicationRunConfiguration::Console);
} }
...@@ -337,24 +340,12 @@ void CustomExecutableRunConfiguration::activeBuildConfigurationChanged() ...@@ -337,24 +340,12 @@ void CustomExecutableRunConfiguration::activeBuildConfigurationChanged()
} }
} }
QString CustomExecutableRunConfiguration::baseExecutable() const
{
return m_executable;
}
QString CustomExecutableRunConfiguration::executable() const QString CustomExecutableRunConfiguration::executable() const
{ {
QString exec; Utils::Environment env = environment();
if (!m_executable.isEmpty() && QDir::isRelativePath(m_executable)) { QString exec = env.searchInPath(m_executable, QStringList() << env.expandVariables(workingDirectory()));
Utils::Environment env = environment();
exec = env.searchInPath(m_executable);
if (exec.isEmpty())
exec = QDir::cleanPath(workingDirectory() + QLatin1Char('/') + m_executable);
} else {
exec = m_executable;
}
if (m_executable.isEmpty() || !QFileInfo(exec).exists()) { if (exec.isEmpty() || !QFileInfo(exec).exists()) {
// Oh the executable doesn't exists, ask the user. // Oh the executable doesn't exists, ask the user.
QWidget *confWidget = const_cast<CustomExecutableRunConfiguration *>(this)->createConfigurationWidget(); QWidget *confWidget = const_cast<CustomExecutableRunConfiguration *>(this)->createConfigurationWidget();
confWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); confWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
...@@ -385,7 +376,12 @@ QString CustomExecutableRunConfiguration::executable() const ...@@ -385,7 +376,12 @@ QString CustomExecutableRunConfiguration::executable() const
return QString(); return QString();
} }
} }
return exec; return m_executable;
}
QString CustomExecutableRunConfiguration::rawExecutable() const
{
return m_executable;
} }
bool CustomExecutableRunConfiguration::isConfigured() const bool CustomExecutableRunConfiguration::isConfigured() const
...@@ -398,19 +394,9 @@ LocalApplicationRunConfiguration::RunMode CustomExecutableRunConfiguration::runM ...@@ -398,19 +394,9 @@ LocalApplicationRunConfiguration::RunMode CustomExecutableRunConfiguration::runM
return m_runMode; return m_runMode;
} }
QString CustomExecutableRunConfiguration::baseWorkingDirectory() const
{
return m_workingDirectory;
}
QString CustomExecutableRunConfiguration::workingDirectory() const QString CustomExecutableRunConfiguration::workingDirectory() const
{ {
QString wd = m_workingDirectory; return m_workingDirectory;
if (activeBuildConfiguration()) {
QString bd = activeBuildConfiguration()->buildDirectory();
wd.replace("$BUILDDIR", QDir::cleanPath(bd));
}
return wd;
} }
QStringList CustomExecutableRunConfiguration::commandLineArguments() const QStringList CustomExecutableRunConfiguration::commandLineArguments() const
......
...@@ -76,21 +76,14 @@ public: ...@@ -76,21 +76,14 @@ public:
* ask the user if none is specified * ask the user if none is specified
*/ */
QString executable() const; QString executable() const;
QString rawExecutable() const;
/** Returns whether this runconfiguration ever was configured with a executable /** Returns whether this runconfiguration ever was configured with a executable
*/ */
bool isConfigured() const; bool isConfigured() const;
/**
* Returns only what is stored in the internal variable, not what we might
* get after extending it with a path or asking the user. This value is
* needed for the configuration widget.
*/
QString baseExecutable() const;
LocalApplicationRunConfiguration::RunMode runMode() const; LocalApplicationRunConfiguration::RunMode runMode() const;
QString workingDirectory() const; QString workingDirectory() const;
QString baseWorkingDirectory() const;
QStringList commandLineArguments() const; QStringList commandLineArguments() const;
Utils::Environment environment() const; Utils::Environment environment() const;
...@@ -134,6 +127,7 @@ private: ...@@ -134,6 +127,7 @@ private:
void setWorkingDirectory(const QString &workingDirectory); void setWorkingDirectory(const QString &workingDirectory);
void setUserName(const QString &name); void setUserName(const QString &name);
void setRunMode(RunMode runMode); void setRunMode(RunMode runMode);
QString m_executable; QString m_executable;
QString m_workingDirectory; QString m_workingDirectory;
QStringList m_cmdArguments; QStringList m_cmdArguments;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment