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:
Marco Bubke
2018-02-06 19:03:14 +01:00
parent 07fcd6f362
commit 56f79feebf
27 changed files with 251 additions and 77 deletions

View File

@@ -205,6 +205,7 @@ HEADERS += \
$$PWD/baseserverproxy.h \
$$PWD/filepath.h \
$$PWD/nativefilepath.h \
$$PWD/filepathview.h
$$PWD/filepathview.h \
$$PWD/compilermacro.h
contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols

View 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>;
}

View File

@@ -27,7 +27,8 @@
#include "clangsupport_global.h"
#include <filepathid.h>
#include "compilermacro.h"
#include "filepathid.h"
#include <utils/smallstringio.h>
@@ -40,12 +41,12 @@ public:
ProjectPartContainer() = default;
ProjectPartContainer(Utils::SmallString &&projectPartId,
Utils::SmallStringVector &&arguments,
Utils::SmallStringVector &&macroNames,
CompilerMacros &&compilerMacros,
FilePathIds &&headerPathIds,
FilePathIds &&sourcePathIds)
: m_projectPartId(std::move(projectPartId)),
m_arguments(std::move(arguments)),
m_macroNames(std::move(macroNames)),
m_compilerMacros(std::move(compilerMacros)),
m_headerPathIds(std::move(headerPathIds)),
m_sourcePathIds(std::move(sourcePathIds))
{
@@ -66,9 +67,9 @@ public:
return std::move(m_arguments);
}
const Utils::SmallStringVector &macroNames() const
const CompilerMacros &compilerMacros() const
{
return m_macroNames;
return m_compilerMacros;
}
const FilePathIds &sourcePathIds() const
@@ -85,7 +86,7 @@ public:
{
out << container.m_projectPartId;
out << container.m_arguments;
out << container.m_macroNames;
out << container.m_compilerMacros;
out << container.m_headerPathIds;
out << container.m_sourcePathIds;
@@ -96,7 +97,7 @@ public:
{
in >> container.m_projectPartId;
in >> container.m_arguments;
in >> container.m_macroNames;
in >> container.m_compilerMacros;
in >> container.m_headerPathIds;
in >> container.m_sourcePathIds;
@@ -107,7 +108,7 @@ public:
{
return first.m_projectPartId == second.m_projectPartId
&& 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_sourcePathIds == second.m_sourcePathIds;
}
@@ -116,12 +117,12 @@ public:
{
return std::tie(first.m_projectPartId,
first.m_arguments,
first.m_macroNames,
first.m_compilerMacros,
first.m_headerPathIds,
first.m_sourcePathIds)
< std::tie(second.m_projectPartId,
second.m_arguments,
second.m_macroNames,
second.m_compilerMacros,
second.m_headerPathIds,
second.m_sourcePathIds);
}
@@ -134,7 +135,7 @@ public:
private:
Utils::SmallString m_projectPartId;
Utils::SmallStringVector m_arguments;
Utils::SmallStringVector m_macroNames;
CompilerMacros m_compilerMacros;
FilePathIds m_headerPathIds;
FilePathIds m_sourcePathIds;
};

View File

@@ -115,7 +115,7 @@ public:
table.addColumn("projectPartId", Sqlite::ColumnType::Integer, Sqlite::Contraint::PrimaryKey);
const Sqlite::Column &projectPartNameColumn = table.addColumn("projectPartName", 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.initialize(database);

View File

@@ -121,11 +121,11 @@ QStringList ProjectUpdater::compilerArguments(CppTools::ProjectPart *projectPart
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 &macro) {
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,
Utils::SmallStringVector(arguments),
createMacroNames(projectPart),
createCompilerMacros(projectPart),
std::move(headerAndSources.headers),
std::move(headerAndSources.sources));
}

View File

@@ -27,6 +27,7 @@
#include "clangpchmanager_global.h"
#include <compilermacro.h>
#include <filecontainerv2.h>
#include <filepathcachinginterface.h>
@@ -73,7 +74,7 @@ unittest_public:
void addToHeaderAndSources(HeaderAndSources &headerAndSources,
const CppTools::ProjectFile &projectFile) const;
static QStringList compilerArguments(CppTools::ProjectPart *projectPart);
static Utils::SmallStringVector createMacroNames(CppTools::ProjectPart *projectPart);
static ClangBackEnd::CompilerMacros createCompilerMacros(CppTools::ProjectPart *projectPart);
static Utils::PathStringVector createExcludedPaths(
const ClangBackEnd::V2::FileContainers &generatedFiles);

View File

@@ -28,8 +28,11 @@
#include <utils/algorithm.h>
#include <utils/smallstringvector.h>
#include <compilermacro.h>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
namespace ClangBackEnd {
@@ -37,16 +40,16 @@ class ProjectPartArtefact
{
public:
ProjectPartArtefact(Utils::SmallStringView compilerArgumentsText,
Utils::SmallStringView macroNamesText,
Utils::SmallStringView compilerMacrosText,
int projectPartId)
: compilerArguments(toVector(compilerArgumentsText)),
macroNames(toVector(macroNamesText)),
: compilerArguments(toStringVector(compilerArgumentsText)),
compilerMacros(toCompilerMacros(compilerMacrosText)),
projectPartId(projectPartId)
{
}
static
Utils::SmallStringVector toVector(Utils::SmallStringView jsonText)
Utils::SmallStringVector toStringVector(Utils::SmallStringView jsonText)
{
QJsonDocument document = QJsonDocument::fromJson(QByteArray::fromRawData(jsonText.data(),
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
bool operator==(const ProjectPartArtefact &first, const ProjectPartArtefact &second)
{
return first.compilerArguments == second.compilerArguments
&& first.macroNames == second.macroNames;
&& first.compilerMacros == second.compilerMacros;
}
public:
Utils::SmallStringVector compilerArguments;
Utils::SmallStringVector macroNames;
CompilerMacros compilerMacros;
int projectPartId = -1;
};

View File

@@ -158,11 +158,11 @@ public:
database
};
WriteStatement insertProjectPartStatement{
"INSERT OR IGNORE INTO projectParts(projectPartName, compilerArguments, macroNames) VALUES (?,?,?)",
"INSERT OR IGNORE INTO projectParts(projectPartName, compilerArguments, compilerMacros) VALUES (?,?,?)",
database
};
WriteStatement updateProjectPartStatement{
"UPDATE projectParts SET compilerArguments = ?, macroNames = ? WHERE projectPartName = ?",
"UPDATE projectParts SET compilerArguments = ?, compilerMacros = ? WHERE projectPartName = ?",
database
};
ReadStatement getProjectPartIdStatement{
@@ -217,8 +217,8 @@ public:
"DELETE FROM newSourceDependencies",
database
};
ReadStatement getProjectPartCompilerArgumentsAndMacroNames{
"SELECT compilerArguments, macroNames, projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)",
ReadStatement getProjectPartCompilerArgumentsAndCompilerMacrosBySourceId{
"SELECT compilerArguments, compilerMacros, projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)",
database
};
};

View File

@@ -65,7 +65,7 @@ void SymbolIndexer::updateProjectPart(V2::ProjectPartContainer &&projectPart,
m_symbolStorage.insertOrUpdateProjectPart(projectPart.projectPartId(),
projectPart.arguments(),
projectPart.macroNames());
projectPart.compilerMacros());
m_symbolStorage.updateProjectPartSources(projectPart.projectPartId(),
m_symbolsCollector.sourceFiles());

View File

@@ -31,8 +31,9 @@
#include <sqlitetransaction.h>
#include <filepathcachingfwd.h>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
namespace ClangBackEnd {
@@ -67,25 +68,25 @@ public:
void insertOrUpdateProjectPart(Utils::SmallStringView projectPartName,
const Utils::SmallStringVector &commandLineArguments,
const Utils::SmallStringVector &macroNames) override
const CompilerMacros &compilerMacros) override
{
m_statementFactory.database.setLastInsertedRowId(-1);
Utils::SmallString compilerArguementsAsJson = toJson(commandLineArguments);
Utils::SmallString macroNamesAsJson = toJson(macroNames);
Utils::SmallString compilerMacrosAsJson = toJson(compilerMacros);
WriteStatement &insertStatement = m_statementFactory.insertProjectPartStatement;
insertStatement.write(projectPartName, compilerArguementsAsJson, macroNamesAsJson);
insertStatement.write(projectPartName, compilerArguementsAsJson, compilerMacrosAsJson);
if (m_statementFactory.database.lastInsertedRowId() == -1) {
WriteStatement &updateStatement = m_statementFactory.updateProjectPartStatement;
updateStatement.write(compilerArguementsAsJson, macroNamesAsJson, projectPartName);
updateStatement.write(compilerArguementsAsJson, compilerMacrosAsJson, projectPartName);
}
}
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);
}
@@ -157,6 +158,19 @@ public:
return document.toJson(QJsonDocument::Compact);
}
static Utils::SmallString toJson(const CompilerMacros &compilerMacros)
{
QJsonDocument document;
QJsonObject object;
for (const CompilerMacro &macro : compilerMacros)
object.insert(QString(macro.key), QString(macro.value));
document.setObject(object);
return document.toJson(QJsonDocument::Compact);
}
void fillTemporarySymbolsTable(const SymbolEntries &symbolEntries)
{
WriteStatement &statement = m_statementFactory.insertSymbolsToNewSymbolsStatement;

View File

@@ -35,6 +35,8 @@
#include <sqlitetransaction.h>
#include <compilermacro.h>
namespace ClangBackEnd {
class SymbolStorageInterface
@@ -49,7 +51,7 @@ public:
const SourceLocationEntries &sourceLocations) = 0;
virtual void insertOrUpdateProjectPart(Utils::SmallStringView projectPartName,
const Utils::SmallStringVector &commandLineArguments,
const Utils::SmallStringVector &macroNames) = 0;
const CompilerMacros &compilerMacros) = 0;
virtual void updateProjectPartSources(Utils::SmallStringView projectPartName,
const FilePathIds &sourceFilePathIds) = 0;
virtual void updateProjectPartSources(int projectPartId,

View File

@@ -887,10 +887,18 @@ std::ostream &operator<<(std::ostream &out, const ProjectPartArtefact &projectPa
{
return out << "("
<< projectPartArtefact.compilerArguments << ", "
<< projectPartArtefact.macroNames
<< projectPartArtefact.compilerMacros
<<")";
}
std::ostream &operator<<(std::ostream &out, const CompilerMacro &compilerMacro)
{
return out << "("
<< compilerMacro.key << ", "
<< compilerMacro.value
<< ")";
}
void PrintTo(const FilePath &filePath, ::std::ostream *os)
{
*os << filePath;

View File

@@ -155,6 +155,7 @@ class UsedMacro;
class FileStatus;
class SourceDependency;
class ProjectPartArtefact;
class CompilerMacro;
std::ostream &operator<<(std::ostream &out, const SourceLocationEntry &entry);
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 SourceDependency &sourceDependency);
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 FilePathView &filePathView, ::std::ostream *os);

View File

@@ -40,7 +40,7 @@ public:
MOCK_METHOD3(insertOrUpdateProjectPart,
void(Utils::SmallStringView projectPartName,
const Utils::SmallStringVector &commandLineArgument,
const Utils::SmallStringVector &macroNames));
const ClangBackEnd::CompilerMacros &compilerMacros));
MOCK_METHOD2(updateProjectPartSources,
void(Utils::SmallStringView projectPartName,
const ClangBackEnd::FilePathIds &sourceFilePathIds));

