ClangRefactoring: Adapt project part in the database

Extend ProjectPartArtefact and use CommandLineBuilder everywhere.

Task-number: QTCREATORBUG-21842
Change-Id: Ibc78849bc543512eccec8a558a1c3f57fec33fa2
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2019-01-23 14:10:58 +01:00
parent 1c2d41a63e
commit a179030a02
19 changed files with 376 additions and 125 deletions

View File

@@ -121,7 +121,7 @@ void ProjectPartArtefact::checkError(const char *whatError, const QJsonParseErro
bool operator==(const ProjectPartArtefact &first, const ProjectPartArtefact &second)
{
return first.compilerArguments == second.compilerArguments
return first.toolChainArguments == second.toolChainArguments
&& first.compilerMacros == second.compilerMacros
&& first.systemIncludeSearchPaths == second.systemIncludeSearchPaths
&& first.projectIncludeSearchPaths == second.projectIncludeSearchPaths;

View File

@@ -27,6 +27,7 @@
#include "projectpartartefactexception.h"
#include <utils/cpplanguage_details.h>
#include <utils/smallstringvector.h>
#include <compilermacro.h>
@@ -44,12 +45,36 @@ public:
Utils::SmallStringView compilerMacrosText,
Utils::SmallStringView systemIncludeSearchPathsText,
Utils::SmallStringView projectIncludeSearchPathsText,
int projectPartId)
: compilerArguments(toStringVector(compilerArgumentsText))
int projectPartId,
int language,
int languageVersion,
int languageExtension)
: toolChainArguments(toStringVector(compilerArgumentsText))
, compilerMacros(toCompilerMacros(compilerMacrosText))
, systemIncludeSearchPaths(toIncludeSearchPaths(systemIncludeSearchPathsText))
, projectIncludeSearchPaths(toIncludeSearchPaths(projectIncludeSearchPathsText))
, projectPartId(projectPartId)
, language(static_cast<Utils::Language>(language))
, languageVersion(static_cast<Utils::LanguageVersion>(languageVersion))
, languageExtension(static_cast<Utils::LanguageExtension>(languageExtension))
{}
ProjectPartArtefact(Utils::SmallStringView compilerArgumentsText,
Utils::SmallStringView compilerMacrosText,
Utils::SmallStringView systemIncludeSearchPathsText,
Utils::SmallStringView projectIncludeSearchPathsText,
int projectPartId,
Utils::Language language,
Utils::LanguageVersion languageVersion,
Utils::LanguageExtension languageExtension)
: toolChainArguments(toStringVector(compilerArgumentsText))
, compilerMacros(toCompilerMacros(compilerMacrosText))
, systemIncludeSearchPaths(toIncludeSearchPaths(systemIncludeSearchPathsText))
, projectIncludeSearchPaths(toIncludeSearchPaths(projectIncludeSearchPathsText))
, projectPartId(projectPartId)
, language(language)
, languageVersion(languageVersion)
, languageExtension(languageExtension)
{}
static Utils::SmallStringVector toStringVector(Utils::SmallStringView jsonText);
@@ -62,11 +87,14 @@ public:
friend bool operator==(const ProjectPartArtefact &first, const ProjectPartArtefact &second);
public:
Utils::SmallStringVector compilerArguments;
Utils::SmallStringVector toolChainArguments;
CompilerMacros compilerMacros;
IncludeSearchPaths systemIncludeSearchPaths;
IncludeSearchPaths projectIncludeSearchPaths;
int projectPartId = -1;
Utils::Language language = Utils::Language::Cxx;
Utils::LanguageVersion languageVersion = Utils::LanguageVersion::CXX98;
Utils::LanguageExtension languageExtension = Utils::LanguageExtension::None;
};
using ProjectPartArtefacts = std::vector<ProjectPartArtefact>;

View File

@@ -37,20 +37,22 @@ public:
ProjectPartEntry(Utils::SmallStringView projectPathName,
const FilePathIds &filePathIds,
Utils::SmallStringVector &&compilerArguments)
: projectPathName(projectPathName), filePathIds(filePathIds), compilerArguments(compilerArguments)
: projectPathName(projectPathName)
, filePathIds(filePathIds)
, toolChainArguments(compilerArguments)
{}
friend bool operator==(const ProjectPartEntry &first, const ProjectPartEntry &second)
{
return first.projectPathName == second.projectPathName
&& first.filePathIds == second.filePathIds
&& first.compilerArguments == second.compilerArguments;
&& first.filePathIds == second.filePathIds
&& first.toolChainArguments == second.toolChainArguments;
}
public:
Utils::PathString projectPathName;
FilePathIds filePathIds;
Utils::SmallStringVector compilerArguments;
Utils::SmallStringVector toolChainArguments;
};
using ProjectPartEntries = std::vector<ProjectPartEntry>;

View File

