Qmake: Move context build action handling to build system

Among others, this removes the wart introduced in 4d3d2d0dfb.

Change-Id: Iafa63f6e4cca327a1d1dd6a8bbcfaa10032327db
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2020-03-20 15:56:43 +01:00
parent 1194340b85
commit 2444595fbc
5 changed files with 60 additions and 94 deletions

View File

@@ -26,7 +26,6 @@
#include "qmakenodes.h" #include "qmakenodes.h"
#include "qmakeproject.h" #include "qmakeproject.h"
#include "qmakeprojectmanagerplugin.h"
#include <projectexplorer/buildconfiguration.h> #include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/runconfiguration.h> #include <projectexplorer/runconfiguration.h>
@@ -343,7 +342,7 @@ bool QmakeProFileNode::validParse() const
void QmakeProFileNode::build() void QmakeProFileNode::build()
{ {
QmakeProjectManagerPlugin::buildProduct(getProject(), this); m_buildSystem->buildHelper(QmakeBuildSystem::BUILD, false, this, nullptr);
} }
QStringList QmakeProFileNode::targetApplications() const QStringList QmakeProFileNode::targetApplications() const

View File

@@ -1358,6 +1358,34 @@ QVariant QmakeBuildSystem::additionalData(Core::Id id) const
return BuildSystem::additionalData(id); 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 } // QmakeProjectManager
#include "qmakeproject.moc" #include "qmakeproject.moc"

View File

@@ -168,6 +168,11 @@ public:
void notifyChanged(const Utils::FilePath &name); void notifyChanged(const Utils::FilePath &name);
enum Action { BUILD, REBUILD, CLEAN };
void buildHelper(Action action, bool isFileBuild,
QmakeProFileNode *profile,
ProjectExplorer::FileNode *buildableFile);
public: public:
void scheduleUpdateAll(QmakeProFile::AsyncUpdateDelay delay); void scheduleUpdateAll(QmakeProFile::AsyncUpdateDelay delay);
void scheduleUpdateAllLater() { scheduleUpdateAll(QmakeProFile::ParseLater); } void scheduleUpdateAllLater() { scheduleUpdateAll(QmakeProFile::ParseLater); }

View File

@@ -126,23 +126,18 @@ public:
QmakeKitAspect qmakeKitAspect; QmakeKitAspect qmakeKitAspect;
enum Action { BUILD, REBUILD, CLEAN };
void addLibrary(); void addLibrary();
void addLibraryContextMenu(); void addLibraryContextMenu();
void runQMake(); void runQMake();
void runQMakeContextMenu(); void runQMakeContextMenu();
void buildSubDirContextMenu();
void rebuildSubDirContextMenu(); void buildSubDirContextMenu() { handleSubDirContextMenu(QmakeBuildSystem::BUILD, false); }
void cleanSubDirContextMenu(); void rebuildSubDirContextMenu() { handleSubDirContextMenu(QmakeBuildSystem::REBUILD, false); }
void buildFileContextMenu(); void cleanSubDirContextMenu() { handleSubDirContextMenu(QmakeBuildSystem::CLEAN, false); }
void buildFileContextMenu() { handleSubDirContextMenu(QmakeBuildSystem::BUILD, true); }
void buildFile(); void buildFile();
void handleSubDirContextMenu(Action action, bool isFileBuild); void handleSubDirContextMenu(QmakeBuildSystem::Action action, bool isFileBuild);
static void handleSubDirContextMenu(Action action, bool isFileBuild,
Project *contextProject,
QmakeProFileNode *profile,
FileNode *buildableFile);
void addLibraryImpl(const QString &fileName, TextEditor::BaseTextEditor *editor); void addLibraryImpl(const QString &fileName, TextEditor::BaseTextEditor *editor);
void runQMakeImpl(Project *p, ProjectExplorer::Node *node); void runQMakeImpl(Project *p, ProjectExplorer::Node *node);
}; };
@@ -444,98 +439,39 @@ void QmakeProjectManagerPluginPrivate::runQMakeImpl(Project *p, Node *node)
bc->setSubNodeBuild(nullptr); 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() void QmakeProjectManagerPluginPrivate::buildFile()
{ {
if (Core::IDocument *currentDocument= Core::EditorManager::currentDocument()) { Core::IDocument *currentDocument = Core::EditorManager::currentDocument();
const Utils::FilePath file = currentDocument->filePath(); if (!currentDocument)
Node *n = ProjectTree::nodeForFile(file); return;
FileNode *node = n ? n->asFileNode() : nullptr;
Project *project = SessionManager::projectForFile(file);
if (project && node) const Utils::FilePath file = currentDocument->filePath();
handleSubDirContextMenu(BUILD, true, project, buildableFileProFile(node), node); 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<QmakeBuildSystem *>(target->buildSystem()))
bs->buildHelper(QmakeBuildSystem::BUILD, true, buildableFileProFile(node), node);
} }
void QmakeProjectManagerPlugin::buildProduct(Project *project, QmakeProFileNode *proFileNode) void QmakeProjectManagerPluginPrivate::handleSubDirContextMenu(QmakeBuildSystem::Action action, bool isFileBuild)
{
QmakeProjectManagerPluginPrivate::handleSubDirContextMenu(
QmakeProjectManagerPluginPrivate::BUILD, false, project, proFileNode, nullptr);
}
void QmakeProjectManagerPluginPrivate::handleSubDirContextMenu(Action action, bool isFileBuild)
{ {
Node *node = ProjectTree::currentNode(); Node *node = ProjectTree::currentNode();
QmakeProFileNode *subProjectNode = buildableFileProFile(node); QmakeProFileNode *subProjectNode = buildableFileProFile(node);
FileNode *fileNode = node ? node->asFileNode() : nullptr; FileNode *fileNode = node ? node->asFileNode() : nullptr;
bool buildFilePossible = subProjectNode && fileNode && fileNode->fileType() == FileType::Source; bool buildFilePossible = subProjectNode && fileNode && fileNode->fileType() == FileType::Source;
FileNode *buildableFileNode = buildFilePossible ? fileNode : nullptr; FileNode *buildableFileNode = buildFilePossible ? fileNode : nullptr;
handleSubDirContextMenu(action, if (auto bs = qobject_cast<QmakeBuildSystem *>(ProjectTree::currentBuildSystem()))
isFileBuild, bs->buildHelper(action, isFileBuild, subProjectNode, buildableFileNode);
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<QmakeBuildConfiguration *>(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);
} }
void QmakeProjectManagerPluginPrivate::activeTargetChanged() void QmakeProjectManagerPluginPrivate::activeTargetChanged()

View File

@@ -43,8 +43,6 @@ class QmakeProjectManagerPlugin final : public ExtensionSystem::IPlugin
public: public:
~QmakeProjectManagerPlugin() final; ~QmakeProjectManagerPlugin() final;
static void buildProduct(ProjectExplorer::Project *project, QmakeProFileNode *proFileNode);
#ifdef WITH_TESTS #ifdef WITH_TESTS
private slots: private slots:
void testQmakeOutputParsers_data(); void testQmakeOutputParsers_data();