View File

@@ -74,12 +74,12 @@ protected:
FilePath generatedFilePath = TESTDATA_DIR "/includecollector_generated_file.h";
ProjectPartContainer projectPart1{"project1",
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
{"DEFINE"},
{{"DEFINE", "1"}},
{id(header1Path)},
{id(main1Path)}};
ProjectPartContainer projectPart2{"project2",
{"-I", TESTDATA_DIR, "-x", "c++-header", "-Wno-pragma-once-outside-header"},
{"DEFINE"},
{{"DEFINE", "1"}},
{id(header2Path)},
{id(main2Path)}};
TestEnvironment environment;

View File

@@ -94,7 +94,7 @@ TEST_F(PchManagerClientServerInProcess, SendUpdatePchProjectPartsMessage)
{
ProjectPartContainer projectPart2{"projectPartId",
{"-x", "c++-header", "-Wno-pragma-once-outside-header"},
{"DEFINE"},
{{"DEFINE", "1"}},
{{1, 1}},
{{1, 2}}};
FileContainer fileContainer{{"/path/to/", "file"}, "content", {}};

View File

@@ -70,12 +70,12 @@ protected:
std::vector<ClangBackEnd::IdPaths> idPaths = {{projectPartId1, {{1, 1}, {1, 2}}}};
ProjectPartContainer projectPart1{projectPartId1.clone(),
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
{"DEFINE"},
{{"DEFINE", "1"}},
{id(header1Path)},
{id(main1Path)}};
ProjectPartContainer projectPart2{projectPartId2.clone(),
{"-x", "c++-header", "-Wno-pragma-once-outside-header"},
{"DEFINE"},
{{"DEFINE", "1"}},
{id(header2Path)},
{id(main2Path)}};
std::vector<ProjectPartContainer> projectParts{projectPart1, projectPart2};

View 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"})));
}
}