@@ -91,7 +91,10 @@ void SymbolIndexer::updateProjectPart(ProjectPartContainer &&projectPart)
projectPart.toolChainArguments,
projectPart.compilerMacros,
projectPart.systemIncludeSearchPaths,
projectPart.projectIncludeSearchPaths);
projectPart.projectIncludeSearchPaths,
projectPart.language,
projectPart.languageVersion,
projectPart.languageExtension);
if (optionalArtefact)
projectPartId = optionalArtefact->projectPartId;
const Utils::optional<ProjectPartPch> optionalProjectPartPch = m_symbolStorage.fetchPrecompiledHeader(projectPartId);
@@ -174,39 +177,37 @@ void SymbolIndexer::updateChangedPath(FilePathId filePathId,
optionalArtefact->projectPartId);
transaction.commit();
if (!optionalArtefact.value().compilerArguments.empty()) {
const ProjectPartArtefact &artefact = optionalArtefact.value();
const ProjectPartArtefact &artefact = optionalArtefact.value();
const Utils::SmallStringVector arguments = compilerArguments(artefact.compilerArguments,
optionalProjectPartPch);
auto pchPath = optionalProjectPartPch ? optionalProjectPartPch.value().pchPath : FilePath{};
auto indexing = [projectPartId = artefact.projectPartId, arguments, filePathId, this](
SymbolsCollectorInterface &symbolsCollector) {
symbolsCollector.setFile(filePathId, arguments);
CommandLineBuilder<ProjectPartArtefact, Utils::SmallStringVector> builder{
artefact, artefact.toolChainArguments, {}, {}, pchPath};
symbolsCollector.collectSymbols();
auto indexing = [projectPartId = artefact.projectPartId, arguments=builder.commandLine, filePathId, this](
SymbolsCollectorInterface &symbolsCollector) {
symbolsCollector.setFile(filePathId, arguments);
Sqlite::ImmediateTransaction transaction{m_transactionInterface};
symbolsCollector.collectSymbols();
m_symbolStorage.addSymbolsAndSourceLocations(symbolsCollector.symbols(),
symbolsCollector.sourceLocations());
Sqlite::ImmediateTransaction transaction{m_transactionInterface};
m_symbolStorage.updateProjectPartSources(projectPartId, symbolsCollector.sourceFiles());
m_symbolStorage.addSymbolsAndSourceLocations(symbolsCollector.symbols(),
symbolsCollector.sourceLocations());
m_buildDependencyStorage.insertOrUpdateUsedMacros(symbolsCollector.usedMacros());
m_symbolStorage.updateProjectPartSources(projectPartId, symbolsCollector.sourceFiles());
m_buildDependencyStorage.insertFileStatuses(symbolsCollector.fileStatuses());
m_buildDependencyStorage.insertOrUpdateUsedMacros(symbolsCollector.usedMacros());
m_buildDependencyStorage.insertOrUpdateSourceDependencies(
symbolsCollector.sourceDependencies());
m_buildDependencyStorage.insertFileStatuses(symbolsCollector.fileStatuses());
transaction.commit();
};
m_buildDependencyStorage.insertOrUpdateSourceDependencies(
symbolsCollector.sourceDependencies());
symbolIndexerTask.emplace_back(filePathId,
optionalArtefact->projectPartId,
std::move(indexing));
}
transaction.commit();
};
symbolIndexerTask.emplace_back(filePathId, optionalArtefact->projectPartId, std::move(indexing));
}
bool SymbolIndexer::compilerMacrosOrIncludeSearchPathsAreDifferent(
@@ -247,18 +248,4 @@ FilePathIds SymbolIndexer::updatableFilePathIds(const ProjectPartContainer &proj
return filterChangedFiles(projectPart);
}
Utils::SmallStringVector SymbolIndexer::compilerArguments(
Utils::SmallStringVector arguments,
const Utils::optional<ProjectPartPch> optionalProjectPartPch) const
{
if (optionalProjectPartPch) {
arguments.emplace_back("-Xclang");
arguments.emplace_back("-include-pch");
arguments.emplace_back("-Xclang");
arguments.emplace_back(std::move(optionalProjectPartPch.value().pchPath));
}
return arguments;
}
} // namespace ClangBackEnd

View File

@@ -67,10 +67,6 @@ public:
FilePathIds updatableFilePathIds(const ProjectPartContainer &projectPart,
const Utils::optional<ProjectPartArtefact> &optionalArtefact) const;
Utils::SmallStringVector compilerArguments(
Utils::SmallStringVector arguments,
const Utils::optional<ProjectPartPch> optionalProjectPartPch) const;
private:
SymbolIndexerTaskQueueInterface &m_symbolIndexerTaskQueue;
SymbolStorageInterface &m_symbolStorage;

View File

