From 498934cfe86e38924f61a14624068a34a0360bda Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Wed, 6 Jul 2016 09:43:55 +0200 Subject: [PATCH] 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 --- .../projectexplorer/projectexplorer.cpp | 34 ++++++++++++++++--- .../projectexplorer/projectexplorersettings.h | 2 +- .../projectexplorersettingspage.cpp | 4 +-- .../projectexplorersettingspage.ui | 5 +++ 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index f435c270aaf..8181cef09f5 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -1144,7 +1144,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er dd->m_projectExplorerSettings.environmentId = QUuid::createUuid(); int tmp = s->value(QLatin1String("ProjectExplorer/Settings/StopBeforeBuild"), Utils::HostOsInfo::isWindowsHost() ? 1 : 0).toInt(); - if (tmp < 0 || tmp > ProjectExplorerSettings::StopAll) + if (tmp < 0 || tmp > ProjectExplorerSettings::StopSameBuildDir) tmp = Utils::HostOsInfo::isWindowsHost() ? 1 : 0; dd->m_projectExplorerSettings.stopBeforeBuild = ProjectExplorerSettings::StopBeforeBuild(tmp); @@ -2225,10 +2225,36 @@ int ProjectExplorerPluginPrivate::queue(QList projects, QList ste if (m_projectExplorerSettings.stopBeforeBuild != ProjectExplorerSettings::StopNone && stepIds.contains(Constants::BUILDSTEPS_BUILD)) { - bool stopAll = (m_projectExplorerSettings.stopBeforeBuild == ProjectExplorerSettings::StopAll); + ProjectExplorerSettings::StopBeforeBuild stopCondition = m_projectExplorerSettings.stopBeforeBuild; const QList toStop - = Utils::filtered(m_outputPane->allRunControls(), [&projects, stopAll](RunControl *rc) { - return rc->isRunning() && (stopAll || projects.contains(rc->project())); + = Utils::filtered(m_outputPane->allRunControls(), [&projects, stopCondition](RunControl *rc) -> bool { + 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()) + return false; + if (!Utils::FileName::fromString(rc->runnable().as().executable).isChildOf(bc->buildDirectory())) + return false; + IDevice::ConstPtr device = rc->runnable().as().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()) { diff --git a/src/plugins/projectexplorer/projectexplorersettings.h b/src/plugins/projectexplorer/projectexplorersettings.h index 046b90e88ac..a2759d66e3d 100644 --- a/src/plugins/projectexplorer/projectexplorersettings.h +++ b/src/plugins/projectexplorer/projectexplorersettings.h @@ -33,7 +33,7 @@ namespace Internal { class ProjectExplorerSettings { public: - enum StopBeforeBuild { StopNone = 0, StopSameProject = 1, StopAll = 2 }; + enum StopBeforeBuild { StopNone = 0, StopSameProject, StopAll, StopSameBuildDir }; bool buildBeforeDeploy = true; bool deployBeforeRun = true; diff --git a/src/plugins/projectexplorer/projectexplorersettingspage.cpp b/src/plugins/projectexplorer/projectexplorersettingspage.cpp index 7605ddbbe24..12c6b10fdc0 100644 --- a/src/plugins/projectexplorer/projectexplorersettingspage.cpp +++ b/src/plugins/projectexplorer/projectexplorersettingspage.cpp @@ -109,7 +109,7 @@ ProjectExplorerSettings ProjectExplorerSettingsWidget::settings() const m_settings.useJom = m_ui.jomCheckbox->isChecked(); m_settings.prompToStopRunControl = m_ui.promptToStopRunControlCheckBox->isChecked(); m_settings.maxAppOutputLines = m_ui.maxAppOutputBox->value(); - m_settings.stopBeforeBuild = ProjectExplorerSettings::StopBeforeBuild(m_ui.stopBeforeBuildComboBox->currentIndex()); + m_settings.stopBeforeBuild = static_cast(m_ui.stopBeforeBuildComboBox->currentIndex()); return m_settings; } @@ -128,7 +128,7 @@ void ProjectExplorerSettingsWidget::setSettings(const ProjectExplorerSettings & m_ui.jomCheckbox->setChecked(m_settings.useJom); m_ui.promptToStopRunControlCheckBox->setChecked(m_settings.prompToStopRunControl); m_ui.maxAppOutputBox->setValue(m_settings.maxAppOutputLines); - m_ui.stopBeforeBuildComboBox->setCurrentIndex(pes.stopBeforeBuild); + m_ui.stopBeforeBuildComboBox->setCurrentIndex(static_cast(pes.stopBeforeBuild)); } QString ProjectExplorerSettingsWidget::projectsDirectory() const diff --git a/src/plugins/projectexplorer/projectexplorersettingspage.ui b/src/plugins/projectexplorer/projectexplorersettingspage.ui index 01a131b63fa..7ea652cc174 100644 --- a/src/plugins/projectexplorer/projectexplorersettingspage.ui +++ b/src/plugins/projectexplorer/projectexplorersettingspage.ui @@ -202,6 +202,11 @@ All + + + Same Build Directory + +