forked from qt-creator/qt-creator
Partially decouple local CMakeRunConfiguration from CMakeProject
Funnel all relevant data through target.applicationTargets() as done for the non-local CMake-supporting setups and QBS already. There is cleanup potential left for later changes. Change-Id: I49ed6abd98c058a7fd1545e41b3bcd6ecb758a8b Task-number: QTCREATORBUG-19985 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -473,20 +473,9 @@ void CMakeProject::startParsing(int reparseParameters)
|
|||||||
m_buildDirManager.parse(reparseParameters);
|
m_buildDirManager.parse(reparseParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList CMakeProject::buildTargetTitles(bool runnable) const
|
QStringList CMakeProject::buildTargetTitles() const
|
||||||
{
|
{
|
||||||
const QList<CMakeBuildTarget> targets
|
return transform(buildTargets(), [](const CMakeBuildTarget &ct) { return ct.title; });
|
||||||
= runnable ? filtered(buildTargets(),
|
|
||||||
[](const CMakeBuildTarget &ct) {
|
|
||||||
return !ct.executable.isEmpty() && ct.targetType == ExecutableType;
|
|
||||||
})
|
|
||||||
: buildTargets();
|
|
||||||
return transform(targets, [](const CMakeBuildTarget &ct) { return ct.title; });
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CMakeProject::hasBuildTarget(const QString &title) const
|
|
||||||
{
|
|
||||||
return anyOf(buildTargets(), [title](const CMakeBuildTarget &ct) { return ct.title == title; });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Project::RestoreResult CMakeProject::fromMap(const QVariantMap &map, QString *errorMessage)
|
Project::RestoreResult CMakeProject::fromMap(const QVariantMap &map, QString *errorMessage)
|
||||||
@@ -562,14 +551,6 @@ void CMakeProject::combineScanAndParse(CMakeBuildConfiguration *bc)
|
|||||||
emitParsingFinished(m_combinedScanAndParseResult);
|
emitParsingFinished(m_combinedScanAndParseResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMakeBuildTarget CMakeProject::buildTargetForTitle(const QString &title)
|
|
||||||
{
|
|
||||||
foreach (const CMakeBuildTarget &ct, buildTargets())
|
|
||||||
if (ct.title == title)
|
|
||||||
return ct;
|
|
||||||
return CMakeBuildTarget();
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList CMakeProject::filesGeneratedFrom(const QString &sourceFile) const
|
QStringList CMakeProject::filesGeneratedFrom(const QString &sourceFile) const
|
||||||
{
|
{
|
||||||
if (!activeTarget())
|
if (!activeTarget())
|
||||||
@@ -676,10 +657,15 @@ void CMakeProject::updateApplicationAndDeploymentTargets()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ct.targetType == ExecutableType) {
|
if (ct.targetType == ExecutableType) {
|
||||||
FileName srcWithTrailingSlash = FileName::fromString(ct.sourceDirectory.toString());
|
BuildTargetInfo bti;
|
||||||
srcWithTrailingSlash.appendString('/');
|
bti.targetName = ct.title;
|
||||||
// TODO: Put a path to corresponding .cbp file into projectFilePath?
|
bti.displayName = ct.title;
|
||||||
appTargetList.list << BuildTargetInfo(ct.title, ct.executable, srcWithTrailingSlash);
|
bti.targetFilePath = ct.executable;
|
||||||
|
bti.projectFilePath = ct.sourceDirectory;
|
||||||
|
bti.projectFilePath.appendString('/');
|
||||||
|
bti.workingDirectory = ct.workingDirectory;
|
||||||
|
bti.buildKey = ct.title + QChar('\n') + bti.projectFilePath.toString();
|
||||||
|
appTargetList.list.append(bti);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -63,10 +63,7 @@ public:
|
|||||||
explicit CMakeProject(const Utils::FileName &filename);
|
explicit CMakeProject(const Utils::FileName &filename);
|
||||||
~CMakeProject() final;
|
~CMakeProject() final;
|
||||||
|
|
||||||
QStringList buildTargetTitles(bool runnable = false) const;
|
QStringList buildTargetTitles() const;
|
||||||
bool hasBuildTarget(const QString &title) const;
|
|
||||||
|
|
||||||
CMakeBuildTarget buildTargetForTitle(const QString &title);
|
|
||||||
|
|
||||||
bool knowsAllBuildExecutables() const final;
|
bool knowsAllBuildExecutables() const final;
|
||||||
|
|
||||||
|
@@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
#include "cmakerunconfiguration.h"
|
#include "cmakerunconfiguration.h"
|
||||||
|
|
||||||
#include "cmakebuildconfiguration.h"
|
|
||||||
#include "cmakeproject.h"
|
|
||||||
#include "cmakeprojectconstants.h"
|
#include "cmakeprojectconstants.h"
|
||||||
|
|
||||||
#include <coreplugin/coreicons.h>
|
#include <coreplugin/coreicons.h>
|
||||||
@@ -40,18 +38,11 @@
|
|||||||
#include <utils/detailswidget.h>
|
#include <utils/detailswidget.h>
|
||||||
#include <utils/fancylineedit.h>
|
#include <utils/fancylineedit.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/pathchooser.h>
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/qtcprocess.h>
|
|
||||||
#include <utils/stringutils.h>
|
#include <utils/stringutils.h>
|
||||||
|
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QLineEdit>
|
|
||||||
#include <QGroupBox>
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QComboBox>
|
|
||||||
#include <QToolButton>
|
|
||||||
#include <QCheckBox>
|
|
||||||
|
|
||||||
using namespace CMakeProjectManager;
|
using namespace CMakeProjectManager;
|
||||||
using namespace CMakeProjectManager::Internal;
|
using namespace CMakeProjectManager::Internal;
|
||||||
@@ -97,14 +88,6 @@ Runnable CMakeRunConfiguration::runnable() const
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CMakeRunConfiguration::baseWorkingDirectory() const
|
|
||||||
{
|
|
||||||
const QString exe = m_executable;
|
|
||||||
if (!exe.isEmpty())
|
|
||||||
return QFileInfo(m_executable).absolutePath();
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CMakeRunConfiguration::title() const
|
QString CMakeRunConfiguration::title() const
|
||||||
{
|
{
|
||||||
return m_title;
|
return m_title;
|
||||||
@@ -140,15 +123,22 @@ bool CMakeRunConfiguration::fromMap(const QVariantMap &map)
|
|||||||
m_executable = extraId;
|
m_executable = extraId;
|
||||||
if (m_title.isEmpty())
|
if (m_title.isEmpty())
|
||||||
m_title = extraId;
|
m_title = extraId;
|
||||||
|
|
||||||
CMakeProject *project = static_cast<CMakeProject *>(target()->project());
|
|
||||||
const CMakeBuildTarget ct = project->buildTargetForTitle(m_title);
|
|
||||||
extraAspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(ct.workingDirectory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMakeRunConfiguration::doAdditionalSetup(const RunConfigurationCreationInfo &info)
|
||||||
|
{
|
||||||
|
m_buildSystemTarget = info.targetName;
|
||||||
|
m_title = info.displayName;
|
||||||
|
m_executable = info.displayName;
|
||||||
|
setDefaultDisplayName(info.displayName);
|
||||||
|
setDisplayName(info.displayName);
|
||||||
|
BuildTargetInfo bti = target()->applicationTargets().buildTargetInfo(info.buildKey);
|
||||||
|
extraAspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(bti.workingDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
QString CMakeRunConfiguration::defaultDisplayName() const
|
QString CMakeRunConfiguration::defaultDisplayName() const
|
||||||
{
|
{
|
||||||
if (m_title.isEmpty())
|
if (m_title.isEmpty())
|
||||||
@@ -156,10 +146,16 @@ QString CMakeRunConfiguration::defaultDisplayName() const
|
|||||||
return m_title;
|
return m_title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CMakeRunConfiguration::isBuildTargetValid() const
|
||||||
|
{
|
||||||
|
return Utils::anyOf(target()->applicationTargets().list, [this](const BuildTargetInfo &bti) {
|
||||||
|
return bti.targetName == m_buildSystemTarget;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void CMakeRunConfiguration::updateEnabledState()
|
void CMakeRunConfiguration::updateEnabledState()
|
||||||
{
|
{
|
||||||
auto cp = qobject_cast<CMakeProject *>(target()->project());
|
if (!isBuildTargetValid())
|
||||||
if (!cp->hasBuildTarget(m_buildSystemTarget))
|
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
else
|
else
|
||||||
RunConfiguration::updateEnabledState();
|
RunConfiguration::updateEnabledState();
|
||||||
@@ -172,10 +168,7 @@ QWidget *CMakeRunConfiguration::createConfigurationWidget()
|
|||||||
|
|
||||||
QString CMakeRunConfiguration::disabledReason() const
|
QString CMakeRunConfiguration::disabledReason() const
|
||||||
{
|
{
|
||||||
auto cp = qobject_cast<CMakeProject *>(target()->project());
|
if (!isBuildTargetValid())
|
||||||
QTC_ASSERT(cp, return QString());
|
|
||||||
|
|
||||||
if (!cp->hasBuildTarget(m_buildSystemTarget))
|
|
||||||
return tr("The project no longer builds the target associated with this run configuration.");
|
return tr("The project no longer builds the target associated with this run configuration.");
|
||||||
return RunConfiguration::disabledReason();
|
return RunConfiguration::disabledReason();
|
||||||
}
|
}
|
||||||
@@ -235,18 +228,3 @@ CMakeRunConfigurationFactory::CMakeRunConfigurationFactory()
|
|||||||
registerRunConfiguration<CMakeRunConfiguration>(CMAKE_RC_PREFIX);
|
registerRunConfiguration<CMakeRunConfiguration>(CMAKE_RC_PREFIX);
|
||||||
addSupportedProjectType(CMakeProjectManager::Constants::CMAKEPROJECT_ID);
|
addSupportedProjectType(CMakeProjectManager::Constants::CMAKEPROJECT_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<RunConfigurationCreationInfo>
|
|
||||||
CMakeRunConfigurationFactory::availableCreators(Target *parent) const
|
|
||||||
{
|
|
||||||
CMakeProject *project = qobject_cast<CMakeProject *>(parent->project());
|
|
||||||
QTC_ASSERT(project, return {});
|
|
||||||
const QStringList titles = project->buildTargetTitles(true);
|
|
||||||
return Utils::transform(titles, [this](const QString &title) { return convert(title, title); });
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CMakeRunConfigurationFactory::canCreateHelper(Target *parent, const QString &buildTarget) const
|
|
||||||
{
|
|
||||||
CMakeProject *project = static_cast<CMakeProject *>(parent->project());
|
|
||||||
return project->hasBuildTarget(buildTarget);
|
|
||||||
}
|
|
||||||
|
@@ -26,7 +26,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <projectexplorer/runnables.h>
|
#include <projectexplorer/runnables.h>
|
||||||
#include <utils/environment.h>
|
|
||||||
|
|
||||||
namespace CMakeProjectManager {
|
namespace CMakeProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -34,7 +33,6 @@ namespace Internal {
|
|||||||
class CMakeRunConfiguration : public ProjectExplorer::RunConfiguration
|
class CMakeRunConfiguration : public ProjectExplorer::RunConfiguration
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
friend class CMakeRunConfigurationWidget;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CMakeRunConfiguration(ProjectExplorer::Target *target);
|
explicit CMakeRunConfiguration(ProjectExplorer::Target *target);
|
||||||
@@ -56,13 +54,13 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool fromMap(const QVariantMap &map) override;
|
bool fromMap(const QVariantMap &map) override;
|
||||||
|
void doAdditionalSetup(const ProjectExplorer::RunConfigurationCreationInfo &) override;
|
||||||
QString defaultDisplayName() const;
|
QString defaultDisplayName() const;
|
||||||
|
bool isBuildTargetValid() const;
|
||||||
|
|
||||||
void updateEnabledState() final;
|
void updateEnabledState() final;
|
||||||
QString extraId() const final;
|
QString extraId() const final;
|
||||||
|
|
||||||
QString baseWorkingDirectory() const;
|
|
||||||
|
|
||||||
QString m_buildSystemTarget;
|
QString m_buildSystemTarget;
|
||||||
QString m_executable;
|
QString m_executable;
|
||||||
QString m_title;
|
QString m_title;
|
||||||
@@ -82,10 +80,6 @@ class CMakeRunConfigurationFactory : public ProjectExplorer::RunConfigurationFac
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
CMakeRunConfigurationFactory();
|
CMakeRunConfigurationFactory();
|
||||||
|
|
||||||
QList<ProjectExplorer::RunConfigurationCreationInfo>
|
|
||||||
availableCreators(ProjectExplorer::Target *parent) const override;
|
|
||||||
bool canCreateHelper(ProjectExplorer::Target *parent, const QString &suffix) const override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -54,6 +54,7 @@ public:
|
|||||||
|
|
||||||
Utils::FileName targetFilePath;
|
Utils::FileName targetFilePath;
|
||||||
Utils::FileName projectFilePath;
|
Utils::FileName projectFilePath;
|
||||||
|
Utils::FileName workingDirectory;
|
||||||
bool isQtcRunnable = true;
|
bool isQtcRunnable = true;
|
||||||
bool usesTerminal = false;
|
bool usesTerminal = false;
|
||||||
|
|
||||||
|
@@ -550,7 +550,7 @@ RunConfiguration *RunConfigurationCreationInfo::create(Target *target) const
|
|||||||
QTC_ASSERT(factory->canHandle(target), return nullptr);
|
QTC_ASSERT(factory->canHandle(target), return nullptr);
|
||||||
QTC_ASSERT(id == factory->runConfigurationBaseId(), return nullptr);
|
QTC_ASSERT(id == factory->runConfigurationBaseId(), return nullptr);
|
||||||
|
|
||||||
if (!factory->canCreateHelper(target, extra))
|
if (!factory->canCreateHelper(target, targetName))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
QTC_ASSERT(factory->m_creator, return nullptr);
|
QTC_ASSERT(factory->m_creator, return nullptr);
|
||||||
@@ -560,9 +560,9 @@ RunConfiguration *RunConfigurationCreationInfo::create(Target *target) const
|
|||||||
|
|
||||||
// "FIX" ids by mangling in the extra data (build system target etc)
|
// "FIX" ids by mangling in the extra data (build system target etc)
|
||||||
// for compatibility for the current format used in settings.
|
// for compatibility for the current format used in settings.
|
||||||
if (!extra.isEmpty()) {
|
if (!targetName.isEmpty()) {
|
||||||
QVariantMap data = rc->toMap();
|
QVariantMap data = rc->toMap();
|
||||||
data[ProjectConfiguration::settingsIdKey()] = id.withSuffix(extra).toString();
|
data[ProjectConfiguration::settingsIdKey()] = id.withSuffix(targetName).toString();
|
||||||
rc->fromMap(data);
|
rc->fromMap(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -290,7 +290,7 @@ public:
|
|||||||
CreationMode creationMode = AlwaysCreate,
|
CreationMode creationMode = AlwaysCreate,
|
||||||
bool useTerminal = false)
|
bool useTerminal = false)
|
||||||
: factory(factory), id(id),
|
: factory(factory), id(id),
|
||||||
extra(extra),
|
targetName(extra),
|
||||||
displayName(displayName),
|
displayName(displayName),
|
||||||
creationMode(creationMode),
|
creationMode(creationMode),
|
||||||
useTerminal(useTerminal)
|
useTerminal(useTerminal)
|
||||||
@@ -300,7 +300,7 @@ public:
|
|||||||
|
|
||||||
const RunConfigurationFactory *factory = nullptr;
|
const RunConfigurationFactory *factory = nullptr;
|
||||||
Core::Id id;
|
Core::Id id;
|
||||||
QString extra;
|
QString targetName;
|
||||||
QString displayName;
|
QString displayName;
|
||||||
QString buildKey;
|
QString buildKey;
|
||||||
CreationMode creationMode = AlwaysCreate;
|
CreationMode creationMode = AlwaysCreate;
|
||||||
|
@@ -564,7 +564,7 @@ void Target::updateDefaultRunConfigurations()
|
|||||||
bool present = false;
|
bool present = false;
|
||||||
for (const RunConfigurationCreationInfo &item : creators) {
|
for (const RunConfigurationCreationInfo &item : creators) {
|
||||||
QString rcExtraId = rc->extraId();
|
QString rcExtraId = rc->extraId();
|
||||||
if (item.id == rc->id() && (item.extra == rcExtraId || item.buildKey == rcExtraId)) {
|
if (item.id == rc->id() && (item.targetName == rcExtraId || item.buildKey == rcExtraId)) {
|
||||||
existing.append(item);
|
existing.append(item);
|
||||||
present = true;
|
present = true;
|
||||||
}
|
}
|
||||||
@@ -580,7 +580,7 @@ void Target::updateDefaultRunConfigurations()
|
|||||||
continue;
|
continue;
|
||||||
bool exists = false;
|
bool exists = false;
|
||||||
for (const RunConfigurationCreationInfo &ex : existing) {
|
for (const RunConfigurationCreationInfo &ex : existing) {
|
||||||
if (ex.id == item.id && ex.extra == item.extra)
|
if (ex.id == item.id && ex.targetName == item.targetName)
|
||||||
exists = true;
|
exists = true;
|
||||||
}
|
}
|
||||||
if (exists)
|
if (exists)
|
||||||
|
@@ -204,7 +204,7 @@ void PythonRunConfiguration::doAdditionalSetup(const RunConfigurationCreationInf
|
|||||||
Environment sysEnv = Environment::systemEnvironment();
|
Environment sysEnv = Environment::systemEnvironment();
|
||||||
const QString exec = sysEnv.searchInPath("python").toString();
|
const QString exec = sysEnv.searchInPath("python").toString();
|
||||||
m_interpreter = exec.isEmpty() ? "python" : exec;
|
m_interpreter = exec.isEmpty() ? "python" : exec;
|
||||||
m_mainScript = info.extra;
|
m_mainScript = info.targetName;
|
||||||
setDefaultDisplayName(defaultDisplayName());
|
setDefaultDisplayName(defaultDisplayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user