@@ -33,6 +33,8 @@
#include <sqlitetable.h>
#include <includesearchpath.h>
#include <utils/cpplanguage_details.h>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
@@ -69,21 +71,27 @@ public:
}
int insertOrUpdateProjectPart(Utils::SmallStringView projectPartName,
const Utils::SmallStringVector &commandLineArguments,
const Utils::SmallStringVector &toolChainArguments,
const CompilerMacros &compilerMacros,
const IncludeSearchPaths &systemIncludeSearchPaths,
const IncludeSearchPaths &projectIncludeSearchPaths) override
const IncludeSearchPaths &projectIncludeSearchPaths,
Utils::Language language,
Utils::LanguageVersion languageVersion,
Utils::LanguageExtension languageExtension) override
{
Utils::SmallString compilerArguementsAsJson = toJson(commandLineArguments);
Utils::SmallString toolChainArgumentsAsJson = toJson(toolChainArguments);
Utils::SmallString compilerMacrosAsJson = toJson(compilerMacros);
Utils::SmallString systemIncludeSearchPathsAsJason = toJson(systemIncludeSearchPaths);
Utils::SmallString projectIncludeSearchPathsAsJason = toJson(projectIncludeSearchPaths);
m_insertOrUpdateProjectPartStatement.write(projectPartName,
compilerArguementsAsJson,
toolChainArgumentsAsJson,
compilerMacrosAsJson,
systemIncludeSearchPathsAsJason,
projectIncludeSearchPathsAsJason);
projectIncludeSearchPathsAsJason,
static_cast<int>(language),
static_cast<int>(languageVersion),
static_cast<int>(languageExtension));
auto projectPartId = m_getProjectPartIdStatement.template value<int>(projectPartName);
@@ -94,14 +102,14 @@ public:
{
ReadStatement &statement = m_getProjectPartArtefactsBySourceId;
return statement.template value<ProjectPartArtefact, 5>(sourceId.filePathId);
return statement.template value<ProjectPartArtefact, 8>(sourceId.filePathId);
}
Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(Utils::SmallStringView projectPartName) const override
{
ReadStatement &statement = m_getProjectPartArtefactsByProjectPartName;
return statement.template value<ProjectPartArtefact, 5>(projectPartName);
return statement.template value<ProjectPartArtefact, 8>(projectPartName);
}
void updateProjectPartSources(int projectPartId,
@@ -308,10 +316,12 @@ public:
m_database
};
WriteStatement m_insertOrUpdateProjectPartStatement{
"INSERT INTO projectParts(projectPartName, compilerArguments, compilerMacros, "
"systemIncludeSearchPaths, projectIncludeSearchPaths) VALUES (?001,?002,?003,?004,?005) ON "
"CONFLICT(projectPartName) DO UPDATE SET compilerArguments=?002, compilerMacros=?003, "
"systemIncludeSearchPaths=?004, projectIncludeSearchPaths=?005",
"INSERT INTO projectParts(projectPartName, toolChainArguments, compilerMacros, "
"systemIncludeSearchPaths, projectIncludeSearchPaths, language, languageVersion, "
"languageExtension) VALUES (?001,?002,?003,?004,?005,?006,?007,?008) ON "
"CONFLICT(projectPartName) DO UPDATE SET toolChainArguments=?002, compilerMacros=?003, "
"systemIncludeSearchPaths=?004, projectIncludeSearchPaths=?005, language=?006, "
"languageVersion=?007, languageExtension=?008",
m_database};
mutable ReadStatement m_getProjectPartIdStatement{
"SELECT projectPartId FROM projectParts WHERE projectPartName = ?",
@@ -326,16 +336,16 @@ public:
m_database
};
mutable ReadStatement m_getCompileArgumentsForFileIdStatement{
"SELECT compilerArguments FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)",
m_database
};
"SELECT toolChainArguments FROM projectParts WHERE projectPartId = (SELECT projectPartId "
"FROM projectPartsSources WHERE sourceId = ?)",
m_database};
mutable ReadStatement m_getProjectPartArtefactsBySourceId{
"SELECT compilerArguments, compilerMacros, systemIncludeSearchPaths, projectIncludeSearchPaths, "
"projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM "
"projectPartsSources WHERE sourceId = ?)",
"SELECT toolChainArguments, compilerMacros, systemIncludeSearchPaths, "
"projectIncludeSearchPaths, projectPartId FROM projectParts WHERE projectPartId = (SELECT "
"projectPartId FROM projectPartsSources WHERE sourceId = ?)",
m_database};
mutable ReadStatement m_getProjectPartArtefactsByProjectPartName{
"SELECT compilerArguments, compilerMacros, systemIncludeSearchPaths, "
"SELECT toolChainArguments, compilerMacros, systemIncludeSearchPaths, "
"projectIncludeSearchPaths, projectPartId FROM projectParts WHERE projectPartName = ?",
m_database};
mutable ReadStatement m_getPrecompiledHeader{

View File

@@ -57,7 +57,10 @@ public:
const Utils::SmallStringVector &commandLineArguments,
const CompilerMacros &compilerMacros,
const ClangBackEnd::IncludeSearchPaths &systemIncludeSearchPaths,
const ClangBackEnd::IncludeSearchPaths &projectIncludeSearchPaths)
const ClangBackEnd::IncludeSearchPaths &projectIncludeSearchPaths,
Utils::Language language,
Utils::LanguageVersion languageVersion,
Utils::LanguageExtension languageExtension)
= 0;
virtual void updateProjectPartSources(int projectPartId, const FilePathIds &sourceFilePathIds) = 0;
virtual Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(