forked from qt-creator/qt-creator
ProjectExplorer: Add convenience Project::addTargetFor{Default,}Kit
Less noise on the user side. Change-Id: I5cdf4af4910a3cc1ee0af1b43fcbc7329a6d59db Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -34,7 +34,6 @@
|
|||||||
|
|
||||||
#include <projectexplorer/abi.h>
|
#include <projectexplorer/abi.h>
|
||||||
#include <projectexplorer/toolchain.h>
|
#include <projectexplorer/toolchain.h>
|
||||||
#include <projectexplorer/kitmanager.h>
|
|
||||||
#include <projectexplorer/kitinformation.h>
|
#include <projectexplorer/kitinformation.h>
|
||||||
#include <projectexplorer/buildconfiguration.h>
|
#include <projectexplorer/buildconfiguration.h>
|
||||||
#include <projectexplorer/buildsteplist.h>
|
#include <projectexplorer/buildsteplist.h>
|
||||||
@@ -105,9 +104,8 @@ Project::RestoreResult AutotoolsProject::fromMap(const QVariantMap &map, QString
|
|||||||
// Load the project tree structure.
|
// Load the project tree structure.
|
||||||
loadProjectTree();
|
loadProjectTree();
|
||||||
|
|
||||||
Kit *defaultKit = KitManager::defaultKit();
|
if (!activeTarget())
|
||||||
if (!activeTarget() && defaultKit)
|
addTargetForDefaultKit();
|
||||||
addTarget(createTarget(defaultKit));
|
|
||||||
|
|
||||||
return RestoreResult::Ok;
|
return RestoreResult::Ok;
|
||||||
}
|
}
|
||||||
|
@@ -405,7 +405,7 @@ CompilationDatabaseProject::CompilationDatabaseProject(const Utils::FilePath &pr
|
|||||||
setPreferredKitPredicate([](const Kit *) { return false; });
|
setPreferredKitPredicate([](const Kit *) { return false; });
|
||||||
|
|
||||||
m_kit.reset(KitManager::defaultKit()->clone());
|
m_kit.reset(KitManager::defaultKit()->clone());
|
||||||
addTarget(createTarget(m_kit.get()));
|
addTargetForKit(m_kit.get());
|
||||||
|
|
||||||
connect(this, &CompilationDatabaseProject::rootProjectDirectoryChanged,
|
connect(this, &CompilationDatabaseProject::rootProjectDirectoryChanged,
|
||||||
m_parseDelay, QOverload<>::of(&QTimer::start));
|
m_parseDelay, QOverload<>::of(&QTimer::start));
|
||||||
|
@@ -45,7 +45,6 @@
|
|||||||
#include <projectexplorer/deploymentdata.h>
|
#include <projectexplorer/deploymentdata.h>
|
||||||
#include <projectexplorer/headerpath.h>
|
#include <projectexplorer/headerpath.h>
|
||||||
#include <projectexplorer/kitinformation.h>
|
#include <projectexplorer/kitinformation.h>
|
||||||
#include <projectexplorer/kitmanager.h>
|
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
#include <projectexplorer/projectexplorerconstants.h>
|
||||||
#include <projectexplorer/projectnodes.h>
|
#include <projectexplorer/projectnodes.h>
|
||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
@@ -562,9 +561,8 @@ Project::RestoreResult GenericProject::fromMap(const QVariantMap &map, QString *
|
|||||||
if (result != RestoreResult::Ok)
|
if (result != RestoreResult::Ok)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
Kit *defaultKit = KitManager::defaultKit();
|
if (!activeTarget())
|
||||||
if (!activeTarget() && defaultKit)
|
addTargetForDefaultKit();
|
||||||
addTarget(createTarget(defaultKit));
|
|
||||||
|
|
||||||
// Sanity check: We need both a buildconfiguration and a runconfiguration!
|
// Sanity check: We need both a buildconfiguration and a runconfiguration!
|
||||||
const QList<Target *> targetList = targets();
|
const QList<Target *> targetList = targets();
|
||||||
|
@@ -267,6 +267,27 @@ void Project::addTarget(std::unique_ptr<Target> &&t)
|
|||||||
SessionManager::setActiveTarget(this, pointer, SetActive::Cascade);
|
SessionManager::setActiveTarget(this, pointer, SetActive::Cascade);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Target *Project::addTargetForDefaultKit()
|
||||||
|
{
|
||||||
|
return addTargetForKit(KitManager::defaultKit());
|
||||||
|
}
|
||||||
|
|
||||||
|
Target *Project::addTargetForKit(Kit *kit)
|
||||||
|
{
|
||||||
|
if (!kit || target(kit))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto t = std::make_unique<Target>(this, kit, Target::_constructor_tag{});
|
||||||
|
Target *pointer = t.get();
|
||||||
|
|
||||||
|
if (!setupTarget(pointer))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
addTarget(std::move(t));
|
||||||
|
|
||||||
|
return pointer;
|
||||||
|
}
|
||||||
|
|
||||||
bool Project::removeTarget(Target *target)
|
bool Project::removeTarget(Target *target)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(target && Utils::contains(d->m_targets, target), return false);
|
QTC_ASSERT(target && Utils::contains(d->m_targets, target), return false);
|
||||||
@@ -336,17 +357,6 @@ Tasks Project::projectIssues(const Kit *k) const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Target> Project::createTarget(Kit *k)
|
|
||||||
{
|
|
||||||
if (!k || target(k))
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
auto t = std::make_unique<Target>(this, k, Target::_constructor_tag{});
|
|
||||||
if (!setupTarget(t.get()))
|
|
||||||
return {};
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Project::copySteps(Target *sourceTarget, Target *newTarget)
|
bool Project::copySteps(Target *sourceTarget, Target *newTarget)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(newTarget, return false);
|
QTC_ASSERT(newTarget, return false);
|
||||||
|
@@ -122,7 +122,8 @@ public:
|
|||||||
EditorConfiguration *editorConfiguration() const;
|
EditorConfiguration *editorConfiguration() const;
|
||||||
|
|
||||||
// Target:
|
// Target:
|
||||||
void addTarget(std::unique_ptr<Target> &&target);
|
Target *addTargetForDefaultKit();
|
||||||
|
Target *addTargetForKit(Kit *kit);
|
||||||
bool removeTarget(Target *target);
|
bool removeTarget(Target *target);
|
||||||
|
|
||||||
QList<Target *> targets() const;
|
QList<Target *> targets() const;
|
||||||
@@ -132,7 +133,6 @@ public:
|
|||||||
Target *target(Kit *k) const;
|
Target *target(Kit *k) const;
|
||||||
virtual Tasks projectIssues(const Kit *k) const;
|
virtual Tasks projectIssues(const Kit *k) const;
|
||||||
|
|
||||||
std::unique_ptr<Target> createTarget(Kit *k);
|
|
||||||
static bool copySteps(Target *sourceTarget, Target *newTarget);
|
static bool copySteps(Target *sourceTarget, Target *newTarget);
|
||||||
|
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
@@ -268,6 +268,8 @@ protected:
|
|||||||
Utils::Environment activeBuildEnvironment() const;
|
Utils::Environment activeBuildEnvironment() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void addTarget(std::unique_ptr<Target> &&target);
|
||||||
|
|
||||||
void handleSubTreeChanged(FolderNode *node);
|
void handleSubTreeChanged(FolderNode *node);
|
||||||
void setActiveTarget(Target *target);
|
void setActiveTarget(Target *target);
|
||||||
ProjectPrivate *d;
|
ProjectPrivate *d;
|
||||||
|
@@ -552,12 +552,8 @@ public:
|
|||||||
BuildConfiguration *lastBc = nullptr;
|
BuildConfiguration *lastBc = nullptr;
|
||||||
for (const BuildInfo &info : projectImporter->import(path, false)) {
|
for (const BuildInfo &info : projectImporter->import(path, false)) {
|
||||||
Target *target = project->target(info.kitId);
|
Target *target = project->target(info.kitId);
|
||||||
if (!target) {
|
if (!target)
|
||||||
std::unique_ptr<Target> newTarget = project->createTarget(KitManager::kit(info.kitId));
|
target = project->addTargetForKit(KitManager::kit(info.kitId));
|
||||||
target = newTarget.get();
|
|
||||||
if (newTarget)
|
|
||||||
project->addTarget(std::move(newTarget));
|
|
||||||
}
|
|
||||||
if (target) {
|
if (target) {
|
||||||
projectImporter->makePersistent(target->kit());
|
projectImporter->makePersistent(target->kit());
|
||||||
BuildConfiguration *bc = info.factory()->create(target, info);
|
BuildConfiguration *bc = info.factory()->create(target, info);
|
||||||
|
@@ -407,8 +407,7 @@ public:
|
|||||||
QTC_ASSERT(!data.isValid(), return false);
|
QTC_ASSERT(!data.isValid(), return false);
|
||||||
if (!isEnabled()) {
|
if (!isEnabled()) {
|
||||||
m_currentChild = DefaultPage;
|
m_currentChild = DefaultPage;
|
||||||
Kit *k = KitManager::kit(m_kitId);
|
m_project->addTargetForKit(KitManager::kit(m_kitId));
|
||||||
m_project->addTarget(m_project->createTarget(k));
|
|
||||||
} else {
|
} else {
|
||||||
// Go to Run page, when on Run previously etc.
|
// Go to Run page, when on Run previously etc.
|
||||||
TargetItem *previousItem = parent()->currentTargetItem();
|
TargetItem *previousItem = parent()->currentTargetItem();
|
||||||
@@ -450,7 +449,7 @@ public:
|
|||||||
QAction *enableAction = menu->addAction(tr("Enable Kit \"%1\" for Project \"%2\"").arg(kitName, projectName));
|
QAction *enableAction = menu->addAction(tr("Enable Kit \"%1\" for Project \"%2\"").arg(kitName, projectName));
|
||||||
enableAction->setEnabled(isSelectable && m_kitId.isValid() && !isEnabled());
|
enableAction->setEnabled(isSelectable && m_kitId.isValid() && !isEnabled());
|
||||||
QObject::connect(enableAction, &QAction::triggered, [this, kit] {
|
QObject::connect(enableAction, &QAction::triggered, [this, kit] {
|
||||||
m_project->addTarget(m_project->createTarget(kit));
|
m_project->addTargetForKit(kit);
|
||||||
});
|
});
|
||||||
|
|
||||||
QAction *disableAction = menu->addAction(tr("Disable Kit \"%1\" for Project \"%2\"").arg(kitName, projectName));
|
QAction *disableAction = menu->addAction(tr("Disable Kit \"%1\" for Project \"%2\"").arg(kitName, projectName));
|
||||||
|
@@ -38,7 +38,6 @@
|
|||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
|
||||||
#include <projectexplorer/buildtargetinfo.h>
|
#include <projectexplorer/buildtargetinfo.h>
|
||||||
#include <projectexplorer/kitmanager.h>
|
|
||||||
#include <projectexplorer/localenvironmentaspect.h>
|
#include <projectexplorer/localenvironmentaspect.h>
|
||||||
#include <projectexplorer/runcontrol.h>
|
#include <projectexplorer/runcontrol.h>
|
||||||
#include <projectexplorer/runconfiguration.h>
|
#include <projectexplorer/runconfiguration.h>
|
||||||
@@ -726,9 +725,8 @@ Project::RestoreResult PythonProject::fromMap(const QVariantMap &map, QString *e
|
|||||||
if (res == RestoreResult::Ok) {
|
if (res == RestoreResult::Ok) {
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
Kit *defaultKit = KitManager::defaultKit();
|
if (!activeTarget())
|
||||||
if (!activeTarget() && defaultKit)
|
addTargetForDefaultKit();
|
||||||
addTarget(createTarget(defaultKit));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
@@ -223,13 +223,7 @@ void QmlProfilerDetailsRewriterTest::seedRewriter()
|
|||||||
DummyProject *project = new DummyProject(Utils::FilePath::fromString(filename));
|
DummyProject *project = new DummyProject(Utils::FilePath::fromString(filename));
|
||||||
ProjectExplorer::SessionManager::addProject(project);
|
ProjectExplorer::SessionManager::addProject(project);
|
||||||
|
|
||||||
{
|
m_rewriter.populateFileFinder(project->addTargetForKit(kit.get()));
|
||||||
// Make sure the uniqe_ptr gets deleted before the project.
|
|
||||||
// Otherwise we'll get a double free because the target is also parented to the project
|
|
||||||
// and unique_ptr doesn't know anything about QObject parent/child relationships.
|
|
||||||
std::unique_ptr<ProjectExplorer::Target> target = project->createTarget(kit.get());
|
|
||||||
m_rewriter.populateFileFinder(target.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
ProjectExplorer::SessionManager::removeProject(project);
|
ProjectExplorer::SessionManager::removeProject(project);
|
||||||
}
|
}
|
||||||
|
@@ -341,8 +341,10 @@ Project::RestoreResult QmlProject::fromMap(const QVariantMap &map, QString *erro
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!kits.isEmpty()) {
|
if (!kits.isEmpty()) {
|
||||||
Kit *kit = kits.contains(KitManager::defaultKit()) ? KitManager::defaultKit() : kits.first();
|
if (kits.contains(KitManager::defaultKit()))
|
||||||
addTarget(createTarget(kit));
|
addTargetForDefaultKit();
|
||||||
|
else
|
||||||
|
addTargetForKit(kits.first());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user