diff --git a/src/plugins/qmakeprojectmanager/qmakenodes.cpp b/src/plugins/qmakeprojectmanager/qmakenodes.cpp index 84b9595a038..557ded347a6 100644 --- a/src/plugins/qmakeprojectmanager/qmakenodes.cpp +++ b/src/plugins/qmakeprojectmanager/qmakenodes.cpp @@ -26,7 +26,6 @@ #include "qmakenodes.h" #include "qmakeproject.h" -#include "qmakeprojectmanagerplugin.h" #include #include @@ -343,7 +342,7 @@ bool QmakeProFileNode::validParse() const void QmakeProFileNode::build() { - QmakeProjectManagerPlugin::buildProduct(getProject(), this); + m_buildSystem->buildHelper(QmakeBuildSystem::BUILD, false, this, nullptr); } QStringList QmakeProFileNode::targetApplications() const diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.cpp b/src/plugins/qmakeprojectmanager/qmakeproject.cpp index 3c4ab4da532..be48fe27520 100644 --- a/src/plugins/qmakeprojectmanager/qmakeproject.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeproject.cpp @@ -1358,6 +1358,34 @@ QVariant QmakeBuildSystem::additionalData(Core::Id id) const return BuildSystem::additionalData(id); } +void QmakeBuildSystem::buildHelper(Action action, bool isFileBuild, QmakeProFileNode *profile, + FileNode *buildableFile) +{ + auto bc = qmakeBuildConfiguration(); + + if (!profile || !buildableFile) + isFileBuild = false; + + if (profile) { + if (profile != project()->rootProjectNode() || isFileBuild) + bc->setSubNodeBuild(profile->proFileNode()); + } + + if (isFileBuild) + bc->setFileNodeBuild(buildableFile); + if (ProjectExplorerPlugin::saveModifiedFiles()) { + if (action == BUILD) + BuildManager::buildList(bc->buildSteps()); + else if (action == CLEAN) + BuildManager::buildList(bc->cleanSteps()); + else if (action == REBUILD) + BuildManager::buildLists({bc->cleanSteps(), bc->buildSteps()}); + } + + bc->setSubNodeBuild(nullptr); + bc->setFileNodeBuild(nullptr); +} + } // QmakeProjectManager #include "qmakeproject.moc" diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.h b/src/plugins/qmakeprojectmanager/qmakeproject.h index 1ac2cc73206..8496c9720b2 100644 --- a/src/plugins/qmakeprojectmanager/qmakeproject.h +++ b/src/plugins/qmakeprojectmanager/qmakeproject.h @@ -168,6 +168,11 @@ public: void notifyChanged(const Utils::FilePath &name); + enum Action { BUILD, REBUILD, CLEAN }; + void buildHelper(Action action, bool isFileBuild, + QmakeProFileNode *profile, + ProjectExplorer::FileNode *buildableFile); + public: void scheduleUpdateAll(QmakeProFile::AsyncUpdateDelay delay); void scheduleUpdateAllLater() { scheduleUpdateAll(QmakeProFile::ParseLater); } diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp index 35862044dce..7a896d4999f 100644 --- a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp @@ -126,23 +126,18 @@ public: QmakeKitAspect qmakeKitAspect; - enum Action { BUILD, REBUILD, CLEAN }; - void addLibrary(); void addLibraryContextMenu(); void runQMake(); void runQMakeContextMenu(); - void buildSubDirContextMenu(); - void rebuildSubDirContextMenu(); - void cleanSubDirContextMenu(); - void buildFileContextMenu(); + + void buildSubDirContextMenu() { handleSubDirContextMenu(QmakeBuildSystem::BUILD, false); } + void rebuildSubDirContextMenu() { handleSubDirContextMenu(QmakeBuildSystem::REBUILD, false); } + void cleanSubDirContextMenu() { handleSubDirContextMenu(QmakeBuildSystem::CLEAN, false); } + void buildFileContextMenu() { handleSubDirContextMenu(QmakeBuildSystem::BUILD, true); } void buildFile(); - void handleSubDirContextMenu(Action action, bool isFileBuild); - static void handleSubDirContextMenu(Action action, bool isFileBuild, - Project *contextProject, - QmakeProFileNode *profile, - FileNode *buildableFile); + void handleSubDirContextMenu(QmakeBuildSystem::Action action, bool isFileBuild); void addLibraryImpl(const QString &fileName, TextEditor::BaseTextEditor *editor); void runQMakeImpl(Project *p, ProjectExplorer::Node *node); }; @@ -444,98 +439,39 @@ void QmakeProjectManagerPluginPrivate::runQMakeImpl(Project *p, Node *node) bc->setSubNodeBuild(nullptr); } -void QmakeProjectManagerPluginPrivate::buildSubDirContextMenu() -{ - handleSubDirContextMenu(BUILD, false); -} - -void QmakeProjectManagerPluginPrivate::cleanSubDirContextMenu() -{ - handleSubDirContextMenu(CLEAN, false); -} - -void QmakeProjectManagerPluginPrivate::rebuildSubDirContextMenu() -{ - handleSubDirContextMenu(REBUILD, false); -} - -void QmakeProjectManagerPluginPrivate::buildFileContextMenu() -{ - handleSubDirContextMenu(BUILD, true); -} - void QmakeProjectManagerPluginPrivate::buildFile() { - if (Core::IDocument *currentDocument= Core::EditorManager::currentDocument()) { - const Utils::FilePath file = currentDocument->filePath(); - Node *n = ProjectTree::nodeForFile(file); - FileNode *node = n ? n->asFileNode() : nullptr; - Project *project = SessionManager::projectForFile(file); + Core::IDocument *currentDocument = Core::EditorManager::currentDocument(); + if (!currentDocument) + return; - if (project && node) - handleSubDirContextMenu(BUILD, true, project, buildableFileProFile(node), node); - } + const Utils::FilePath file = currentDocument->filePath(); + Node *n = ProjectTree::nodeForFile(file); + FileNode *node = n ? n->asFileNode() : nullptr; + if (!node) + return; + Project *project = SessionManager::projectForFile(file); + if (!project) + return; + Target *target = project->activeTarget(); + if (!target) + return; + + if (auto bs = qobject_cast(target->buildSystem())) + bs->buildHelper(QmakeBuildSystem::BUILD, true, buildableFileProFile(node), node); } -void QmakeProjectManagerPlugin::buildProduct(Project *project, QmakeProFileNode *proFileNode) -{ - QmakeProjectManagerPluginPrivate::handleSubDirContextMenu( - QmakeProjectManagerPluginPrivate::BUILD, false, project, proFileNode, nullptr); -} - -void QmakeProjectManagerPluginPrivate::handleSubDirContextMenu(Action action, bool isFileBuild) +void QmakeProjectManagerPluginPrivate::handleSubDirContextMenu(QmakeBuildSystem::Action action, bool isFileBuild) { Node *node = ProjectTree::currentNode(); QmakeProFileNode *subProjectNode = buildableFileProFile(node); FileNode *fileNode = node ? node->asFileNode() : nullptr; bool buildFilePossible = subProjectNode && fileNode && fileNode->fileType() == FileType::Source; - FileNode *buildableFileNode = buildFilePossible ? fileNode : nullptr; - handleSubDirContextMenu(action, - isFileBuild, - ProjectTree::currentProject(), - buildableFileProFile(ProjectTree::currentNode()), - buildableFileNode); -} - -void QmakeProjectManagerPluginPrivate::handleSubDirContextMenu(Action action, - bool isFileBuild, - Project *contextProject, - QmakeProFileNode *profile, - FileNode *buildableFile) -{ - QTC_ASSERT(contextProject, return); - Target *target = contextProject->activeTarget(); - if (!target) - return; - - auto *bc = qobject_cast(target->activeBuildConfiguration()); - if (!bc) - return; - - if (!profile || !buildableFile) - isFileBuild = false; - - if (profile) { - if (profile != contextProject->rootProjectNode() || isFileBuild) - bc->setSubNodeBuild(profile->proFileNode()); - } - - if (isFileBuild) - bc->setFileNodeBuild(buildableFile); - if (ProjectExplorerPlugin::saveModifiedFiles()) { - if (action == BUILD) - BuildManager::buildList(bc->buildSteps()); - else if (action == CLEAN) - BuildManager::buildList(bc->cleanSteps()); - else if (action == REBUILD) - BuildManager::buildLists({bc->cleanSteps(), bc->buildSteps()}); - } - - bc->setSubNodeBuild(nullptr); - bc->setFileNodeBuild(nullptr); + if (auto bs = qobject_cast(ProjectTree::currentBuildSystem())) + bs->buildHelper(action, isFileBuild, subProjectNode, buildableFileNode); } void QmakeProjectManagerPluginPrivate::activeTargetChanged() diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.h b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.h index 9cab4ae8495..68255197dd0 100644 --- a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.h +++ b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.h @@ -43,8 +43,6 @@ class QmakeProjectManagerPlugin final : public ExtensionSystem::IPlugin public: ~QmakeProjectManagerPlugin() final; - static void buildProduct(ProjectExplorer::Project *project, QmakeProFileNode *proFileNode); - #ifdef WITH_TESTS private slots: void testQmakeOutputParsers_data();