forked from qt-creator/qt-creator
QbsProjectManager: Reduce calls to mime database.
Qbs already has some definite information about file types. Change-Id: I024feeae3e6df5ec5462924ffedc7332e585f6b7 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
This commit is contained in:
@@ -44,7 +44,10 @@ namespace {
|
|||||||
class ProjectFileCategorizer
|
class ProjectFileCategorizer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ProjectFileCategorizer(const QString &partName, const QStringList &files)
|
ProjectFileCategorizer(const QString &partName,
|
||||||
|
const QStringList &files,
|
||||||
|
ProjectPartBuilder::FileClassifier fileClassifier
|
||||||
|
= ProjectPartBuilder::FileClassifier())
|
||||||
: m_partName(partName)
|
: m_partName(partName)
|
||||||
{
|
{
|
||||||
using CppTools::ProjectFile;
|
using CppTools::ProjectFile;
|
||||||
@@ -52,7 +55,11 @@ public:
|
|||||||
QStringList cHeaders, cxxHeaders;
|
QStringList cHeaders, cxxHeaders;
|
||||||
|
|
||||||
foreach (const QString &file, files) {
|
foreach (const QString &file, files) {
|
||||||
switch (ProjectFile::classify(file)) {
|
const ProjectFile::Kind kind = fileClassifier
|
||||||
|
? fileClassifier(file)
|
||||||
|
: ProjectFile::classify(file);
|
||||||
|
|
||||||
|
switch (kind) {
|
||||||
case ProjectFile::CSource: m_cSources += file; break;
|
case ProjectFile::CSource: m_cSources += file; break;
|
||||||
case ProjectFile::CHeader: cHeaders += file; break;
|
case ProjectFile::CHeader: cHeaders += file; break;
|
||||||
case ProjectFile::CXXSource: m_cxxSources += file; break;
|
case ProjectFile::CXXSource: m_cxxSources += file; break;
|
||||||
@@ -191,11 +198,12 @@ void ProjectPartBuilder::setConfigFileName(const QString &configFileName)
|
|||||||
m_templatePart->projectConfigFile = configFileName;
|
m_templatePart->projectConfigFile = configFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Core::Id> ProjectPartBuilder::createProjectPartsForFiles(const QStringList &files)
|
QList<Core::Id> ProjectPartBuilder::createProjectPartsForFiles(const QStringList &files,
|
||||||
|
FileClassifier fileClassifier)
|
||||||
{
|
{
|
||||||
QList<Core::Id> languages;
|
QList<Core::Id> languages;
|
||||||
|
|
||||||
ProjectFileCategorizer cat(m_templatePart->displayName, files);
|
ProjectFileCategorizer cat(m_templatePart->displayName, files, fileClassifier);
|
||||||
if (cat.hasNoParts())
|
if (cat.hasNoParts())
|
||||||
return languages;
|
return languages;
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,8 @@
|
|||||||
#include "projectinfo.h"
|
#include "projectinfo.h"
|
||||||
#include "projectpart.h"
|
#include "projectpart.h"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
class ToolChain;
|
class ToolChain;
|
||||||
}
|
}
|
||||||
@@ -53,7 +55,10 @@ public:
|
|||||||
void setDisplayName(const QString &displayName);
|
void setDisplayName(const QString &displayName);
|
||||||
void setConfigFileName(const QString &configFileName);
|
void setConfigFileName(const QString &configFileName);
|
||||||
|
|
||||||
QList<Core::Id> createProjectPartsForFiles(const QStringList &files);
|
using FileClassifier = std::function<ProjectFile::Kind (const QString &filePath)>;
|
||||||
|
|
||||||
|
QList<Core::Id> createProjectPartsForFiles(const QStringList &files,
|
||||||
|
FileClassifier fileClassifier = FileClassifier());
|
||||||
|
|
||||||
static void evaluateProjectPartToolchain(ProjectPart *projectPart,
|
static void evaluateProjectPartToolchain(ProjectPart *projectPart,
|
||||||
const ProjectExplorer::ToolChain *toolChain,
|
const ProjectExplorer::ToolChain *toolChain,
|
||||||
|
|||||||
@@ -674,6 +674,21 @@ void QbsProject::updateDocuments(const QSet<QString> &files)
|
|||||||
m_qbsDocuments.unite(toAdd);
|
m_qbsDocuments.unite(toAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CppTools::ProjectFile::Kind cppFileType(const qbs::SourceArtifact &sourceFile)
|
||||||
|
{
|
||||||
|
if (sourceFile.fileTags().contains(QLatin1String("hpp")))
|
||||||
|
return CppTools::ProjectFile::CXXHeader;
|
||||||
|
if (sourceFile.fileTags().contains(QLatin1String("cpp")))
|
||||||
|
return CppTools::ProjectFile::CXXSource;
|
||||||
|
if (sourceFile.fileTags().contains(QLatin1String("c")))
|
||||||
|
return CppTools::ProjectFile::CSource;
|
||||||
|
if (sourceFile.fileTags().contains(QLatin1String("objc")))
|
||||||
|
return CppTools::ProjectFile::ObjCSource;
|
||||||
|
if (sourceFile.fileTags().contains(QLatin1String("objcpp")))
|
||||||
|
return CppTools::ProjectFile::ObjCXXSource;
|
||||||
|
return CppTools::ProjectFile::Unclassified;
|
||||||
|
}
|
||||||
|
|
||||||
void QbsProject::updateCppCodeModel()
|
void QbsProject::updateCppCodeModel()
|
||||||
{
|
{
|
||||||
if (!m_projectData.isValid())
|
if (!m_projectData.isValid())
|
||||||
@@ -759,7 +774,11 @@ void QbsProject::updateCppCodeModel()
|
|||||||
.arg(grp.location().line())
|
.arg(grp.location().line())
|
||||||
.arg(grp.location().column()));
|
.arg(grp.location().column()));
|
||||||
|
|
||||||
|
|
||||||
|
QHash<QString, qbs::SourceArtifact> filePathToSourceArtifact;
|
||||||
foreach (const qbs::SourceArtifact &source, grp.allSourceArtifacts()) {
|
foreach (const qbs::SourceArtifact &source, grp.allSourceArtifacts()) {
|
||||||
|
filePathToSourceArtifact.insert(source.filePath(), source);
|
||||||
|
|
||||||
foreach (const QString &tag, source.fileTags()) {
|
foreach (const QString &tag, source.fileTags()) {
|
||||||
for (auto i = factoriesBegin; i != factoriesEnd; ++i) {
|
for (auto i = factoriesBegin; i != factoriesEnd; ++i) {
|
||||||
if ((*i)->sourceTag() != tag)
|
if ((*i)->sourceTag() != tag)
|
||||||
@@ -779,8 +798,12 @@ void QbsProject::updateCppCodeModel()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QList<Id> languages =
|
const QList<Id> languages = ppBuilder.createProjectPartsForFiles(
|
||||||
ppBuilder.createProjectPartsForFiles(grp.allFilePaths());
|
grp.allFilePaths(),
|
||||||
|
[filePathToSourceArtifact](const QString &filePath) {
|
||||||
|
return cppFileType(filePathToSourceArtifact.value(filePath));
|
||||||
|
});
|
||||||
|
|
||||||
foreach (Id language, languages)
|
foreach (Id language, languages)
|
||||||
setProjectLanguage(language, true);
|
setProjectLanguage(language, true);
|
||||||
}
|
}
|
||||||
@@ -811,13 +834,14 @@ void QbsProject::updateCppCompilerCallData()
|
|||||||
if (!group.isEnabled())
|
if (!group.isEnabled())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
foreach (const QString &file, group.allFilePaths()) {
|
foreach (const qbs::SourceArtifact &file, group.allSourceArtifacts()) {
|
||||||
if (!CppTools::ProjectFile::isSource(CppTools::ProjectFile::classify(file)))
|
const QString &filePath = file.filePath();
|
||||||
|
if (!CppTools::ProjectFile::isSource(cppFileType(file)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
qbs::ErrorInfo errorInfo;
|
qbs::ErrorInfo errorInfo;
|
||||||
const qbs::RuleCommandList ruleCommands
|
const qbs::RuleCommandList ruleCommands = m_qbsProject.ruleCommands(product,
|
||||||
= m_qbsProject.ruleCommands(product, file, QLatin1String("obj"), &errorInfo);
|
filePath, QLatin1String("obj"), &errorInfo);
|
||||||
if (errorInfo.hasError())
|
if (errorInfo.hasError())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -828,7 +852,7 @@ void QbsProject::updateCppCompilerCallData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!calls.isEmpty())
|
if (!calls.isEmpty())
|
||||||
data.insert(file, calls);
|
data.insert(filePath, calls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user