forked from qt-creator/qt-creator
Clang: Introduce CompilerMacro
We want not only the name but the value of the macro too. So we can compare if anything has changed. Change-Id: Ie59caf8cbf54d108f9e15299d25306a406b5c40d Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -205,6 +205,7 @@ HEADERS += \
|
|||||||
$$PWD/baseserverproxy.h \
|
$$PWD/baseserverproxy.h \
|
||||||
$$PWD/filepath.h \
|
$$PWD/filepath.h \
|
||||||
$$PWD/nativefilepath.h \
|
$$PWD/nativefilepath.h \
|
||||||
$$PWD/filepathview.h
|
$$PWD/filepathview.h \
|
||||||
|
$$PWD/compilermacro.h
|
||||||
|
|
||||||
contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols
|
contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols
|
||||||
|
78
src/libs/clangsupport/compilermacro.h
Normal file
78
src/libs/clangsupport/compilermacro.h
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2017 The Qt Company Ltd.
|
||||||
|
** Contact: https://www.qt.io/licensing/
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and The Qt Company. For licensing terms
|
||||||
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||||
|
** information use the contact form at https://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3 as published by the Free Software
|
||||||
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||||
|
** included in the packaging of this file. Please review the following
|
||||||
|
** information to ensure the GNU General Public License requirements will
|
||||||
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <utils/smallstringio.h>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
|
class CompilerMacro
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
constexpr CompilerMacro() = default;
|
||||||
|
|
||||||
|
CompilerMacro(Utils::SmallString &&key,
|
||||||
|
Utils::SmallString &&value)
|
||||||
|
: key(std::move(key)),
|
||||||
|
value(std::move(value))
|
||||||
|
{}
|
||||||
|
|
||||||
|
friend QDataStream &operator<<(QDataStream &out, const CompilerMacro &compilerMacro)
|
||||||
|
{
|
||||||
|
out << compilerMacro.key;
|
||||||
|
out << compilerMacro.value;
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend QDataStream &operator>>(QDataStream &in, CompilerMacro &compilerMacro)
|
||||||
|
{
|
||||||
|
in >> compilerMacro.key;
|
||||||
|
in >> compilerMacro.value;
|
||||||
|
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend bool operator==(const CompilerMacro &first, const CompilerMacro &second)
|
||||||
|
{
|
||||||
|
return first.key == second.key
|
||||||
|
&& first.value == second.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend bool operator<(const CompilerMacro &first, const CompilerMacro &second)
|
||||||
|
{
|
||||||
|
return std::tie(first.key, first.value) < std::tie(second.key, second.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
Utils::SmallString key;
|
||||||
|
Utils::SmallString value;
|
||||||
|
};
|
||||||
|
|
||||||
|
using CompilerMacros = std::vector<CompilerMacro>;
|
||||||
|
}
|
@@ -27,7 +27,8 @@
|
|||||||
|
|
||||||
#include "clangsupport_global.h"
|
#include "clangsupport_global.h"
|
||||||
|
|
||||||
#include <filepathid.h>
|
#include "compilermacro.h"
|
||||||
|
#include "filepathid.h"
|
||||||
|
|
||||||
#include <utils/smallstringio.h>
|
#include <utils/smallstringio.h>
|
||||||
|
|
||||||
@@ -40,12 +41,12 @@ public:
|
|||||||
ProjectPartContainer() = default;
|
ProjectPartContainer() = default;
|
||||||
ProjectPartContainer(Utils::SmallString &&projectPartId,
|
ProjectPartContainer(Utils::SmallString &&projectPartId,
|
||||||
Utils::SmallStringVector &&arguments,
|
Utils::SmallStringVector &&arguments,
|
||||||
Utils::SmallStringVector &¯oNames,
|
CompilerMacros &&compilerMacros,
|
||||||
FilePathIds &&headerPathIds,
|
FilePathIds &&headerPathIds,
|
||||||
FilePathIds &&sourcePathIds)
|
FilePathIds &&sourcePathIds)
|
||||||
: m_projectPartId(std::move(projectPartId)),
|
: m_projectPartId(std::move(projectPartId)),
|
||||||
m_arguments(std::move(arguments)),
|
m_arguments(std::move(arguments)),
|
||||||
m_macroNames(std::move(macroNames)),
|
m_compilerMacros(std::move(compilerMacros)),
|
||||||
m_headerPathIds(std::move(headerPathIds)),
|
m_headerPathIds(std::move(headerPathIds)),
|
||||||
m_sourcePathIds(std::move(sourcePathIds))
|
m_sourcePathIds(std::move(sourcePathIds))
|
||||||
{
|
{
|
||||||
@@ -66,9 +67,9 @@ public:
|
|||||||
return std::move(m_arguments);
|
return std::move(m_arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Utils::SmallStringVector ¯oNames() const
|
const CompilerMacros &compilerMacros() const
|
||||||
{
|
{
|
||||||
return m_macroNames;
|
return m_compilerMacros;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FilePathIds &sourcePathIds() const
|
const FilePathIds &sourcePathIds() const
|
||||||
@@ -85,7 +86,7 @@ public:
|
|||||||
{
|
{
|
||||||
out << container.m_projectPartId;
|
out << container.m_projectPartId;
|
||||||
out << container.m_arguments;
|
out << container.m_arguments;
|
||||||
out << container.m_macroNames;
|
out << container.m_compilerMacros;
|
||||||
out << container.m_headerPathIds;
|
out << container.m_headerPathIds;
|
||||||
out << container.m_sourcePathIds;
|
out << container.m_sourcePathIds;
|
||||||
|
|
||||||
@@ -96,7 +97,7 @@ public:
|
|||||||
{
|
{
|
||||||
in >> container.m_projectPartId;
|
in >> container.m_projectPartId;
|
||||||
in >> container.m_arguments;
|
in >> container.m_arguments;
|
||||||
in >> container.m_macroNames;
|
in >> container.m_compilerMacros;
|
||||||
in >> container.m_headerPathIds;
|
in >> container.m_headerPathIds;
|
||||||
in >> container.m_sourcePathIds;
|
in >> container.m_sourcePathIds;
|
||||||
|
|
||||||
@@ -107,7 +108,7 @@ public:
|
|||||||
{
|
{
|
||||||
return first.m_projectPartId == second.m_projectPartId
|
return first.m_projectPartId == second.m_projectPartId
|
||||||
&& first.m_arguments == second.m_arguments
|
&& first.m_arguments == second.m_arguments
|
||||||
&& first.m_macroNames == second.m_macroNames
|
&& first.m_compilerMacros == second.m_compilerMacros
|
||||||
&& first.m_headerPathIds == second.m_headerPathIds
|
&& first.m_headerPathIds == second.m_headerPathIds
|
||||||
&& first.m_sourcePathIds == second.m_sourcePathIds;
|
&& first.m_sourcePathIds == second.m_sourcePathIds;
|
||||||
}
|
}
|
||||||
@@ -116,12 +117,12 @@ public:
|
|||||||
{
|
{
|
||||||
return std::tie(first.m_projectPartId,
|
return std::tie(first.m_projectPartId,
|
||||||
first.m_arguments,
|
first.m_arguments,
|
||||||
first.m_macroNames,
|
first.m_compilerMacros,
|
||||||
first.m_headerPathIds,
|
first.m_headerPathIds,
|
||||||
first.m_sourcePathIds)
|
first.m_sourcePathIds)
|
||||||
< std::tie(second.m_projectPartId,
|
< std::tie(second.m_projectPartId,
|
||||||
second.m_arguments,
|
second.m_arguments,
|
||||||
second.m_macroNames,
|
second.m_compilerMacros,
|
||||||
second.m_headerPathIds,
|
second.m_headerPathIds,
|
||||||
second.m_sourcePathIds);
|
second.m_sourcePathIds);
|
||||||
}
|
}
|
||||||
@@ -134,7 +135,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
Utils::SmallString m_projectPartId;
|
Utils::SmallString m_projectPartId;
|
||||||
Utils::SmallStringVector m_arguments;
|
Utils::SmallStringVector m_arguments;
|
||||||
Utils::SmallStringVector m_macroNames;
|
CompilerMacros m_compilerMacros;
|
||||||
FilePathIds m_headerPathIds;
|
FilePathIds m_headerPathIds;
|
||||||
FilePathIds m_sourcePathIds;
|
FilePathIds m_sourcePathIds;
|
||||||
};
|
};
|
||||||
|
@@ -115,7 +115,7 @@ public:
|
|||||||
table.addColumn("projectPartId", Sqlite::ColumnType::Integer, Sqlite::Contraint::PrimaryKey);
|
table.addColumn("projectPartId", Sqlite::ColumnType::Integer, Sqlite::Contraint::PrimaryKey);
|
||||||
const Sqlite::Column &projectPartNameColumn = table.addColumn("projectPartName", Sqlite::ColumnType::Text);
|
const Sqlite::Column &projectPartNameColumn = table.addColumn("projectPartName", Sqlite::ColumnType::Text);
|
||||||
table.addColumn("compilerArguments", Sqlite::ColumnType::Text);
|
table.addColumn("compilerArguments", Sqlite::ColumnType::Text);
|
||||||
table.addColumn("macroNames", Sqlite::ColumnType::Text);
|
table.addColumn("compilerMacros", Sqlite::ColumnType::Text);
|
||||||
table.addIndex({projectPartNameColumn});
|
table.addIndex({projectPartNameColumn});
|
||||||
|
|
||||||
table.initialize(database);
|
table.initialize(database);
|
||||||
|
@@ -121,11 +121,11 @@ QStringList ProjectUpdater::compilerArguments(CppTools::ProjectPart *projectPart
|
|||||||
return builder.build(CppTools::ProjectFile::CXXHeader, CompilerOptionsBuilder::PchUsage::None);
|
return builder.build(CppTools::ProjectFile::CXXHeader, CompilerOptionsBuilder::PchUsage::None);
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::SmallStringVector ProjectUpdater::createMacroNames(CppTools::ProjectPart *projectPart)
|
ClangBackEnd::CompilerMacros ProjectUpdater::createCompilerMacros(CppTools::ProjectPart *projectPart)
|
||||||
{
|
{
|
||||||
return Utils::transform<Utils::SmallStringVector>(projectPart->projectMacros,
|
return Utils::transform<ClangBackEnd::CompilerMacros>(projectPart->projectMacros,
|
||||||
[] (const ProjectExplorer::Macro ¯o) {
|
[] (const ProjectExplorer::Macro ¯o) {
|
||||||
return macro.key;
|
return ClangBackEnd::CompilerMacro{macro.key, macro.value};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ ClangBackEnd::V2::ProjectPartContainer ProjectUpdater::toProjectPartContainer(
|
|||||||
|
|
||||||
return ClangBackEnd::V2::ProjectPartContainer(projectPart->displayName,
|
return ClangBackEnd::V2::ProjectPartContainer(projectPart->displayName,
|
||||||
Utils::SmallStringVector(arguments),
|
Utils::SmallStringVector(arguments),
|
||||||
createMacroNames(projectPart),
|
createCompilerMacros(projectPart),
|
||||||
std::move(headerAndSources.headers),
|
std::move(headerAndSources.headers),
|
||||||
std::move(headerAndSources.sources));
|
std::move(headerAndSources.sources));
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "clangpchmanager_global.h"
|
#include "clangpchmanager_global.h"
|
||||||
|
|
||||||
|
#include <compilermacro.h>
|
||||||
#include <filecontainerv2.h>
|
#include <filecontainerv2.h>
|
||||||
#include <filepathcachinginterface.h>
|
#include <filepathcachinginterface.h>
|
||||||
|
|
||||||
@@ -73,7 +74,7 @@ unittest_public:
|
|||||||
void addToHeaderAndSources(HeaderAndSources &headerAndSources,
|
void addToHeaderAndSources(HeaderAndSources &headerAndSources,
|
||||||
const CppTools::ProjectFile &projectFile) const;
|
const CppTools::ProjectFile &projectFile) const;
|
||||||
static QStringList compilerArguments(CppTools::ProjectPart *projectPart);
|
static QStringList compilerArguments(CppTools::ProjectPart *projectPart);
|
||||||
static Utils::SmallStringVector createMacroNames(CppTools::ProjectPart *projectPart);
|
static ClangBackEnd::CompilerMacros createCompilerMacros(CppTools::ProjectPart *projectPart);
|
||||||
static Utils::PathStringVector createExcludedPaths(
|
static Utils::PathStringVector createExcludedPaths(
|
||||||
const ClangBackEnd::V2::FileContainers &generatedFiles);
|
const ClangBackEnd::V2::FileContainers &generatedFiles);
|
||||||
|
|
||||||
|
@@ -28,8 +28,11 @@
|
|||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/smallstringvector.h>
|
#include <utils/smallstringvector.h>
|
||||||
|
|
||||||
|
#include <compilermacro.h>
|
||||||
|
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
namespace ClangBackEnd {
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
@@ -37,16 +40,16 @@ class ProjectPartArtefact
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ProjectPartArtefact(Utils::SmallStringView compilerArgumentsText,
|
ProjectPartArtefact(Utils::SmallStringView compilerArgumentsText,
|
||||||
Utils::SmallStringView macroNamesText,
|
Utils::SmallStringView compilerMacrosText,
|
||||||
int projectPartId)
|
int projectPartId)
|
||||||
: compilerArguments(toVector(compilerArgumentsText)),
|
: compilerArguments(toStringVector(compilerArgumentsText)),
|
||||||
macroNames(toVector(macroNamesText)),
|
compilerMacros(toCompilerMacros(compilerMacrosText)),
|
||||||
projectPartId(projectPartId)
|
projectPartId(projectPartId)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
Utils::SmallStringVector toVector(Utils::SmallStringView jsonText)
|
Utils::SmallStringVector toStringVector(Utils::SmallStringView jsonText)
|
||||||
{
|
{
|
||||||
QJsonDocument document = QJsonDocument::fromJson(QByteArray::fromRawData(jsonText.data(),
|
QJsonDocument document = QJsonDocument::fromJson(QByteArray::fromRawData(jsonText.data(),
|
||||||
jsonText.size()));
|
jsonText.size()));
|
||||||
@@ -56,16 +59,31 @@ public:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
CompilerMacros toCompilerMacros(Utils::SmallStringView jsonText)
|
||||||
|
{
|
||||||
|
QJsonDocument document = QJsonDocument::fromJson(QByteArray::fromRawData(jsonText.data(),
|
||||||
|
jsonText.size()));
|
||||||
|
QJsonObject object = document.object();
|
||||||
|
CompilerMacros macros;
|
||||||
|
macros.reserve(object.size());
|
||||||
|
|
||||||
|
for (auto current = object.constBegin(); current != object.constEnd(); ++current)
|
||||||
|
macros.emplace_back(current.key(), current.value().toString());
|
||||||
|
|
||||||
|
return macros;
|
||||||
|
}
|
||||||
|
|
||||||
friend
|
friend
|
||||||
bool operator==(const ProjectPartArtefact &first, const ProjectPartArtefact &second)
|
bool operator==(const ProjectPartArtefact &first, const ProjectPartArtefact &second)
|
||||||
{
|
{
|
||||||
return first.compilerArguments == second.compilerArguments
|
return first.compilerArguments == second.compilerArguments
|
||||||
&& first.macroNames == second.macroNames;
|
&& first.compilerMacros == second.compilerMacros;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Utils::SmallStringVector compilerArguments;
|
Utils::SmallStringVector compilerArguments;
|
||||||
Utils::SmallStringVector macroNames;
|
CompilerMacros compilerMacros;
|
||||||
int projectPartId = -1;
|
int projectPartId = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -158,11 +158,11 @@ public:
|
|||||||
database
|
database
|
||||||
};
|
};
|
||||||
WriteStatement insertProjectPartStatement{
|
WriteStatement insertProjectPartStatement{
|
||||||
"INSERT OR IGNORE INTO projectParts(projectPartName, compilerArguments, macroNames) VALUES (?,?,?)",
|
"INSERT OR IGNORE INTO projectParts(projectPartName, compilerArguments, compilerMacros) VALUES (?,?,?)",
|
||||||
database
|
database
|
||||||
};
|
};
|
||||||
WriteStatement updateProjectPartStatement{
|
WriteStatement updateProjectPartStatement{
|
||||||
"UPDATE projectParts SET compilerArguments = ?, macroNames = ? WHERE projectPartName = ?",
|
"UPDATE projectParts SET compilerArguments = ?, compilerMacros = ? WHERE projectPartName = ?",
|
||||||
database
|
database
|
||||||
};
|
};
|
||||||
ReadStatement getProjectPartIdStatement{
|
ReadStatement getProjectPartIdStatement{
|
||||||
@@ -217,8 +217,8 @@ public:
|
|||||||
"DELETE FROM newSourceDependencies",
|
"DELETE FROM newSourceDependencies",
|
||||||
database
|
database
|
||||||
};
|
};
|
||||||
ReadStatement getProjectPartCompilerArgumentsAndMacroNames{
|
ReadStatement getProjectPartCompilerArgumentsAndCompilerMacrosBySourceId{
|
||||||
"SELECT compilerArguments, macroNames, projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)",
|
"SELECT compilerArguments, compilerMacros, projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)",
|
||||||
database
|
database
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@@ -65,7 +65,7 @@ void SymbolIndexer::updateProjectPart(V2::ProjectPartContainer &&projectPart,
|
|||||||
|
|
||||||
m_symbolStorage.insertOrUpdateProjectPart(projectPart.projectPartId(),
|
m_symbolStorage.insertOrUpdateProjectPart(projectPart.projectPartId(),
|
||||||
projectPart.arguments(),
|
projectPart.arguments(),
|
||||||
projectPart.macroNames());
|
projectPart.compilerMacros());
|
||||||
m_symbolStorage.updateProjectPartSources(projectPart.projectPartId(),
|
m_symbolStorage.updateProjectPartSources(projectPart.projectPartId(),
|
||||||
m_symbolsCollector.sourceFiles());
|
m_symbolsCollector.sourceFiles());
|
||||||
|
|
||||||
|
@@ -31,8 +31,9 @@
|
|||||||
#include <sqlitetransaction.h>
|
#include <sqlitetransaction.h>
|
||||||
#include <filepathcachingfwd.h>
|
#include <filepathcachingfwd.h>
|
||||||
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
namespace ClangBackEnd {
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
@@ -67,25 +68,25 @@ public:
|
|||||||
|
|
||||||
void insertOrUpdateProjectPart(Utils::SmallStringView projectPartName,
|
void insertOrUpdateProjectPart(Utils::SmallStringView projectPartName,
|
||||||
const Utils::SmallStringVector &commandLineArguments,
|
const Utils::SmallStringVector &commandLineArguments,
|
||||||
const Utils::SmallStringVector ¯oNames) override
|
const CompilerMacros &compilerMacros) override
|
||||||
{
|
{
|
||||||
m_statementFactory.database.setLastInsertedRowId(-1);
|
m_statementFactory.database.setLastInsertedRowId(-1);
|
||||||
|
|
||||||
Utils::SmallString compilerArguementsAsJson = toJson(commandLineArguments);
|
Utils::SmallString compilerArguementsAsJson = toJson(commandLineArguments);
|
||||||
Utils::SmallString macroNamesAsJson = toJson(macroNames);
|
Utils::SmallString compilerMacrosAsJson = toJson(compilerMacros);
|
||||||
|
|
||||||
WriteStatement &insertStatement = m_statementFactory.insertProjectPartStatement;
|
WriteStatement &insertStatement = m_statementFactory.insertProjectPartStatement;
|
||||||
insertStatement.write(projectPartName, compilerArguementsAsJson, macroNamesAsJson);
|
insertStatement.write(projectPartName, compilerArguementsAsJson, compilerMacrosAsJson);
|
||||||
|
|
||||||
if (m_statementFactory.database.lastInsertedRowId() == -1) {
|
if (m_statementFactory.database.lastInsertedRowId() == -1) {
|
||||||
WriteStatement &updateStatement = m_statementFactory.updateProjectPartStatement;
|
WriteStatement &updateStatement = m_statementFactory.updateProjectPartStatement;
|
||||||
updateStatement.write(compilerArguementsAsJson, macroNamesAsJson, projectPartName);
|
updateStatement.write(compilerArguementsAsJson, compilerMacrosAsJson, projectPartName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(FilePathId sourceId) const override
|
Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(FilePathId sourceId) const override
|
||||||
{
|
{
|
||||||
ReadStatement &statement = m_statementFactory.getProjectPartCompilerArgumentsAndMacroNames;
|
ReadStatement &statement = m_statementFactory.getProjectPartCompilerArgumentsAndCompilerMacrosBySourceId;
|
||||||
|
|
||||||
return statement.template value<ProjectPartArtefact, 3>(sourceId.filePathId);
|
return statement.template value<ProjectPartArtefact, 3>(sourceId.filePathId);
|
||||||
}
|
}
|
||||||
@@ -157,6 +158,19 @@ public:
|
|||||||
return document.toJson(QJsonDocument::Compact);
|
return document.toJson(QJsonDocument::Compact);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Utils::SmallString toJson(const CompilerMacros &compilerMacros)
|
||||||
|
{
|
||||||
|
QJsonDocument document;
|
||||||
|
QJsonObject object;
|
||||||
|
|
||||||
|
for (const CompilerMacro ¯o : compilerMacros)
|
||||||
|
object.insert(QString(macro.key), QString(macro.value));
|
||||||
|
|
||||||
|
document.setObject(object);
|
||||||
|
|
||||||
|
return document.toJson(QJsonDocument::Compact);
|
||||||
|
}
|
||||||
|
|
||||||
void fillTemporarySymbolsTable(const SymbolEntries &symbolEntries)
|
void fillTemporarySymbolsTable(const SymbolEntries &symbolEntries)
|
||||||
{
|
{
|
||||||
WriteStatement &statement = m_statementFactory.insertSymbolsToNewSymbolsStatement;
|
WriteStatement &statement = m_statementFactory.insertSymbolsToNewSymbolsStatement;
|
||||||
|
@@ -35,6 +35,8 @@
|
|||||||
|
|
||||||
#include <sqlitetransaction.h>
|
#include <sqlitetransaction.h>
|
||||||
|
|
||||||
|
#include <compilermacro.h>
|
||||||
|
|
||||||
namespace ClangBackEnd {
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
class SymbolStorageInterface
|
class SymbolStorageInterface
|
||||||
@@ -49,7 +51,7 @@ public:
|
|||||||
const SourceLocationEntries &sourceLocations) = 0;
|
const SourceLocationEntries &sourceLocations) = 0;
|
||||||
virtual void insertOrUpdateProjectPart(Utils::SmallStringView projectPartName,
|
virtual void insertOrUpdateProjectPart(Utils::SmallStringView projectPartName,
|
||||||
const Utils::SmallStringVector &commandLineArguments,
|
const Utils::SmallStringVector &commandLineArguments,
|
||||||
const Utils::SmallStringVector ¯oNames) = 0;
|
const CompilerMacros &compilerMacros) = 0;
|
||||||
virtual void updateProjectPartSources(Utils::SmallStringView projectPartName,
|
virtual void updateProjectPartSources(Utils::SmallStringView projectPartName,
|
||||||
const FilePathIds &sourceFilePathIds) = 0;
|
const FilePathIds &sourceFilePathIds) = 0;
|
||||||
virtual void updateProjectPartSources(int projectPartId,
|
virtual void updateProjectPartSources(int projectPartId,
|
||||||
|
@@ -887,7 +887,15 @@ std::ostream &operator<<(std::ostream &out, const ProjectPartArtefact &projectPa
|
|||||||
{
|
{
|
||||||
return out << "("
|
return out << "("
|
||||||
<< projectPartArtefact.compilerArguments << ", "
|
<< projectPartArtefact.compilerArguments << ", "
|
||||||
<< projectPartArtefact.macroNames
|
<< projectPartArtefact.compilerMacros
|
||||||
|
<<")";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &out, const CompilerMacro &compilerMacro)
|
||||||
|
{
|
||||||
|
return out << "("
|
||||||
|
<< compilerMacro.key << ", "
|
||||||
|
<< compilerMacro.value
|
||||||
<< ")";
|
<< ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -155,6 +155,7 @@ class UsedMacro;
|
|||||||
class FileStatus;
|
class FileStatus;
|
||||||
class SourceDependency;
|
class SourceDependency;
|
||||||
class ProjectPartArtefact;
|
class ProjectPartArtefact;
|
||||||
|
class CompilerMacro;
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const SourceLocationEntry &entry);
|
std::ostream &operator<<(std::ostream &out, const SourceLocationEntry &entry);
|
||||||
std::ostream &operator<<(std::ostream &out, const IdPaths &idPaths);
|
std::ostream &operator<<(std::ostream &out, const IdPaths &idPaths);
|
||||||
@@ -226,6 +227,7 @@ std::ostream &operator<<(std::ostream &out, const UsedMacro &usedMacro);
|
|||||||
std::ostream &operator<<(std::ostream &out, const FileStatus &fileStatus);
|
std::ostream &operator<<(std::ostream &out, const FileStatus &fileStatus);
|
||||||
std::ostream &operator<<(std::ostream &out, const SourceDependency &sourceDependency);
|
std::ostream &operator<<(std::ostream &out, const SourceDependency &sourceDependency);
|
||||||
std::ostream &operator<<(std::ostream &out, const ProjectPartArtefact &projectPartArtefact);
|
std::ostream &operator<<(std::ostream &out, const ProjectPartArtefact &projectPartArtefact);
|
||||||
|
std::ostream &operator<<(std::ostream &out, const CompilerMacro &compilerMacro);
|
||||||
|
|
||||||
void PrintTo(const FilePath &filePath, ::std::ostream *os);
|
void PrintTo(const FilePath &filePath, ::std::ostream *os);
|
||||||
void PrintTo(const FilePathView &filePathView, ::std::ostream *os);
|
void PrintTo(const FilePathView &filePathView, ::std::ostream *os);
|
||||||
|
@@ -40,7 +40,7 @@ public:
|
|||||||
MOCK_METHOD3(insertOrUpdateProjectPart,
|
MOCK_METHOD3(insertOrUpdateProjectPart,
|
||||||
void(Utils::SmallStringView projectPartName,
|
void(Utils::SmallStringView projectPartName,
|
||||||
const Utils::SmallStringVector &commandLineArgument,
|
const Utils::SmallStringVector &commandLineArgument,
|
||||||
const Utils::SmallStringVector ¯oNames));
|
const ClangBackEnd::CompilerMacros &compilerMacros));
|
||||||
MOCK_METHOD2(updateProjectPartSources,
|
MOCK_METHOD2(updateProjectPartSources,
|
||||||
void(Utils::SmallStringView projectPartName,
|
void(Utils::SmallStringView projectPartName,
|
||||||
const ClangBackEnd::FilePathIds &sourceFilePathIds));
|
const ClangBackEnd::FilePathIds &sourceFilePathIds));
|
||||||
|
@@ -74,12 +74,12 @@ protected:
|
|||||||
FilePath generatedFilePath = TESTDATA_DIR "/includecollector_generated_file.h";
|
FilePath generatedFilePath = TESTDATA_DIR "/includecollector_generated_file.h";
|
||||||
ProjectPartContainer projectPart1{"project1",
|
ProjectPartContainer projectPart1{"project1",
|
||||||
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
|
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
|
||||||
{"DEFINE"},
|
{{"DEFINE", "1"}},
|
||||||
{id(header1Path)},
|
{id(header1Path)},
|
||||||
{id(main1Path)}};
|
{id(main1Path)}};
|
||||||
ProjectPartContainer projectPart2{"project2",
|
ProjectPartContainer projectPart2{"project2",
|
||||||
{"-I", TESTDATA_DIR, "-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
{"-I", TESTDATA_DIR, "-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
||||||
{"DEFINE"},
|
{{"DEFINE", "1"}},
|
||||||
{id(header2Path)},
|
{id(header2Path)},
|
||||||
{id(main2Path)}};
|
{id(main2Path)}};
|
||||||
TestEnvironment environment;
|
TestEnvironment environment;
|
||||||
|
@@ -94,7 +94,7 @@ TEST_F(PchManagerClientServerInProcess, SendUpdatePchProjectPartsMessage)
|
|||||||
{
|
{
|
||||||
ProjectPartContainer projectPart2{"projectPartId",
|
ProjectPartContainer projectPart2{"projectPartId",
|
||||||
{"-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
{"-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
||||||
{"DEFINE"},
|
{{"DEFINE", "1"}},
|
||||||
{{1, 1}},
|
{{1, 1}},
|
||||||
{{1, 2}}};
|
{{1, 2}}};
|
||||||
FileContainer fileContainer{{"/path/to/", "file"}, "content", {}};
|
FileContainer fileContainer{{"/path/to/", "file"}, "content", {}};
|
||||||
|
@@ -70,12 +70,12 @@ protected:
|
|||||||
std::vector<ClangBackEnd::IdPaths> idPaths = {{projectPartId1, {{1, 1}, {1, 2}}}};
|
std::vector<ClangBackEnd::IdPaths> idPaths = {{projectPartId1, {{1, 1}, {1, 2}}}};
|
||||||
ProjectPartContainer projectPart1{projectPartId1.clone(),
|
ProjectPartContainer projectPart1{projectPartId1.clone(),
|
||||||
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
|
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
|
||||||
{"DEFINE"},
|
{{"DEFINE", "1"}},
|
||||||
{id(header1Path)},
|
{id(header1Path)},
|
||||||
{id(main1Path)}};
|
{id(main1Path)}};
|
||||||
ProjectPartContainer projectPart2{projectPartId2.clone(),
|
ProjectPartContainer projectPart2{projectPartId2.clone(),
|
||||||
{"-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
{"-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
||||||
{"DEFINE"},
|
{{"DEFINE", "1"}},
|
||||||
{id(header2Path)},
|
{id(header2Path)},
|
||||||
{id(main2Path)}};
|
{id(main2Path)}};
|
||||||
std::vector<ProjectPartContainer> projectParts{projectPart1, projectPart2};
|
std::vector<ProjectPartContainer> projectParts{projectPart1, projectPart2};
|
||||||
|
48
tests/unit/unittest/projectpartartefact-test.cpp
Normal file
48
tests/unit/unittest/projectpartartefact-test.cpp
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2017 The Qt Company Ltd.
|
||||||
|
** Contact: https://www.qt.io/licensing/
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and The Qt Company. For licensing terms
|
||||||
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||||
|
** information use the contact form at https://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3 as published by the Free Software
|
||||||
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||||
|
** included in the packaging of this file. Please review the following
|
||||||
|
** information to ensure the GNU General Public License requirements will
|
||||||
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "googletest.h"
|
||||||
|
|
||||||
|
#include <projectpartartefacts.h>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
using ClangBackEnd::CompilerMacro;
|
||||||
|
|
||||||
|
TEST(ProjectPartArtefact, CompilerArguments)
|
||||||
|
{
|
||||||
|
ClangBackEnd::ProjectPartArtefact artefact{"[\"-DFoo\",\"-DBar\"]", "", 1};
|
||||||
|
|
||||||
|
ASSERT_THAT(artefact.compilerArguments, ElementsAre(Eq("-DFoo"), Eq("-DBar")));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ProjectPartArtefact, CompilerMacros)
|
||||||
|
{
|
||||||
|
ClangBackEnd::ProjectPartArtefact artefact{"", "{\"Foo\":\"1\",\"Bar\":\"42\"}", 1};
|
||||||
|
|
||||||
|
ASSERT_THAT(artefact.compilerMacros,
|
||||||
|
UnorderedElementsAre(Eq(CompilerMacro{"Foo", "1"}), Eq(CompilerMacro{"Bar", "42"})));
|
||||||
|
}
|
||||||
|
}
|
@@ -49,17 +49,17 @@ protected:
|
|||||||
FilePathId thirdSource{1, 13};
|
FilePathId thirdSource{1, 13};
|
||||||
ProjectPartContainer projectPartContainer1{"id",
|
ProjectPartContainer projectPartContainer1{"id",
|
||||||
{"-DUNIX", "-O2"},
|
{"-DUNIX", "-O2"},
|
||||||
{"UNIX"},
|
{{"DEFINE", "1"}},
|
||||||
{firstHeader, secondHeader},
|
{firstHeader, secondHeader},
|
||||||
{firstSource, secondSource}};
|
{firstSource, secondSource}};
|
||||||
ProjectPartContainer updatedProjectPartContainer1{"id",
|
ProjectPartContainer updatedProjectPartContainer1{"id",
|
||||||
{"-DUNIX", "-O2"},
|
{"-DUNIX", "-O2"},
|
||||||
{"UNIX"},
|
{{"DEFINE", "1"}},
|
||||||
{firstHeader, secondHeader},
|
{firstHeader, secondHeader},
|
||||||
{firstSource, secondSource, thirdSource}};
|
{firstSource, secondSource, thirdSource}};
|
||||||
ProjectPartContainer projectPartContainer2{"id2",
|
ProjectPartContainer projectPartContainer2{"id2",
|
||||||
{"-DUNIX", "-O2"},
|
{"-DUNIX", "-O2"},
|
||||||
{"UNIX"},
|
{{"DEFINE", "1"}},
|
||||||
{firstHeader, secondHeader},
|
{firstHeader, secondHeader},
|
||||||
{firstSource, secondSource}};
|
{firstSource, secondSource}};
|
||||||
};
|
};
|
||||||
|
@@ -77,14 +77,14 @@ protected:
|
|||||||
projectPart.files.push_back(source1ProjectFile);
|
projectPart.files.push_back(source1ProjectFile);
|
||||||
projectPart.files.push_back(source2ProjectFile);
|
projectPart.files.push_back(source2ProjectFile);
|
||||||
projectPart.displayName = QString(projectPartId);
|
projectPart.displayName = QString(projectPartId);
|
||||||
projectPart.projectMacros.push_back({"DEFINE"});
|
projectPart.projectMacros.push_back({"DEFINE", "1"});
|
||||||
|
|
||||||
Utils::SmallStringVector arguments{ClangPchManager::ProjectUpdater::compilerArguments(
|
Utils::SmallStringVector arguments{ClangPchManager::ProjectUpdater::compilerArguments(
|
||||||
&projectPart)};
|
&projectPart)};
|
||||||
|
|
||||||
expectedContainer = {projectPartId.clone(),
|
expectedContainer = {projectPartId.clone(),
|
||||||
arguments.clone(),
|
arguments.clone(),
|
||||||
macroNames.clone(),
|
Utils::clone(compilerMacros),
|
||||||
{filePathId(headerPaths[1])},
|
{filePathId(headerPaths[1])},
|
||||||
{filePathIds(sourcePaths)}};
|
{filePathIds(sourcePaths)}};
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,7 @@ protected:
|
|||||||
Utils::SmallString projectPartId2{"project2"};
|
Utils::SmallString projectPartId2{"project2"};
|
||||||
Utils::PathStringVector headerPaths = {"/path/to/header1.h", "/path/to/header2.h"};
|
Utils::PathStringVector headerPaths = {"/path/to/header1.h", "/path/to/header2.h"};
|
||||||
Utils::PathStringVector sourcePaths = {"/path/to/source1.cpp", "/path/to/source2.cpp"};
|
Utils::PathStringVector sourcePaths = {"/path/to/source1.cpp", "/path/to/source2.cpp"};
|
||||||
Utils::SmallStringVector macroNames = {"DEFINE"};
|
ClangBackEnd::CompilerMacros compilerMacros = {{"DEFINE", "1"}};
|
||||||
CppTools::ProjectFile header1ProjectFile{QString(headerPaths[0]), CppTools::ProjectFile::CXXHeader};
|
CppTools::ProjectFile header1ProjectFile{QString(headerPaths[0]), CppTools::ProjectFile::CXXHeader};
|
||||||
CppTools::ProjectFile header2ProjectFile{QString(headerPaths[1]), CppTools::ProjectFile::CXXHeader};
|
CppTools::ProjectFile header2ProjectFile{QString(headerPaths[1]), CppTools::ProjectFile::CXXHeader};
|
||||||
CppTools::ProjectFile source1ProjectFile{QString(sourcePaths[0]), CppTools::ProjectFile::CXXSource};
|
CppTools::ProjectFile source1ProjectFile{QString(sourcePaths[0]), CppTools::ProjectFile::CXXSource};
|
||||||
|
@@ -178,7 +178,7 @@ TEST_F(RefactoringClientServerInProcess, SendUpdatePchProjectPartsMessage)
|
|||||||
{
|
{
|
||||||
ProjectPartContainer projectPart2{"projectPartId",
|
ProjectPartContainer projectPart2{"projectPartId",
|
||||||
{"-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
{"-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
||||||
{"DEFINE"},
|
{{"DEFINE", "1"}},
|
||||||
{{1, 1}},
|
{{1, 1}},
|
||||||
{{1, 2}}};
|
{{1, 2}}};
|
||||||
FileContainer fileContainer{{"/path/to/", "file"}, "content", {}};
|
FileContainer fileContainer{{"/path/to/", "file"}, "content", {}};
|
||||||
|
@@ -86,7 +86,7 @@ TEST_F(RefactoringDatabaseInitializer, AddProjectPartsTable)
|
|||||||
{
|
{
|
||||||
InSequence s;
|
InSequence s;
|
||||||
|
|
||||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectParts(projectPartId INTEGER PRIMARY KEY, projectPartName TEXT, compilerArguments TEXT, macroNames TEXT)")));
|
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectParts(projectPartId INTEGER PRIMARY KEY, projectPartName TEXT, compilerArguments TEXT, compilerMacros TEXT)")));
|
||||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_projectParts_projectPartName ON projectParts(projectPartName)")));
|
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_projectParts_projectPartName ON projectParts(projectPartName)")));
|
||||||
|
|
||||||
initializer.createProjectPartsTable();
|
initializer.createProjectPartsTable();
|
||||||
@@ -146,7 +146,7 @@ TEST_F(RefactoringDatabaseInitializer, CreateInTheContructor)
|
|||||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_sources_directoryId_sourceName ON sources(directoryId, sourceName)")));
|
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_sources_directoryId_sourceName ON sources(directoryId, sourceName)")));
|
||||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS directories(directoryId INTEGER PRIMARY KEY, directoryPath TEXT)")));
|
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS directories(directoryId INTEGER PRIMARY KEY, directoryPath TEXT)")));
|
||||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_directories_directoryPath ON directories(directoryPath)")));
|
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_directories_directoryPath ON directories(directoryPath)")));
|
||||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectParts(projectPartId INTEGER PRIMARY KEY, projectPartName TEXT, compilerArguments TEXT, macroNames TEXT)")));
|
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectParts(projectPartId INTEGER PRIMARY KEY, projectPartName TEXT, compilerArguments TEXT, compilerMacros TEXT)")));
|
||||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_projectParts_projectPartName ON projectParts(projectPartName)")));
|
EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_projectParts_projectPartName ON projectParts(projectPartName)")));
|
||||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, sourceId INTEGER)")));
|
EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, sourceId INTEGER)")));
|
||||||
EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectPartsSources_sourceId_projectPartId ON projectPartsSources(sourceId, projectPartId)")));
|
EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectPartsSources_sourceId_projectPartId ON projectPartsSources(sourceId, projectPartId)")));
|
||||||
|
@@ -301,7 +301,7 @@ TEST_F(RefactoringServer, UpdatePchProjectPartsCallsSymbolIndexingUpdateProjectP
|
|||||||
{
|
{
|
||||||
ProjectPartContainers projectParts{{{"projectPartId",
|
ProjectPartContainers projectParts{{{"projectPartId",
|
||||||
{"-I", TESTDATA_DIR},
|
{"-I", TESTDATA_DIR},
|
||||||
{"DEFINE"},
|
{{"DEFINE", "1"}},
|
||||||
{filePathId("header1.h")},
|
{filePathId("header1.h")},
|
||||||
{filePathId("main.cpp")}}}};
|
{filePathId("main.cpp")}}}};
|
||||||
FileContainers unsaved{{{TESTDATA_DIR, "query_simplefunction.h"},
|
FileContainers unsaved{{{TESTDATA_DIR, "query_simplefunction.h"},
|
||||||
|
@@ -169,13 +169,13 @@ TEST_F(StorageSqliteStatementFactory, DeleteNewLocationsTableStatement)
|
|||||||
TEST_F(StorageSqliteStatementFactory, InsertProjectPart)
|
TEST_F(StorageSqliteStatementFactory, InsertProjectPart)
|
||||||
{
|
{
|
||||||
ASSERT_THAT(factory.insertProjectPartStatement.sqlStatement,
|
ASSERT_THAT(factory.insertProjectPartStatement.sqlStatement,
|
||||||
Eq("INSERT OR IGNORE INTO projectParts(projectPartName, compilerArguments, macroNames) VALUES (?,?,?)"));
|
Eq("INSERT OR IGNORE INTO projectParts(projectPartName, compilerArguments, compilerMacros) VALUES (?,?,?)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(StorageSqliteStatementFactory, UpdateProjectPart)
|
TEST_F(StorageSqliteStatementFactory, UpdateProjectPart)
|
||||||
{
|
{
|
||||||
ASSERT_THAT(factory.updateProjectPartStatement.sqlStatement,
|
ASSERT_THAT(factory.updateProjectPartStatement.sqlStatement,
|
||||||
Eq("UPDATE projectParts SET compilerArguments = ?, macroNames = ? WHERE projectPartName = ?"));
|
Eq("UPDATE projectParts SET compilerArguments = ?, compilerMacros = ? WHERE projectPartName = ?"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(StorageSqliteStatementFactory, GetProjectPartIdForProjectPartName)
|
TEST_F(StorageSqliteStatementFactory, GetProjectPartIdForProjectPartName)
|
||||||
@@ -256,10 +256,10 @@ TEST_F(StorageSqliteStatementFactory, DeleteAllInNewSourceDependencies)
|
|||||||
Eq("DELETE FROM newSourceDependencies"));
|
Eq("DELETE FROM newSourceDependencies"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(StorageSqliteStatementFactory, GetProjectPartCompilerArgumentsAndMacroNames)
|
TEST_F(StorageSqliteStatementFactory, GetProjectPartCompilerArgumentsAndCompilerMacrosBySourceId)
|
||||||
{
|
{
|
||||||
ASSERT_THAT(factory.getProjectPartCompilerArgumentsAndMacroNames.sqlStatement,
|
ASSERT_THAT(factory.getProjectPartCompilerArgumentsAndCompilerMacrosBySourceId.sqlStatement,
|
||||||
Eq("SELECT compilerArguments, macroNames, projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)"));
|
Eq("SELECT compilerArguments, compilerMacros, projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -37,6 +37,7 @@
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using Utils::PathString;
|
using Utils::PathString;
|
||||||
|
using ClangBackEnd::CompilerMacro;
|
||||||
using ClangBackEnd::FileStatuses;
|
using ClangBackEnd::FileStatuses;
|
||||||
using ClangBackEnd::FilePathIds;
|
using ClangBackEnd::FilePathIds;
|
||||||
using ClangBackEnd::FilePathView;
|
using ClangBackEnd::FilePathView;
|
||||||
@@ -81,12 +82,12 @@ protected:
|
|||||||
ClangBackEnd::FilePathId generatedFilePathId{1, 21};
|
ClangBackEnd::FilePathId generatedFilePathId{1, 21};
|
||||||
ProjectPartContainer projectPart1{"project1",
|
ProjectPartContainer projectPart1{"project1",
|
||||||
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
|
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
|
||||||
{"DEFINE"},
|
{{"DEFINE", "1"}},
|
||||||
{header1PathId},
|
{header1PathId},
|
||||||
{main1PathId}};
|
{main1PathId}};
|
||||||
ProjectPartContainer projectPart2{"project2",
|
ProjectPartContainer projectPart2{"project2",
|
||||||
{"-I", TESTDATA_DIR, "-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
{"-I", TESTDATA_DIR, "-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
||||||
{"DEFINE"},
|
{{"DEFINE", "1"}},
|
||||||
{header2PathId},
|
{header2PathId},
|
||||||
{main2PathId}};
|
{main2PathId}};
|
||||||
FileContainers unsaved{{{TESTDATA_DIR, "query_simplefunction.h"},
|
FileContainers unsaved{{{TESTDATA_DIR, "query_simplefunction.h"},
|
||||||
@@ -98,7 +99,7 @@ protected:
|
|||||||
UsedMacros usedMacros{{"Foo", {1, 1}}};
|
UsedMacros usedMacros{{"Foo", {1, 1}}};
|
||||||
FileStatuses fileStatus{{{1, 2}, 3, 4}};
|
FileStatuses fileStatus{{{1, 2}, 3, 4}};
|
||||||
SourceDependencies sourceDependencies{{{1, 1}, {1, 2}}, {{1, 1}, {1, 3}}};
|
SourceDependencies sourceDependencies{{{1, 1}, {1, 2}}, {{1, 1}, {1, 3}}};
|
||||||
ClangBackEnd::ProjectPartArtefact artefact{{"-DFOO"}, {"FOO"}, 74};
|
ClangBackEnd::ProjectPartArtefact artefact{"[-DFOO]", "{\"FOO\":\"1\"}", 74};
|
||||||
NiceMock<MockSqliteTransactionBackend> mockSqliteTransactionBackend;
|
NiceMock<MockSqliteTransactionBackend> mockSqliteTransactionBackend;
|
||||||
NiceMock<MockSymbolsCollector> mockCollector;
|
NiceMock<MockSymbolsCollector> mockCollector;
|
||||||
NiceMock<MockSymbolStorage> mockStorage;
|
NiceMock<MockSymbolStorage> mockStorage;
|
||||||
@@ -177,10 +178,10 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartsInStorage)
|
|||||||
{
|
{
|
||||||
EXPECT_CALL(mockStorage, insertOrUpdateProjectPart(Eq("project1"),
|
EXPECT_CALL(mockStorage, insertOrUpdateProjectPart(Eq("project1"),
|
||||||
ElementsAre("-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"),
|
ElementsAre("-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"),
|
||||||
ElementsAre("DEFINE")));
|
ElementsAre(CompilerMacro{"DEFINE", "1"})));
|
||||||
EXPECT_CALL(mockStorage, insertOrUpdateProjectPart(Eq("project2"),
|
EXPECT_CALL(mockStorage, insertOrUpdateProjectPart(Eq("project2"),
|
||||||
ElementsAre("-I", TESTDATA_DIR, "-x", "c++-header", "-Wno-pragma-once-outside-header"),
|
ElementsAre("-I", TESTDATA_DIR, "-x", "c++-header", "-Wno-pragma-once-outside-header"),
|
||||||
ElementsAre("DEFINE")));
|
ElementsAre(CompilerMacro{"DEFINE", "1"})));
|
||||||
|
|
||||||
indexer.updateProjectParts({projectPart1, projectPart2}, Utils::clone(unsaved));
|
indexer.updateProjectParts({projectPart1, projectPart2}, Utils::clone(unsaved));
|
||||||
}
|
}
|
||||||
@@ -227,7 +228,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrder)
|
|||||||
EXPECT_CALL(mockCollector, collectSymbols());
|
EXPECT_CALL(mockCollector, collectSymbols());
|
||||||
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
|
||||||
EXPECT_CALL(mockStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
|
EXPECT_CALL(mockStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations));
|
||||||
EXPECT_CALL(mockStorage, insertOrUpdateProjectPart(Eq(projectPart1.projectPartId()), Eq(projectPart1.arguments()), Eq(projectPart1.macroNames())));
|
EXPECT_CALL(mockStorage, insertOrUpdateProjectPart(Eq(projectPart1.projectPartId()), Eq(projectPart1.arguments()), Eq(projectPart1.compilerMacros())));
|
||||||
EXPECT_CALL(mockStorage, updateProjectPartSources(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId()), Eq(sourceFileIds)));
|
EXPECT_CALL(mockStorage, updateProjectPartSources(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId()), Eq(sourceFileIds)));
|
||||||
EXPECT_CALL(mockStorage, insertOrUpdateUsedMacros(Eq(usedMacros)));
|
EXPECT_CALL(mockStorage, insertOrUpdateUsedMacros(Eq(usedMacros)));
|
||||||
EXPECT_CALL(mockStorage, insertFileStatuses(Eq(fileStatus)));
|
EXPECT_CALL(mockStorage, insertFileStatuses(Eq(fileStatus)));
|
||||||
|
@@ -87,7 +87,7 @@ protected:
|
|||||||
PathString main1Path = TESTDATA_DIR "/symbolindexing_main1.cpp";
|
PathString main1Path = TESTDATA_DIR "/symbolindexing_main1.cpp";
|
||||||
ProjectPartContainer projectPart1{"project1",
|
ProjectPartContainer projectPart1{"project1",
|
||||||
{"cc", "-I", TESTDATA_DIR, "-std=c++1z"},
|
{"cc", "-I", TESTDATA_DIR, "-std=c++1z"},
|
||||||
{"DEFINE"},
|
{{"DEFINE", "1"}},
|
||||||
{},
|
{},
|
||||||
{filePathId(main1Path)}};
|
{filePathId(main1Path)}};
|
||||||
};
|
};
|
||||||
|
@@ -85,12 +85,12 @@ protected:
|
|||||||
MockSqliteWriteStatement &syncNewSourceDependenciesStatement = statementFactory.syncNewSourceDependenciesStatement;
|
MockSqliteWriteStatement &syncNewSourceDependenciesStatement = statementFactory.syncNewSourceDependenciesStatement;
|
||||||
MockSqliteWriteStatement &deleteOutdatedSourceDependenciesStatement = statementFactory.deleteOutdatedSourceDependenciesStatement;
|
MockSqliteWriteStatement &deleteOutdatedSourceDependenciesStatement = statementFactory.deleteOutdatedSourceDependenciesStatement;
|
||||||
MockSqliteWriteStatement &deleteNewSourceDependenciesStatement = statementFactory.deleteNewSourceDependenciesStatement;
|
MockSqliteWriteStatement &deleteNewSourceDependenciesStatement = statementFactory.deleteNewSourceDependenciesStatement;
|
||||||
MockSqliteReadStatement &getProjectPartCompilerArgumentsAndMacroNames = statementFactory.getProjectPartCompilerArgumentsAndMacroNames;
|
MockSqliteReadStatement &getProjectPartCompilerArgumentsAndCompilerMacrosBySourceId = statementFactory.getProjectPartCompilerArgumentsAndCompilerMacrosBySourceId;
|
||||||
SymbolEntries symbolEntries{{1, {"functionUSR", "function"}},
|
SymbolEntries symbolEntries{{1, {"functionUSR", "function"}},
|
||||||
{2, {"function2USR", "function2"}}};
|
{2, {"function2USR", "function2"}}};
|
||||||
SourceLocationEntries sourceLocations{{1, {1, 3}, {42, 23}, SymbolType::Declaration},
|
SourceLocationEntries sourceLocations{{1, {1, 3}, {42, 23}, SymbolType::Declaration},
|
||||||
{2, {1, 4}, {7, 11}, SymbolType::Declaration}};
|
{2, {1, 4}, {7, 11}, SymbolType::Declaration}};
|
||||||
ClangBackEnd::ProjectPartArtefact artefact{{"-DFOO"}, {"FOO"}, 74};
|
ClangBackEnd::ProjectPartArtefact artefact{"-DFOO", "{\"FOO\":\"1\"}", 74};
|
||||||
Storage storage{statementFactory, filePathCache};
|
Storage storage{statementFactory, filePathCache};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -189,10 +189,10 @@ TEST_F(SymbolStorage, InsertProjectPart)
|
|||||||
EXPECT_CALL(insertProjectPartStatement,
|
EXPECT_CALL(insertProjectPartStatement,
|
||||||
write(TypedEq<Utils::SmallStringView>("project"),
|
write(TypedEq<Utils::SmallStringView>("project"),
|
||||||
TypedEq<Utils::SmallStringView>("[\"foo\"]"),
|
TypedEq<Utils::SmallStringView>("[\"foo\"]"),
|
||||||
TypedEq<Utils::SmallStringView>("[\"FOO\"]")));
|
TypedEq<Utils::SmallStringView>("{\"FOO\":\"1\"}")));
|
||||||
EXPECT_CALL(mockDatabase, lastInsertedRowId());
|
EXPECT_CALL(mockDatabase, lastInsertedRowId());
|
||||||
|
|
||||||
storage.insertOrUpdateProjectPart("project", {"foo"}, {"FOO"});
|
storage.insertOrUpdateProjectPart("project", {"foo"}, {{"FOO", "1"}});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SymbolStorage, UpdateProjectPart)
|
TEST_F(SymbolStorage, UpdateProjectPart)
|
||||||
@@ -204,14 +204,14 @@ TEST_F(SymbolStorage, UpdateProjectPart)
|
|||||||
EXPECT_CALL(insertProjectPartStatement,
|
EXPECT_CALL(insertProjectPartStatement,
|
||||||
write(TypedEq<Utils::SmallStringView>("project"),
|
write(TypedEq<Utils::SmallStringView>("project"),
|
||||||
TypedEq<Utils::SmallStringView>("[\"foo\"]"),
|
TypedEq<Utils::SmallStringView>("[\"foo\"]"),
|
||||||
TypedEq<Utils::SmallStringView>("[\"FOO\"]")));
|
TypedEq<Utils::SmallStringView>("{\"FOO\":\"1\"}")));
|
||||||
EXPECT_CALL(mockDatabase, lastInsertedRowId());
|
EXPECT_CALL(mockDatabase, lastInsertedRowId());
|
||||||
EXPECT_CALL(updateProjectPartStatement,
|
EXPECT_CALL(updateProjectPartStatement,
|
||||||
write(TypedEq<Utils::SmallStringView>("[\"foo\"]"),
|
write(TypedEq<Utils::SmallStringView>("[\"foo\"]"),
|
||||||
TypedEq<Utils::SmallStringView>("[\"FOO\"]"),
|
TypedEq<Utils::SmallStringView>("{\"FOO\":\"1\"}"),
|
||||||
TypedEq<Utils::SmallStringView>("project")));
|
TypedEq<Utils::SmallStringView>("project")));
|
||||||
|
|
||||||
storage.insertOrUpdateProjectPart("project", {"foo"}, {"FOO"});
|
storage.insertOrUpdateProjectPart("project", {"foo"}, {{"FOO", "1"}});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SymbolStorage, UpdateProjectPartSources)
|
TEST_F(SymbolStorage, UpdateProjectPartSources)
|
||||||
@@ -260,17 +260,17 @@ TEST_F(SymbolStorage, InsertOrUpdateSourceDependencies)
|
|||||||
storage.insertOrUpdateSourceDependencies({{{1, 42}, {1, 1}}, {{1, 42}, {1, 2}}});
|
storage.insertOrUpdateSourceDependencies({{{1, 42}, {1, 1}}, {{1, 42}, {1, 2}}});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SymbolStorage, FetchProjectPartArtefactCallsValueInStatement)
|
TEST_F(SymbolStorage, FetchProjectPartArtefactBySourceIdCallsValueInStatement)
|
||||||
{
|
{
|
||||||
EXPECT_CALL(getProjectPartCompilerArgumentsAndMacroNames, valueReturnProjectPartArtefact(1))
|
EXPECT_CALL(getProjectPartCompilerArgumentsAndCompilerMacrosBySourceId, valueReturnProjectPartArtefact(1))
|
||||||
.WillRepeatedly(Return(artefact));
|
.WillRepeatedly(Return(artefact));
|
||||||
|
|
||||||
storage.fetchProjectPartArtefact({2, 1});
|
storage.fetchProjectPartArtefact({2, 1});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SymbolStorage, FetchProjectPartArtefactReturnArtefact)
|
TEST_F(SymbolStorage, FetchProjectPartArtefactBySourceIdReturnArtefact)
|
||||||
{
|
{
|
||||||
EXPECT_CALL(getProjectPartCompilerArgumentsAndMacroNames, valueReturnProjectPartArtefact(1))
|
EXPECT_CALL(getProjectPartCompilerArgumentsAndCompilerMacrosBySourceId, valueReturnProjectPartArtefact(1))
|
||||||
.WillRepeatedly(Return(artefact));
|
.WillRepeatedly(Return(artefact));
|
||||||
|
|
||||||
auto result = storage.fetchProjectPartArtefact({2, 1});
|
auto result = storage.fetchProjectPartArtefact({2, 1});
|
||||||
|
Reference in New Issue
Block a user