ProjectExplorer: Add option to stop applications from the same build directory

Creator can stop running applications when a build starts. This prevents isssues
on windows where the running application locks files in the build directory, which
in turn will make the build fail.

In addition to the current options to kill all applications or just those from the
current project, add a new option to kill all applications of the current project
that live in the same build directory.

Task-number: QTCREATORBUG-16470
Change-Id: Ib4a74e2452055eaf5f9e384555be5ef14de1cd40
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
Tobias Hunger
2016-07-06 09:43:55 +02:00
parent e1f9cba249
commit 498934cfe8
4 changed files with 38 additions and 7 deletions

View File

@@ -1144,7 +1144,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
dd->m_projectExplorerSettings.environmentId = QUuid::createUuid(); dd->m_projectExplorerSettings.environmentId = QUuid::createUuid();
int tmp = s->value(QLatin1String("ProjectExplorer/Settings/StopBeforeBuild"), int tmp = s->value(QLatin1String("ProjectExplorer/Settings/StopBeforeBuild"),
Utils::HostOsInfo::isWindowsHost() ? 1 : 0).toInt(); Utils::HostOsInfo::isWindowsHost() ? 1 : 0).toInt();
if (tmp < 0 || tmp > ProjectExplorerSettings::StopAll) if (tmp < 0 || tmp > ProjectExplorerSettings::StopSameBuildDir)
tmp = Utils::HostOsInfo::isWindowsHost() ? 1 : 0; tmp = Utils::HostOsInfo::isWindowsHost() ? 1 : 0;
dd->m_projectExplorerSettings.stopBeforeBuild = ProjectExplorerSettings::StopBeforeBuild(tmp); dd->m_projectExplorerSettings.stopBeforeBuild = ProjectExplorerSettings::StopBeforeBuild(tmp);
@@ -2225,10 +2225,36 @@ int ProjectExplorerPluginPrivate::queue(QList<Project *> projects, QList<Id> ste
if (m_projectExplorerSettings.stopBeforeBuild != ProjectExplorerSettings::StopNone if (m_projectExplorerSettings.stopBeforeBuild != ProjectExplorerSettings::StopNone
&& stepIds.contains(Constants::BUILDSTEPS_BUILD)) { && stepIds.contains(Constants::BUILDSTEPS_BUILD)) {
bool stopAll = (m_projectExplorerSettings.stopBeforeBuild == ProjectExplorerSettings::StopAll); ProjectExplorerSettings::StopBeforeBuild stopCondition = m_projectExplorerSettings.stopBeforeBuild;
const QList<RunControl *> toStop const QList<RunControl *> toStop
= Utils::filtered(m_outputPane->allRunControls(), [&projects, stopAll](RunControl *rc) { = Utils::filtered(m_outputPane->allRunControls(), [&projects, stopCondition](RunControl *rc) -> bool {
return rc->isRunning() && (stopAll || projects.contains(rc->project())); if (!rc->isRunning())
return false;
switch (stopCondition) {
case ProjectExplorerSettings::StopNone:
return false;
case ProjectExplorerSettings::StopAll:
return true;
case ProjectExplorerSettings::StopSameProject:
return projects.contains(rc->project());
case ProjectExplorerSettings::StopSameBuildDir:
return Utils::contains(projects, [rc](Project *p) {
Target *t = p ? p->activeTarget() : nullptr;
BuildConfiguration *bc = t ? t->activeBuildConfiguration() : nullptr;
if (!bc)
return false;
if (!rc->runnable().is<StandardRunnable>())
return false;
if (!Utils::FileName::fromString(rc->runnable().as<StandardRunnable>().executable).isChildOf(bc->buildDirectory()))
return false;
IDevice::ConstPtr device = rc->runnable().as<StandardRunnable>().device;
if (device.isNull())
device = DeviceKitInformation::device(t->kit());
return !device.isNull() && device->type() == Core::Id(Constants::DESKTOP_DEVICE_TYPE);
});
}
return false; // Can't get here!
}); });
if (!toStop.isEmpty()) { if (!toStop.isEmpty()) {

View File

@@ -33,7 +33,7 @@ namespace Internal {
class ProjectExplorerSettings class ProjectExplorerSettings
{ {
public: public:
enum StopBeforeBuild { StopNone = 0, StopSameProject = 1, StopAll = 2 }; enum StopBeforeBuild { StopNone = 0, StopSameProject, StopAll, StopSameBuildDir };
bool buildBeforeDeploy = true; bool buildBeforeDeploy = true;
bool deployBeforeRun = true; bool deployBeforeRun = true;

View File

@@ -109,7 +109,7 @@ ProjectExplorerSettings ProjectExplorerSettingsWidget::settings() const
m_settings.useJom = m_ui.jomCheckbox->isChecked(); m_settings.useJom = m_ui.jomCheckbox->isChecked();
m_settings.prompToStopRunControl = m_ui.promptToStopRunControlCheckBox->isChecked(); m_settings.prompToStopRunControl = m_ui.promptToStopRunControlCheckBox->isChecked();
m_settings.maxAppOutputLines = m_ui.maxAppOutputBox->value(); m_settings.maxAppOutputLines = m_ui.maxAppOutputBox->value();
m_settings.stopBeforeBuild = ProjectExplorerSettings::StopBeforeBuild(m_ui.stopBeforeBuildComboBox->currentIndex()); m_settings.stopBeforeBuild = static_cast<ProjectExplorerSettings::StopBeforeBuild>(m_ui.stopBeforeBuildComboBox->currentIndex());
return m_settings; return m_settings;
} }
@@ -128,7 +128,7 @@ void ProjectExplorerSettingsWidget::setSettings(const ProjectExplorerSettings &
m_ui.jomCheckbox->setChecked(m_settings.useJom); m_ui.jomCheckbox->setChecked(m_settings.useJom);
m_ui.promptToStopRunControlCheckBox->setChecked(m_settings.prompToStopRunControl); m_ui.promptToStopRunControlCheckBox->setChecked(m_settings.prompToStopRunControl);
m_ui.maxAppOutputBox->setValue(m_settings.maxAppOutputLines); m_ui.maxAppOutputBox->setValue(m_settings.maxAppOutputLines);
m_ui.stopBeforeBuildComboBox->setCurrentIndex(pes.stopBeforeBuild); m_ui.stopBeforeBuildComboBox->setCurrentIndex(static_cast<int>(pes.stopBeforeBuild));
} }
QString ProjectExplorerSettingsWidget::projectsDirectory() const QString ProjectExplorerSettingsWidget::projectsDirectory() const

View File

@@ -202,6 +202,11 @@
<string>All</string> <string>All</string>
</property> </property>
</item> </item>
<item>
<property name="text">
<string>Same Build Directory</string>
</property>
</item>
</widget> </widget>
</item> </item>
<item> <item>