View File

@@ -49,17 +49,17 @@ protected:
FilePathId thirdSource{1, 13};
ProjectPartContainer projectPartContainer1{"id",
{"-DUNIX", "-O2"},
{"UNIX"},
{{"DEFINE", "1"}},
{firstHeader, secondHeader},
{firstSource, secondSource}};
ProjectPartContainer updatedProjectPartContainer1{"id",
{"-DUNIX", "-O2"},
{"UNIX"},
{{"DEFINE", "1"}},
{firstHeader, secondHeader},
{firstSource, secondSource, thirdSource}};
ProjectPartContainer projectPartContainer2{"id2",
{"-DUNIX", "-O2"},
{"UNIX"},
{{"DEFINE", "1"}},
{firstHeader, secondHeader},
{firstSource, secondSource}};
};

View File

@@ -77,14 +77,14 @@ protected:
projectPart.files.push_back(source1ProjectFile);
projectPart.files.push_back(source2ProjectFile);
projectPart.displayName = QString(projectPartId);
projectPart.projectMacros.push_back({"DEFINE"});
projectPart.projectMacros.push_back({"DEFINE", "1"});
Utils::SmallStringVector arguments{ClangPchManager::ProjectUpdater::compilerArguments(
&projectPart)};
expectedContainer = {projectPartId.clone(),
arguments.clone(),
macroNames.clone(),
Utils::clone(compilerMacros),
{filePathId(headerPaths[1])},
{filePathIds(sourcePaths)}};
}
@@ -101,7 +101,7 @@ protected:
Utils::SmallString projectPartId2{"project2"};
Utils::PathStringVector headerPaths = {"/path/to/header1.h", "/path/to/header2.h"};
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 header2ProjectFile{QString(headerPaths[1]), CppTools::ProjectFile::CXXHeader};
CppTools::ProjectFile source1ProjectFile{QString(sourcePaths[0]), CppTools::ProjectFile::CXXSource};

