forked from qt-creator/qt-creator
Clang: Check if the include search path has changed
If the include search paths and the compiler macros have not changed it is save to assume that we don't need to update the symbol database. This saves us from executing a very expensive task. Later we have to test the modification time of the files too. Change-Id: I6b958075024a811c2abd3d7918263fd74bba090b Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -33,9 +33,13 @@
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
ProjectPartArtefact::ProjectPartArtefact(Utils::SmallStringView compilerArgumentsText, Utils::SmallStringView compilerMacrosText, int projectPartId)
|
||||
ProjectPartArtefact::ProjectPartArtefact(Utils::SmallStringView compilerArgumentsText,
|
||||
Utils::SmallStringView compilerMacrosText,
|
||||
Utils::SmallStringView includeSearchPaths,
|
||||
int projectPartId)
|
||||
: compilerArguments(toStringVector(compilerArgumentsText)),
|
||||
compilerMacros(toCompilerMacros(compilerMacrosText)),
|
||||
includeSearchPaths(toStringVector(includeSearchPaths)),
|
||||
projectPartId(projectPartId)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ class ProjectPartArtefact
|
||||
public:
|
||||
ProjectPartArtefact(Utils::SmallStringView compilerArgumentsText,
|
||||
Utils::SmallStringView compilerMacrosText,
|
||||
Utils::SmallStringView includeSearchPaths,
|
||||
int projectPartId);
|
||||
|
||||
static
|
||||
@@ -60,6 +61,7 @@ public:
|
||||
public:
|
||||
Utils::SmallStringVector compilerArguments;
|
||||
CompilerMacros compilerMacros;
|
||||
Utils::SmallStringVector includeSearchPaths;
|
||||
int projectPartId = -1;
|
||||
};
|
||||
|
||||
|
||||
@@ -158,11 +158,11 @@ public:
|
||||
database
|
||||
};
|
||||
WriteStatement insertProjectPartStatement{
|
||||
"INSERT OR IGNORE INTO projectParts(projectPartName, compilerArguments, compilerMacros) VALUES (?,?,?)",
|
||||
"INSERT OR IGNORE INTO projectParts(projectPartName, compilerArguments, compilerMacros, includeSearchPaths) VALUES (?,?,?,?)",
|
||||
database
|
||||
};
|
||||
WriteStatement updateProjectPartStatement{
|
||||
"UPDATE projectParts SET compilerArguments = ?, compilerMacros = ? WHERE projectPartName = ?",
|
||||
"UPDATE projectParts SET compilerArguments = ?, compilerMacros = ?, includeSearchPaths = ? WHERE projectPartName = ?",
|
||||
database
|
||||
};
|
||||
ReadStatement getProjectPartIdStatement{
|
||||
@@ -217,12 +217,12 @@ public:
|
||||
"DELETE FROM newSourceDependencies",
|
||||
database
|
||||
};
|
||||
ReadStatement getProjectPartCompilerArgumentsAndCompilerMacrosBySourceId{
|
||||
"SELECT compilerArguments, compilerMacros, projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)",
|
||||
ReadStatement getProjectPartArtefactsBySourceId{
|
||||
"SELECT compilerArguments, compilerMacros, includeSearchPaths, projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)",
|
||||
database
|
||||
};
|
||||
ReadStatement getProjectPartCompilerArgumentsAndCompilerMacrosByProjectPartName{
|
||||
"SELECT compilerArguments, compilerMacros, projectPartId FROM projectParts WHERE projectPartName = ?",
|
||||
ReadStatement getProjectPartArtefactsByProjectPartName{
|
||||
"SELECT compilerArguments, compilerMacros, includeSearchPaths, projectPartId FROM projectParts WHERE projectPartName = ?",
|
||||
database
|
||||
};
|
||||
};
|
||||
|
||||
@@ -52,7 +52,7 @@ void SymbolIndexer::updateProjectPart(V2::ProjectPartContainer &&projectPart,
|
||||
{
|
||||
m_symbolsCollector.clear();
|
||||
|
||||
if (compilerMacrosAreDifferent(projectPart)) {
|
||||
if (compilerMacrosOrIncludeSearchPathsAreDifferent(projectPart)) {
|
||||
m_symbolsCollector.addFiles(projectPart.sourcePathIds(), projectPart.arguments());
|
||||
|
||||
m_symbolsCollector.addUnsavedFiles(generatedFiles);
|
||||
@@ -66,7 +66,8 @@ void SymbolIndexer::updateProjectPart(V2::ProjectPartContainer &&projectPart,
|
||||
|
||||
m_symbolStorage.insertOrUpdateProjectPart(projectPart.projectPartId(),
|
||||
projectPart.arguments(),
|
||||
projectPart.compilerMacros());
|
||||
projectPart.compilerMacros(),
|
||||
projectPart.includeSearchPaths());
|
||||
m_symbolStorage.updateProjectPartSources(projectPart.projectPartId(),
|
||||
m_symbolsCollector.sourceFiles());
|
||||
|
||||
@@ -121,13 +122,16 @@ void SymbolIndexer::updateChangedPath(FilePathId filePathId)
|
||||
}
|
||||
}
|
||||
|
||||
bool SymbolIndexer::compilerMacrosAreDifferent(const V2::ProjectPartContainer &projectPart) const
|
||||
bool SymbolIndexer::compilerMacrosOrIncludeSearchPathsAreDifferent(const V2::ProjectPartContainer &projectPart) const
|
||||
{
|
||||
const Utils::optional<ProjectPartArtefact> optionalArtefact = m_symbolStorage.fetchProjectPartArtefact(
|
||||
projectPart.projectPartId());
|
||||
|
||||
if (optionalArtefact)
|
||||
return projectPart.compilerMacros() != optionalArtefact.value().compilerMacros;
|
||||
if (optionalArtefact) {
|
||||
const ProjectPartArtefact &artefact = optionalArtefact.value();
|
||||
return projectPart.compilerMacros() != artefact.compilerMacros
|
||||
|| projectPart.includeSearchPaths() != artefact.includeSearchPaths;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,8 @@ public:
|
||||
void pathsChanged(const FilePathIds &filePathIds) override;
|
||||
void updateChangedPath(FilePathId filePath);
|
||||
|
||||
bool compilerMacrosAreDifferent(const V2::ProjectPartContainer &projectPart) const;
|
||||
bool compilerMacrosOrIncludeSearchPathsAreDifferent(
|
||||
const V2::ProjectPartContainer &projectPart) const;
|
||||
|
||||
private:
|
||||
SymbolsCollectorInterface &m_symbolsCollector;
|
||||
|
||||
@@ -68,34 +68,42 @@ public:
|
||||
|
||||
void insertOrUpdateProjectPart(Utils::SmallStringView projectPartName,
|
||||
const Utils::SmallStringVector &commandLineArguments,
|
||||
const CompilerMacros &compilerMacros) override
|
||||
const CompilerMacros &compilerMacros,
|
||||
const Utils::SmallStringVector &includeSearchPaths) override
|
||||
{
|
||||
m_statementFactory.database.setLastInsertedRowId(-1);
|
||||
|
||||
Utils::SmallString compilerArguementsAsJson = toJson(commandLineArguments);
|
||||
Utils::SmallString compilerMacrosAsJson = toJson(compilerMacros);
|
||||
Utils::SmallString includeSearchPathsAsJason = toJson(includeSearchPaths);
|
||||
|
||||
WriteStatement &insertStatement = m_statementFactory.insertProjectPartStatement;
|
||||
insertStatement.write(projectPartName, compilerArguementsAsJson, compilerMacrosAsJson);
|
||||
insertStatement.write(projectPartName,
|
||||
compilerArguementsAsJson,
|
||||
compilerMacrosAsJson,
|
||||
includeSearchPathsAsJason);
|
||||
|
||||
if (m_statementFactory.database.lastInsertedRowId() == -1) {
|
||||
WriteStatement &updateStatement = m_statementFactory.updateProjectPartStatement;
|
||||
updateStatement.write(compilerArguementsAsJson, compilerMacrosAsJson, projectPartName);
|
||||
updateStatement.write(compilerArguementsAsJson,
|
||||
compilerMacrosAsJson,
|
||||
projectPartName,
|
||||
includeSearchPathsAsJason);
|
||||
}
|
||||
}
|
||||
|
||||
Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(FilePathId sourceId) const override
|
||||
{
|
||||
ReadStatement &statement = m_statementFactory.getProjectPartCompilerArgumentsAndCompilerMacrosBySourceId;
|
||||
ReadStatement &statement = m_statementFactory.getProjectPartArtefactsBySourceId;
|
||||
|
||||
return statement.template value<ProjectPartArtefact, 3>(sourceId.filePathId);
|
||||
return statement.template value<ProjectPartArtefact, 4>(sourceId.filePathId);
|
||||
}
|
||||
|
||||
Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(Utils::SmallStringView projectPartName) const override
|
||||
{
|
||||
ReadStatement &statement = m_statementFactory.getProjectPartCompilerArgumentsAndCompilerMacrosByProjectPartName;
|
||||
ReadStatement &statement = m_statementFactory.getProjectPartArtefactsByProjectPartName;
|
||||
|
||||
return statement.template value<ProjectPartArtefact, 3>(projectPartName);
|
||||
return statement.template value<ProjectPartArtefact, 4>(projectPartName);
|
||||
}
|
||||
|
||||
void insertOrUpdateUsedMacros(const UsedMacros &usedMacros) override
|
||||
|
||||
@@ -51,7 +51,8 @@ public:
|
||||
const SourceLocationEntries &sourceLocations) = 0;
|
||||
virtual void insertOrUpdateProjectPart(Utils::SmallStringView projectPartName,
|
||||
const Utils::SmallStringVector &commandLineArguments,
|
||||
const CompilerMacros &compilerMacros) = 0;
|
||||
const CompilerMacros &compilerMacros,
|
||||
const Utils::SmallStringVector &includeSearchPaths) = 0;
|
||||
virtual void updateProjectPartSources(Utils::SmallStringView projectPartName,
|
||||
const FilePathIds &sourceFilePathIds) = 0;
|
||||
virtual void updateProjectPartSources(int projectPartId,
|
||||
|
||||
Reference in New Issue
Block a user