ProjectExplorer: Use a functor for BuildSystem creation

... instead of creating the BuildSystem direct. This will help the
shift of BuildSystem owner ship as a Project will have potentially
multiple BuildSystem instances (one per BuildConfiguration), but
still be responsible for creating them with the Targets.

Change-Id: I2dd71c7687ed41af9e42c874b3f932ce704e7ee3
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2019-10-23 08:47:05 +02:00
parent 5b815d22a3
commit 6a878c7293
16 changed files with 34 additions and 33 deletions
@@ -50,7 +50,7 @@ AutotoolsProject::AutotoolsProject(const Utils::FilePath &fileName)
setHasMakeInstallEquivalent(true);
setBuildSystem(std::make_unique<AutotoolsBuildSystem>(this));
setBuildSystemCreator([](Project *p) { return new AutotoolsBuildSystem(p); });
}
class AutotoolsProjectPluginPrivate
@@ -57,8 +57,8 @@ Q_LOGGING_CATEGORY(cmakeBuildSystemLog, "qtc.cmake.buildsystem", QtWarningMsg);
// CMakeBuildSystem:
// --------------------------------------------------------------------
CMakeBuildSystem::CMakeBuildSystem(CMakeProject *p)
: BuildSystem(p)
CMakeBuildSystem::CMakeBuildSystem(Project *project)
: BuildSystem(project)
, m_cppCodeModelUpdater(new CppTools::CppProjectUpdater)
{
// TreeScanner:
@@ -67,9 +67,9 @@ CMakeBuildSystem::CMakeBuildSystem(CMakeProject *p)
this,
&CMakeBuildSystem::handleTreeScanningFinished);
m_treeScanner.setFilter([this, p](const Utils::MimeType &mimeType, const Utils::FilePath &fn) {
m_treeScanner.setFilter([this](const MimeType &mimeType, const FilePath &fn) {
// Mime checks requires more resources, so keep it last in check list
auto isIgnored = fn.toString().startsWith(p->projectFilePath().toString() + ".user")
auto isIgnored = fn.toString().startsWith(projectFilePath().toString() + ".user")
|| TreeScanner::isWellKnownBinary(mimeType, fn);
// Cache mime check result for speed up
@@ -48,7 +48,7 @@ class CMakeBuildSystem : public ProjectExplorer::BuildSystem
Q_OBJECT
public:
explicit CMakeBuildSystem(CMakeProject *project);
explicit CMakeBuildSystem(ProjectExplorer::Project *project);
~CMakeBuildSystem() final;
protected:
@@ -91,7 +91,7 @@ CMakeProject::CMakeProject(const FilePath &fileName)
setKnowsAllBuildExecutables(false);
setHasMakeInstallEquivalent(true);
setBuildSystem(std::make_unique<CMakeBuildSystem>(this));
setBuildSystemCreator([](Project *p) { return new CMakeBuildSystem(p); });
}
CMakeProject::~CMakeProject() = default;
@@ -122,7 +122,7 @@ private:
class GenericBuildSytem : public BuildSystem
{
public:
explicit GenericBuildSytem(GenericProject *project)
explicit GenericBuildSytem(Project *project)
: BuildSystem(project)
{}
@@ -176,7 +176,7 @@ GenericProject::GenericProject(const Utils::FilePath &fileName)
setId(Constants::GENERICPROJECT_ID);
setProjectLanguages(Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
setDisplayName(fileName.toFileInfo().completeBaseName());
setBuildSystem(std::make_unique<GenericBuildSytem>(this));
setBuildSystemCreator([](Project *p) { return new GenericBuildSytem(p); });
QObject *projectUpdaterFactory = ExtensionSystem::PluginManager::getObjectByName(
"CppProjectUpdaterFactory");
+1 -1
View File
@@ -45,7 +45,7 @@ NimProject::NimProject(const FilePath &fileName) : Project(Constants::C_NIM_MIME
// ensure debugging is enabled (Nim plugin translates nim code to C code)
setProjectLanguages(Core::Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
setBuildSystem(std::make_unique<NimBuildSystem>(this));
setBuildSystemCreator([](Project *p) { return new NimBuildSystem(p); });
}
Tasks NimProject::projectIssues(const Kit *k) const
+2 -3
View File
@@ -888,10 +888,9 @@ Utils::Environment Project::activeParseEnvironment() const
return result;
}
void Project::setBuildSystem(std::unique_ptr<BuildSystem> &&bs)
void Project::setBuildSystemCreator(const std::function<BuildSystem *(Project *)> &creator)
{
QTC_ASSERT(!bs->parent(), bs->setParent(nullptr));
d->m_buildSystem = std::move(bs);
d->m_buildSystem.reset(creator(this));
}
Core::Context Project::projectContext() const
+1 -1
View File
@@ -310,7 +310,7 @@ protected:
static ProjectExplorer::Task createProjectTask(ProjectExplorer::Task::TaskType type,
const QString &description);
void setBuildSystem(std::unique_ptr<BuildSystem> &&bs); // takes ownership!
void setBuildSystemCreator(const std::function<BuildSystem *(Project *)> &creator);
private:
// Helper methods to manage parsing state and signalling
+4 -4
View File
@@ -57,7 +57,7 @@ namespace Internal {
class PythonBuildSystem : public BuildSystem
{
public:
PythonBuildSystem(PythonProject *project);
explicit PythonBuildSystem(Project *project);
bool supportsAction(Node *context, ProjectAction action, const Node *node) const override;
bool addFiles(Node *, const QStringList &filePaths, QStringList *) override;
@@ -191,7 +191,7 @@ PythonProject::PythonProject(const FilePath &fileName)
setDisplayName(fileName.toFileInfo().completeBaseName());
setNeedsBuildConfigurations(false);
setBuildSystem(std::make_unique<PythonBuildSystem>(this));
setBuildSystemCreator([](Project *p) { return new PythonBuildSystem(p); });
}
void PythonBuildSystem::refresh()
@@ -433,10 +433,10 @@ bool PythonProject::setupTarget(Target *t)
return res;
}
PythonBuildSystem::PythonBuildSystem(PythonProject *project)
PythonBuildSystem::PythonBuildSystem(Project *project)
: BuildSystem(project)
{
connect(project, &PythonProject::projectFileIsDirty, this, [this]() { refresh(); });
connect(project, &Project::projectFileIsDirty, this, [this]() { refresh(); });
QTimer::singleShot(0, this, &PythonBuildSystem::refresh);
}
+9 -4
View File
@@ -365,8 +365,8 @@ QbsRootProjectNode::QbsRootProjectNode(QbsProject *project) :
// QbsBuildSystem:
// --------------------------------------------------------------------
QbsBuildSystem::QbsBuildSystem(QbsProject *project)
: BuildSystem(project), m_project(project)
QbsBuildSystem::QbsBuildSystem(Project *project)
: BuildSystem(project)
{
}
@@ -449,7 +449,7 @@ RemovedFilesFromProject QbsBuildSystem::removeFiles(Node *context, const QString
return RemovedFilesFromProject::Error;
}
return m_project->removeFilesFromProduct(filePaths, prdNode->qbsProductData(),
return project()->removeFilesFromProduct(filePaths, prdNode->qbsProductData(),
n->m_qbsGroupData, notRemoved);
}
@@ -486,7 +486,7 @@ bool QbsBuildSystem::renameFile(Node *context, const QString &filePath, const QS
if (!prdNode || !prdNode->qbsProductData().isValid())
return false;
return m_project->renameFileInProduct(filePath, newFilePath,
return project()->renameFileInProduct(filePath, newFilePath,
prdNode->qbsProductData(), n->m_qbsGroupData);
}
@@ -502,5 +502,10 @@ bool QbsBuildSystem::renameFile(Node *context, const QString &filePath, const QS
return BuildSystem::renameFile(context, filePath, newFilePath);
}
QbsProject *QbsBuildSystem::project() const
{
return static_cast<QbsProject *>(BuildSystem::project());
}
} // namespace Internal
} // namespace QbsProjectManager
+2 -3
View File
@@ -39,7 +39,7 @@ class QbsProject;
class QbsBuildSystem : public ProjectExplorer::BuildSystem
{
public:
explicit QbsBuildSystem(QbsProject *project);
explicit QbsBuildSystem(ProjectExplorer::Project *project);
bool supportsAction(ProjectExplorer::Node *context,
ProjectExplorer::ProjectAction action,
@@ -53,8 +53,7 @@ public:
bool renameFile(ProjectExplorer::Node *context,
const QString &filePath, const QString &newFilePath) override;
private:
QbsProject *m_project = nullptr;
QbsProject *project() const;
};
// --------------------------------------------------------------------
+1 -1
View File
@@ -135,7 +135,7 @@ QbsProject::QbsProject(const FilePath &fileName)
setProjectLanguages(Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
setCanBuildProducts();
setBuildSystem(std::make_unique<QbsBuildSystem>(this));
setBuildSystemCreator([](Project *p) { return new QbsBuildSystem(p); });
rebuildProjectTree();
@@ -500,8 +500,8 @@ TargetInformation QmakeProFileNode::targetInformation() const
return proFile() ? proFile()->targetInformation() : TargetInformation();
}
QmakeBuildSystem::QmakeBuildSystem(QmakeProject *project)
: BuildSystem(project), m_project(project)
QmakeBuildSystem::QmakeBuildSystem(Project *project)
: BuildSystem(project)
{
}
+1 -3
View File
@@ -40,7 +40,7 @@ class QmakeProject;
class QmakeBuildSystem : public ProjectExplorer::BuildSystem
{
public:
explicit QmakeBuildSystem(QmakeProject *project);
explicit QmakeBuildSystem(ProjectExplorer::Project *project);
bool supportsAction(ProjectExplorer::Node *context,
ProjectExplorer::ProjectAction action,
@@ -60,8 +60,6 @@ public:
const QString &filePath, const QString &newFilePath) override;
bool addDependencies(ProjectExplorer::Node *context,
const QStringList &dependencies) override;
private:
QmakeProject *m_project = nullptr;
};
// Implements ProjectNode for qmake .pri files
@@ -145,7 +145,7 @@ QmakeProject::QmakeProject(const FilePath &fileName) :
this, &QmakeProject::buildFinished);
setPreferredKitPredicate([this](const Kit *kit) -> bool { return matchesKit(kit); });
setBuildSystem(std::make_unique<QmakeBuildSystem>(this));
setBuildSystemCreator([](Project *p) { return new QmakeBuildSystem(p); });
}
QmakeProject::~QmakeProject()
+1 -1
View File
@@ -67,7 +67,7 @@ QmlProject::QmlProject(const Utils::FilePath &fileName)
setDisplayName(fileName.toFileInfo().completeBaseName());
setNeedsBuildConfigurations(false);
setBuildSystem(std::make_unique<Internal::QmlBuildSystem>(this));
setBuildSystemCreator([](Project *p) { return new Internal::QmlBuildSystem(p); });
connect(this, &QmlProject::projectFileIsDirty, this, &QmlProject::refreshProjectFile);
}