View File

@@ -178,7 +178,7 @@ TEST_F(RefactoringClientServerInProcess, SendUpdatePchProjectPartsMessage)
{
ProjectPartContainer projectPart2{"projectPartId",
{"-x", "c++-header", "-Wno-pragma-once-outside-header"},
{"DEFINE"},
{{"DEFINE", "1"}},
{{1, 1}},
{{1, 2}}};
FileContainer fileContainer{{"/path/to/", "file"}, "content", {}};

View File

@@ -86,7 +86,7 @@ TEST_F(RefactoringDatabaseInitializer, AddProjectPartsTable)
{
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)")));
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 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 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 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)")));

View File

@@ -301,7 +301,7 @@ TEST_F(RefactoringServer, UpdatePchProjectPartsCallsSymbolIndexingUpdateProjectP
{
ProjectPartContainers projectParts{{{"projectPartId",
{"-I", TESTDATA_DIR},
{"DEFINE"},
{{"DEFINE", "1"}},
{filePathId("header1.h")},
{filePathId("main.cpp")}}}};
FileContainers unsaved{{{TESTDATA_DIR, "query_simplefunction.h"},

View File

@@ -169,13 +169,13 @@ TEST_F(StorageSqliteStatementFactory, DeleteNewLocationsTableStatement)
TEST_F(StorageSqliteStatementFactory, InsertProjectPart)
{
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)
{
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)
@@ -256,10 +256,10 @@ TEST_F(StorageSqliteStatementFactory, DeleteAllInNewSourceDependencies)
Eq("DELETE FROM newSourceDependencies"));
}
TEST_F(StorageSqliteStatementFactory, GetProjectPartCompilerArgumentsAndMacroNames)
TEST_F(StorageSqliteStatementFactory, GetProjectPartCompilerArgumentsAndCompilerMacrosBySourceId)
{
ASSERT_THAT(factory.getProjectPartCompilerArgumentsAndMacroNames.sqlStatement,
Eq("SELECT compilerArguments, macroNames, projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)"));
ASSERT_THAT(factory.getProjectPartCompilerArgumentsAndCompilerMacrosBySourceId.sqlStatement,
Eq("SELECT compilerArguments, compilerMacros, projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)"));
}
}

View File

@@ -37,6 +37,7 @@
namespace {
using Utils::PathString;
using ClangBackEnd::CompilerMacro;
using ClangBackEnd::FileStatuses;
using ClangBackEnd::FilePathIds;
using ClangBackEnd::FilePathView;
@@ -81,12 +82,12 @@ protected:
ClangBackEnd::FilePathId generatedFilePathId{1, 21};
ProjectPartContainer projectPart1{"project1",
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
{"DEFINE"},
{{"DEFINE", "1"}},
{header1PathId},
{main1PathId}};
ProjectPartContainer projectPart2{"project2",
{"-I", TESTDATA_DIR, "-x", "c++-header", "-Wno-pragma-once-outside-header"},
{"DEFINE"},
{{"DEFINE", "1"}},
{header2PathId},
{main2PathId}};
FileContainers unsaved{{{TESTDATA_DIR, "query_simplefunction.h"},
@@ -98,7 +99,7 @@ protected:
UsedMacros usedMacros{{"Foo", {1, 1}}};
FileStatuses fileStatus{{{1, 2}, 3, 4}};
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<MockSymbolsCollector> mockCollector;
NiceMock<MockSymbolStorage> mockStorage;
@@ -177,10 +178,10 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartsInStorage)
{
EXPECT_CALL(mockStorage, insertOrUpdateProjectPart(Eq("project1"),
ElementsAre("-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"),
ElementsAre("DEFINE")));
ElementsAre(CompilerMacro{"DEFINE", "1"})));
EXPECT_CALL(mockStorage, insertOrUpdateProjectPart(Eq("project2"),
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));
}
@@ -227,7 +228,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrder)
EXPECT_CALL(mockCollector, collectSymbols());
EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin());
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, insertOrUpdateUsedMacros(Eq(usedMacros)));
EXPECT_CALL(mockStorage, insertFileStatuses(Eq(fileStatus)));

