Commit 53712515 authored by Christian Kandeler's avatar Christian Kandeler

QbsProjectManager: Reduce calls to mime database.

Qbs already has some definite information about file types.

Change-Id: I024feeae3e6df5ec5462924ffedc7332e585f6b7
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@theqtcompany.com>
parent af16e876
......@@ -44,7 +44,10 @@ namespace {
class ProjectFileCategorizer
{
public:
ProjectFileCategorizer(const QString &partName, const QStringList &files)
ProjectFileCategorizer(const QString &partName,
const QStringList &files,
ProjectPartBuilder::FileClassifier fileClassifier
= ProjectPartBuilder::FileClassifier())
: m_partName(partName)
{
using CppTools::ProjectFile;
......@@ -52,7 +55,11 @@ public:
QStringList cHeaders, cxxHeaders;
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::CHeader: cHeaders += file; break;
case ProjectFile::CXXSource: m_cxxSources += file; break;
......@@ -191,11 +198,12 @@ void ProjectPartBuilder::setConfigFileName(const QString &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;
ProjectFileCategorizer cat(m_templatePart->displayName, files);
ProjectFileCategorizer cat(m_templatePart->displayName, files, fileClassifier);
if (cat.hasNoParts())
return languages;
......
......@@ -31,6 +31,8 @@
#include "projectinfo.h"
#include "projectpart.h"
#include <functional>
namespace ProjectExplorer {
class ToolChain;
}
......@@ -53,7 +55,10 @@ public:
void setDisplayName(const QString &displayName);
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,
const ProjectExplorer::ToolChain *toolChain,
......
......@@ -674,6 +674,21 @@ void QbsProject::updateDocuments(const QSet<QString> &files)
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()
{
if (!m_projectData.isValid())
......@@ -759,7 +774,11 @@ void QbsProject::updateCppCodeModel()
.arg(grp.location().line())
.arg(grp.location().column()));
QHash<QString, qbs::SourceArtifact> filePathToSourceArtifact;
foreach (const qbs::SourceArtifact &source, grp.allSourceArtifacts()) {
filePathToSourceArtifact.insert(source.filePath(), source);
foreach (const QString &tag, source.fileTags()) {
for (auto i = factoriesBegin; i != factoriesEnd; ++i) {
if ((*i)->sourceTag() != tag)
......@@ -779,8 +798,12 @@ void QbsProject::updateCppCodeModel()
}
}
const QList<Id> languages =
ppBuilder.createProjectPartsForFiles(grp.allFilePaths());
const QList<Id> languages = ppBuilder.createProjectPartsForFiles(
grp.allFilePaths(),
[filePathToSourceArtifact](const QString &filePath) {
return cppFileType(filePathToSourceArtifact.value(filePath));
});
foreach (Id language, languages)
setProjectLanguage(language, true);
}
......@@ -811,13 +834,14 @@ void QbsProject::updateCppCompilerCallData()
if (!group.isEnabled())
continue;
foreach (const QString &file, group.allFilePaths()) {
if (!CppTools::ProjectFile::isSource(CppTools::ProjectFile::classify(file)))
foreach (const qbs::SourceArtifact &file, group.allSourceArtifacts()) {
const QString &filePath = file.filePath();
if (!CppTools::ProjectFile::isSource(cppFileType(file)))
continue;
qbs::ErrorInfo errorInfo;
const qbs::RuleCommandList ruleCommands
= m_qbsProject.ruleCommands(product, file, QLatin1String("obj"), &errorInfo);
const qbs::RuleCommandList ruleCommands = m_qbsProject.ruleCommands(product,
filePath, QLatin1String("obj"), &errorInfo);
if (errorInfo.hasError())
continue;
......@@ -828,7 +852,7 @@ void QbsProject::updateCppCompilerCallData()
}
if (!calls.isEmpty())
data.insert(file, calls);
data.insert(filePath, calls);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment