ProjectExplorer: Refactor BuildSystem::extraCompilerForSource

Factor out backend into more generic function to easily support new
accessors.
No functional changes.

Change-Id: I715ce2842d2c63574bdf6ada0d0e32fbfd5d08fb
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2023-01-25 14:15:15 +01:00
parent 49f3b8efd7
commit 97976fd3cb
10 changed files with 31 additions and 21 deletions

View File

@@ -1401,11 +1401,9 @@ void CMakeBuildSystem::runGenerator(Id id)
proc->start();
}
ExtraCompiler *CMakeBuildSystem::extraCompilerForSource(const Utils::FilePath &source)
ExtraCompiler *CMakeBuildSystem::findExtraCompiler(const ExtraCompilerFilter &filter) const
{
return Utils::findOrDefault(m_extraCompilers, [source](ExtraCompiler *ec) {
return ec->source() == source;
});
return Utils::findOrDefault(m_extraCompilers, filter);
}
} // CMakeProjectManager::Internal

View File

@@ -122,7 +122,8 @@ signals:
private:
QList<QPair<Utils::Id, QString>> generators() const override;
void runGenerator(Utils::Id id) override;
ProjectExplorer::ExtraCompiler *extraCompilerForSource(const Utils::FilePath &source) override;
ProjectExplorer::ExtraCompiler *findExtraCompiler(
const ExtraCompilerFilter &filter) const override;
enum ForceEnabledChanged { False, True };
void clearError(ForceEnabledChanged fec = ForceEnabledChanged::False);

View File

@@ -4,6 +4,7 @@
#include "buildsystem.h"
#include "buildconfiguration.h"
#include "extracompiler.h"
#include "projectexplorer.h"
#include "projectexplorertr.h"
#include "runconfiguration.h"
@@ -190,6 +191,12 @@ void BuildSystem::requestParseHelper(int delay)
d->m_delayedParsingTimer.start();
}
ExtraCompiler *BuildSystem::findExtraCompiler(
const std::function<bool (const ExtraCompiler *)> &) const
{
return nullptr;
}
bool BuildSystem::addFiles(Node *, const FilePaths &filePaths, FilePaths *notAdded)
{
Q_UNUSED(filePaths)
@@ -236,10 +243,9 @@ bool BuildSystem::supportsAction(Node *, ProjectAction, const Node *) const
return false;
}
ExtraCompiler *BuildSystem::extraCompilerForSource(const Utils::FilePath &source)
ExtraCompiler *BuildSystem::extraCompilerForSource(const Utils::FilePath &source) const
{
Q_UNUSED(source);
return nullptr;
return findExtraCompiler([source](const ExtraCompiler *ec) { return ec->source() == source; });
}
MakeInstallCommand BuildSystem::makeInstallCommand(const FilePath &installRoot) const

View File

@@ -84,7 +84,7 @@ public:
virtual QString name() const = 0;
// Owned by the build system. Use only in main thread. Can go away at any time.
virtual ExtraCompiler *extraCompilerForSource(const Utils::FilePath &source);
ExtraCompiler *extraCompilerForSource(const Utils::FilePath &source) const;
virtual MakeInstallCommand makeInstallCommand(const Utils::FilePath &installRoot) const;
@@ -161,9 +161,12 @@ protected:
// Call in GUI thread right after the actual parsing is done
void emitParsingFinished(bool success);
using ExtraCompilerFilter = std::function<bool(const ExtraCompiler *)>;
private:
void requestParseHelper(int delay); // request a (delayed!) parser run.
virtual ExtraCompiler *findExtraCompiler(const ExtraCompilerFilter &filter) const;
class BuildSystemPrivate *d = nullptr;
};

View File

@@ -586,11 +586,9 @@ void QbsBuildSystem::delayParsing()
requestDelayedParse();
}
ExtraCompiler *QbsBuildSystem::extraCompilerForSource(const Utils::FilePath &source)
ExtraCompiler *QbsBuildSystem::findExtraCompiler(const ExtraCompilerFilter &filter) const
{
return Utils::findOrDefault(m_extraCompilers, [source](ExtraCompiler *ec) {
return ec->source() == source;
});
return Utils::findOrDefault(m_extraCompilers, filter);
}
void QbsBuildSystem::parseCurrentBuildConfiguration()

View File

@@ -105,7 +105,8 @@ public:
private:
friend class QbsProject;
ProjectExplorer::ExtraCompiler *extraCompilerForSource(const Utils::FilePath &source) override;
ProjectExplorer::ExtraCompiler *findExtraCompiler(
const ExtraCompilerFilter &filter) const override;
void handleQbsParsingDone(bool success);
void changeActiveTarget(ProjectExplorer::Target *t);

View File

@@ -2080,15 +2080,16 @@ QList<ExtraCompiler *> QmakeProFile::extraCompilers() const
return m_extraCompilers;
}
ExtraCompiler *QmakeProFile::extraCompilerForSource(const Utils::FilePath &sourceFile)
ExtraCompiler *QmakeProFile::findExtraCompiler(
const std::function<bool(ProjectExplorer::ExtraCompiler *)> &filter)
{
for (ExtraCompiler * const ec : std::as_const(m_extraCompilers)) {
if (ec->source() == sourceFile)
if (filter(ec))
return ec;
}
for (QmakePriFile * const priFile : std::as_const(m_children)) {
if (const auto proFile = dynamic_cast<QmakeProFile *>(priFile)) {
if (ExtraCompiler * const ec = proFile->extraCompilerForSource(sourceFile))
if (ExtraCompiler * const ec = proFile->findExtraCompiler(filter))
return ec;
}
}

View File

@@ -301,7 +301,8 @@ public:
const Utils::FilePath &sourceFile,
const ProjectExplorer::FileType &sourceFileType) const;
QList<ProjectExplorer::ExtraCompiler *> extraCompilers() const;
ProjectExplorer::ExtraCompiler *extraCompilerForSource(const Utils::FilePath &sourceFile);
ProjectExplorer::ExtraCompiler *findExtraCompiler(
const std::function<bool(ProjectExplorer::ExtraCompiler *)> &filter);
TargetInformation targetInformation() const;
InstallsList installsList() const;

View File

@@ -532,9 +532,9 @@ void QmakeBuildSystem::scheduleUpdateAllNowOrLater()
scheduleUpdateAll(QmakeProFile::ParseLater);
}
ExtraCompiler *QmakeBuildSystem::extraCompilerForSource(const Utils::FilePath &source)
ExtraCompiler *QmakeBuildSystem::findExtraCompiler(const ExtraCompilerFilter &filter) const
{
return m_rootProFile->extraCompilerForSource(source);
return m_rootProFile->findExtraCompiler(filter);
}
QmakeBuildConfiguration *QmakeBuildSystem::qmakeBuildConfiguration() const

View File

@@ -163,7 +163,8 @@ public:
void scheduleUpdateAllNowOrLater();
private:
ProjectExplorer::ExtraCompiler *extraCompilerForSource(const Utils::FilePath &source) override;
ProjectExplorer::ExtraCompiler *findExtraCompiler(
const ExtraCompilerFilter &filter) const override;
void scheduleUpdateAll(QmakeProFile::AsyncUpdateDelay delay);
void scheduleUpdateAllLater() { scheduleUpdateAll(QmakeProFile::ParseLater); }