View File

@@ -87,7 +87,7 @@ protected:
PathString main1Path = TESTDATA_DIR "/symbolindexing_main1.cpp";
ProjectPartContainer projectPart1{"project1",
{"cc", "-I", TESTDATA_DIR, "-std=c++1z"},
{"DEFINE"},
{{"DEFINE", "1"}},
{},
{filePathId(main1Path)}};
};

View File

@@ -85,12 +85,12 @@ protected:
MockSqliteWriteStatement &syncNewSourceDependenciesStatement = statementFactory.syncNewSourceDependenciesStatement;
MockSqliteWriteStatement &deleteOutdatedSourceDependenciesStatement = statementFactory.deleteOutdatedSourceDependenciesStatement;
MockSqliteWriteStatement &deleteNewSourceDependenciesStatement = statementFactory.deleteNewSourceDependenciesStatement;
MockSqliteReadStatement &getProjectPartCompilerArgumentsAndMacroNames = statementFactory.getProjectPartCompilerArgumentsAndMacroNames;
MockSqliteReadStatement &getProjectPartCompilerArgumentsAndCompilerMacrosBySourceId = statementFactory.getProjectPartCompilerArgumentsAndCompilerMacrosBySourceId;
SymbolEntries symbolEntries{{1, {"functionUSR", "function"}},
{2, {"function2USR", "function2"}}};
SourceLocationEntries sourceLocations{{1, {1, 3}, {42, 23}, 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};
};
@@ -189,10 +189,10 @@ TEST_F(SymbolStorage, InsertProjectPart)
EXPECT_CALL(insertProjectPartStatement,
write(TypedEq<Utils::SmallStringView>("project"),
TypedEq<Utils::SmallStringView>("[\"foo\"]"),
TypedEq<Utils::SmallStringView>("[\"FOO\"]")));
TypedEq<Utils::SmallStringView>("{\"FOO\":\"1\"}")));
EXPECT_CALL(mockDatabase, lastInsertedRowId());
storage.insertOrUpdateProjectPart("project", {"foo"}, {"FOO"});
storage.insertOrUpdateProjectPart("project", {"foo"}, {{"FOO", "1"}});
}
TEST_F(SymbolStorage, UpdateProjectPart)
@@ -204,14 +204,14 @@ TEST_F(SymbolStorage, UpdateProjectPart)
EXPECT_CALL(insertProjectPartStatement,
write(TypedEq<Utils::SmallStringView>("project"),
TypedEq<Utils::SmallStringView>("[\"foo\"]"),
TypedEq<Utils::SmallStringView>("[\"FOO\"]")));
TypedEq<Utils::SmallStringView>("{\"FOO\":\"1\"}")));
EXPECT_CALL(mockDatabase, lastInsertedRowId());
EXPECT_CALL(updateProjectPartStatement,
write(TypedEq<Utils::SmallStringView>("[\"foo\"]"),
TypedEq<Utils::SmallStringView>("[\"FOO\"]"),
TypedEq<Utils::SmallStringView>("{\"FOO\":\"1\"}"),
TypedEq<Utils::SmallStringView>("project")));
storage.insertOrUpdateProjectPart("project", {"foo"}, {"FOO"});
storage.insertOrUpdateProjectPart("project", {"foo"}, {{"FOO", "1"}});
}
TEST_F(SymbolStorage, UpdateProjectPartSources)
@@ -260,17 +260,17 @@ TEST_F(SymbolStorage, InsertOrUpdateSourceDependencies)
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));
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));
auto result = storage.fetchProjectPartArtefact({2, 1});