forked from qt-creator/qt-creator
ClangPchManager: Add UsedMacroFilter
The compiler macros are filtered in system and project macros. Not used ones are removed. The original order of the macros is retained. Task-number: QTCREATORBUG-21548 Change-Id: Ic9265866bde033e6a9600f9e6439b1697ab73422 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -36,10 +36,10 @@ class CompilerMacro
|
|||||||
public:
|
public:
|
||||||
constexpr CompilerMacro() = default;
|
constexpr CompilerMacro() = default;
|
||||||
|
|
||||||
CompilerMacro(Utils::SmallString &&key,
|
CompilerMacro(Utils::SmallString &&key, Utils::SmallString &&value, int index)
|
||||||
Utils::SmallString &&value)
|
: key(std::move(key))
|
||||||
: key(std::move(key)),
|
, value(std::move(value))
|
||||||
value(std::move(value))
|
, index(index)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
friend QDataStream &operator<<(QDataStream &out, const CompilerMacro &compilerMacro)
|
friend QDataStream &operator<<(QDataStream &out, const CompilerMacro &compilerMacro)
|
||||||
@@ -72,6 +72,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
Utils::SmallString key;
|
Utils::SmallString key;
|
||||||
Utils::SmallString value;
|
Utils::SmallString value;
|
||||||
|
int index = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
using CompilerMacros = std::vector<CompilerMacro>;
|
using CompilerMacros = std::vector<CompilerMacro>;
|
||||||
|
|||||||
@@ -156,10 +156,11 @@ QStringList ProjectUpdater::compilerArguments(CppTools::ProjectPart *projectPart
|
|||||||
|
|
||||||
ClangBackEnd::CompilerMacros ProjectUpdater::createCompilerMacros(const ProjectExplorer::Macros &projectMacros)
|
ClangBackEnd::CompilerMacros ProjectUpdater::createCompilerMacros(const ProjectExplorer::Macros &projectMacros)
|
||||||
{
|
{
|
||||||
auto macros = Utils::transform<ClangBackEnd::CompilerMacros>(projectMacros,
|
int index = 0;
|
||||||
[] (const ProjectExplorer::Macro ¯o) {
|
auto macros = Utils::transform<ClangBackEnd::CompilerMacros>(
|
||||||
return ClangBackEnd::CompilerMacro{macro.key, macro.value};
|
projectMacros, [&](const ProjectExplorer::Macro ¯o) {
|
||||||
});
|
return ClangBackEnd::CompilerMacro{macro.key, macro.value, ++index};
|
||||||
|
});
|
||||||
|
|
||||||
std::sort(macros.begin(), macros.end());
|
std::sort(macros.begin(), macros.end());
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ HEADERS += \
|
|||||||
$$PWD/modifiedtimecheckerinterface.h \
|
$$PWD/modifiedtimecheckerinterface.h \
|
||||||
$$PWD/sourceentry.h \
|
$$PWD/sourceentry.h \
|
||||||
$$PWD/builddependenciesstorage.h \
|
$$PWD/builddependenciesstorage.h \
|
||||||
$$PWD/builddependencygeneratorinterface.h
|
$$PWD/builddependencygeneratorinterface.h \
|
||||||
|
$$PWD/usedmacrofilter.h
|
||||||
|
|
||||||
!isEmpty(LIBTOOLING_LIBS) {
|
!isEmpty(LIBTOOLING_LIBS) {
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
|||||||
@@ -117,9 +117,11 @@ public:
|
|||||||
sourceType = SourceType::SystemInclude;
|
sourceType = SourceType::SystemInclude;
|
||||||
else
|
else
|
||||||
sourceType = SourceType::TopSystemInclude;
|
sourceType = SourceType::TopSystemInclude;
|
||||||
} else if (isNotInExcludedIncludeUID(fileUID)
|
} else if (isNotInExcludedIncludeUID(fileUID)) {
|
||||||
&& isInExcludedIncludeUID(sourceFileUID)) {
|
if (isInExcludedIncludeUID(sourceFileUID))
|
||||||
sourceType = SourceType::TopInclude;
|
sourceType = SourceType::TopProjectInclude;
|
||||||
|
else
|
||||||
|
sourceType = SourceType::ProjectInclude;
|
||||||
}
|
}
|
||||||
|
|
||||||
addInclude({includeId, sourceType, lastModified});
|
addInclude({includeId, sourceType, lastModified});
|
||||||
|
|||||||
@@ -398,7 +398,7 @@ FilePathIds PchCreator::topIncludeIds(const SourceEntries &includes)
|
|||||||
topIncludes.reserve(includes.size());
|
topIncludes.reserve(includes.size());
|
||||||
|
|
||||||
for (SourceEntry include : includes) {
|
for (SourceEntry include : includes) {
|
||||||
if (include.sourceType == SourceType::TopInclude)
|
if (include.sourceType == SourceType::TopProjectInclude)
|
||||||
topIncludes.push_back(include.sourceId);
|
topIncludes.push_back(include.sourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,9 +33,10 @@ namespace ClangBackEnd {
|
|||||||
|
|
||||||
enum class SourceType : unsigned char
|
enum class SourceType : unsigned char
|
||||||
{
|
{
|
||||||
TopInclude,
|
TopProjectInclude,
|
||||||
TopSystemInclude,
|
TopSystemInclude,
|
||||||
UserInclude,
|
UserInclude,
|
||||||
|
ProjectInclude,
|
||||||
SystemInclude
|
SystemInclude
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
194
src/tools/clangpchmanagerbackend/source/usedmacrofilter.h
Normal file
194
src/tools/clangpchmanagerbackend/source/usedmacrofilter.h
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2018 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 "usedmacro.h"
|
||||||
|
#include "sourceentry.h"
|
||||||
|
|
||||||
|
#include <compilermacro.h>
|
||||||
|
|
||||||
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
|
class UsedMacroFilter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct Includes
|
||||||
|
{
|
||||||
|
FilePathIds project;
|
||||||
|
FilePathIds system;
|
||||||
|
};
|
||||||
|
|
||||||
|
UsedMacroFilter(const SourceEntries &includes, const UsedMacros &usedMacros)
|
||||||
|
{
|
||||||
|
Includes filteredIncludes = filterIncludes(includes);
|
||||||
|
m_systemUsedMacros = filterUsedMarcos(usedMacros, filteredIncludes.system);
|
||||||
|
m_projectUsedMacros = filterUsedMarcos(usedMacros, filteredIncludes.project);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Includes filterIncludes(const SourceEntries &includes)
|
||||||
|
{
|
||||||
|
Includes result;
|
||||||
|
result.system.reserve(includes.size());
|
||||||
|
result.project.reserve(includes.size());
|
||||||
|
|
||||||
|
for (SourceEntry include : includes)
|
||||||
|
filterInclude(include, result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Utils::PathStringVector &projectUsedMacros() const { return m_projectUsedMacros; }
|
||||||
|
|
||||||
|
const Utils::PathStringVector &systemUsedMacros() const { return m_systemUsedMacros; }
|
||||||
|
|
||||||
|
const CompilerMacros &projectCompilerMacros() const { return m_projectCompilerMacros; }
|
||||||
|
|
||||||
|
const CompilerMacros &systemCompilerMacros() const { return m_systemCompilerMacros; }
|
||||||
|
|
||||||
|
void filter(const CompilerMacros &compilerMacros)
|
||||||
|
{
|
||||||
|
CompilerMacros indexedCompilerMacro = compilerMacros;
|
||||||
|
|
||||||
|
std::sort(indexedCompilerMacro.begin(),
|
||||||
|
indexedCompilerMacro.end(),
|
||||||
|
[](const CompilerMacro &first, const CompilerMacro &second) {
|
||||||
|
return std::tie(first.key, first.value) < std::tie(second.key, second.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
m_systemCompilerMacros = filtercompilerMacros(indexedCompilerMacro, m_systemUsedMacros);
|
||||||
|
m_projectCompilerMacros = filtercompilerMacros(indexedCompilerMacro, m_projectUsedMacros);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void filterInclude(SourceEntry include, Includes &result)
|
||||||
|
{
|
||||||
|
switch (include.sourceType) {
|
||||||
|
case SourceType::TopSystemInclude:
|
||||||
|
case SourceType::SystemInclude:
|
||||||
|
result.system.emplace_back(include.sourceId);
|
||||||
|
break;
|
||||||
|
case SourceType::TopProjectInclude:
|
||||||
|
case SourceType::ProjectInclude:
|
||||||
|
result.project.emplace_back(include.sourceId);
|
||||||
|
break;
|
||||||
|
case SourceType::UserInclude:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Utils::PathStringVector filterUsedMarcos(const UsedMacros &usedMacros,
|
||||||
|
const FilePathIds &filePathId)
|
||||||
|
{
|
||||||
|
class BackInserterIterator : public std::back_insert_iterator<Utils::PathStringVector>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BackInserterIterator(Utils::PathStringVector &container)
|
||||||
|
: std::back_insert_iterator<Utils::PathStringVector>(container)
|
||||||
|
{}
|
||||||
|
|
||||||
|
BackInserterIterator &operator=(const UsedMacro &usedMacro)
|
||||||
|
{
|
||||||
|
container->push_back(usedMacro.macroName);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
BackInserterIterator &operator*() { return *this; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Compare
|
||||||
|
{
|
||||||
|
bool operator()(const UsedMacro &usedMacro, FilePathId filePathId)
|
||||||
|
{
|
||||||
|
return usedMacro.filePathId < filePathId;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator()(FilePathId filePathId, const UsedMacro &usedMacro)
|
||||||
|
{
|
||||||
|
return filePathId < usedMacro.filePathId;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Utils::PathStringVector filtertedMacros;
|
||||||
|
filtertedMacros.reserve(usedMacros.size());
|
||||||
|
|
||||||
|
std::set_intersection(usedMacros.begin(),
|
||||||
|
usedMacros.end(),
|
||||||
|
filePathId.begin(),
|
||||||
|
filePathId.end(),
|
||||||
|
BackInserterIterator(filtertedMacros),
|
||||||
|
Compare{});
|
||||||
|
|
||||||
|
std::sort(filtertedMacros.begin(), filtertedMacros.end());
|
||||||
|
|
||||||
|
return filtertedMacros;
|
||||||
|
}
|
||||||
|
|
||||||
|
static CompilerMacros filtercompilerMacros(const CompilerMacros &indexedCompilerMacro,
|
||||||
|
const Utils::PathStringVector &usedMacros)
|
||||||
|
{
|
||||||
|
struct Compare
|
||||||
|
{
|
||||||
|
bool operator()(const Utils::PathString &usedMacro,
|
||||||
|
const CompilerMacro &compileMacro)
|
||||||
|
{
|
||||||
|
return usedMacro < compileMacro.key;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator()(const CompilerMacro &compileMacro,
|
||||||
|
const Utils::PathString &usedMacro)
|
||||||
|
{
|
||||||
|
return compileMacro.key < usedMacro;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
CompilerMacros filtertedCompilerMacros;
|
||||||
|
filtertedCompilerMacros.reserve(indexedCompilerMacro.size());
|
||||||
|
|
||||||
|
std::set_intersection(indexedCompilerMacro.begin(),
|
||||||
|
indexedCompilerMacro.end(),
|
||||||
|
usedMacros.begin(),
|
||||||
|
usedMacros.end(),
|
||||||
|
std::back_inserter(filtertedCompilerMacros),
|
||||||
|
Compare{});
|
||||||
|
|
||||||
|
std::sort(filtertedCompilerMacros.begin(),
|
||||||
|
filtertedCompilerMacros.end(),
|
||||||
|
[](const CompilerMacro &first, const CompilerMacro &second) {
|
||||||
|
return first.index < second.index;
|
||||||
|
});
|
||||||
|
|
||||||
|
return filtertedCompilerMacros;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Utils::PathStringVector m_projectUsedMacros;
|
||||||
|
Utils::PathStringVector m_systemUsedMacros;
|
||||||
|
CompilerMacros m_projectCompilerMacros;
|
||||||
|
CompilerMacros m_systemCompilerMacros;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace ClangBackEnd
|
||||||
@@ -62,8 +62,9 @@ CompilerMacros ProjectPartArtefact::createCompilerMacrosFromDocument(const QJson
|
|||||||
CompilerMacros macros;
|
CompilerMacros macros;
|
||||||
macros.reserve(object.size());
|
macros.reserve(object.size());
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
for (auto current = object.constBegin(); current != object.constEnd(); ++current)
|
for (auto current = object.constBegin(); current != object.constEnd(); ++current)
|
||||||
macros.emplace_back(current.key(), current.value().toString());
|
macros.emplace_back(current.key(), current.value().toString(), ++index);
|
||||||
|
|
||||||
std::sort(macros.begin(), macros.end());
|
std::sort(macros.begin(), macros.end());
|
||||||
|
|
||||||
|
|||||||
@@ -65,13 +65,13 @@ protected:
|
|||||||
mockSqliteTransactionBackend};
|
mockSqliteTransactionBackend};
|
||||||
ClangBackEnd::V2::ProjectPartContainer projectPart1{"ProjectPart1",
|
ClangBackEnd::V2::ProjectPartContainer projectPart1{"ProjectPart1",
|
||||||
{"--yi"},
|
{"--yi"},
|
||||||
{{"YI", "1"}},
|
{{"YI", "1", 1}},
|
||||||
{"/yi"},
|
{"/yi"},
|
||||||
{1},
|
{1},
|
||||||
{2}};
|
{2}};
|
||||||
ClangBackEnd::V2::ProjectPartContainer projectPart2{"ProjectPart2",
|
ClangBackEnd::V2::ProjectPartContainer projectPart2{"ProjectPart2",
|
||||||
{"--er"},
|
{"--er"},
|
||||||
{{"ER", "2"}},
|
{{"ER", "2", 1}},
|
||||||
{"/er"},
|
{"/er"},
|
||||||
{1},
|
{1},
|
||||||
{2, 3, 4}};
|
{2, 3, 4}};
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ TEST_F(BuildDependenciesStorage, AddNewSourceDependenciesTable)
|
|||||||
TEST_F(BuildDependenciesStorage, UpdateSources)
|
TEST_F(BuildDependenciesStorage, UpdateSources)
|
||||||
{
|
{
|
||||||
InSequence s;
|
InSequence s;
|
||||||
SourceEntries entries{{1, SourceType::TopInclude, 10}, {2, SourceType::TopSystemInclude, 20}};
|
SourceEntries entries{{1, SourceType::TopProjectInclude, 10}, {2, SourceType::TopSystemInclude, 20}};
|
||||||
|
|
||||||
EXPECT_CALL(updateBuildDependencyTimeStampStatement, write(TypedEq<long long>(10), TypedEq<int>(1)));
|
EXPECT_CALL(updateBuildDependencyTimeStampStatement, write(TypedEq<long long>(10), TypedEq<int>(1)));
|
||||||
EXPECT_CALL(updateSourceTypeStatement, write(TypedEq<uchar>(0), TypedEq<int>(1)));
|
EXPECT_CALL(updateSourceTypeStatement, write(TypedEq<uchar>(0), TypedEq<int>(1)));
|
||||||
@@ -205,7 +205,7 @@ TEST_F(BuildDependenciesStorage, FetchDependSourcesWithNonExistingProjectPartRet
|
|||||||
|
|
||||||
TEST_F(BuildDependenciesStorage, FetchDependSourcesWithExistingProjectPartReturnsSourceEntries)
|
TEST_F(BuildDependenciesStorage, FetchDependSourcesWithExistingProjectPartReturnsSourceEntries)
|
||||||
{
|
{
|
||||||
SourceEntries sourceEntries{{1, SourceType::TopInclude, 10}, {2, SourceType::TopSystemInclude, 20}};
|
SourceEntries sourceEntries{{1, SourceType::TopProjectInclude, 10}, {2, SourceType::TopSystemInclude, 20}};
|
||||||
EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq<Utils::SmallStringView>("test"))).WillOnce(Return(Utils::optional<int>{20}));
|
EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq<Utils::SmallStringView>("test"))).WillOnce(Return(Utils::optional<int>{20}));
|
||||||
EXPECT_CALL(fetchSourceDependenciesStatement, valuesReturnSourceEntries(_, 22, 20)).WillOnce(Return(sourceEntries));
|
EXPECT_CALL(fetchSourceDependenciesStatement, valuesReturnSourceEntries(_, 22, 20)).WillOnce(Return(sourceEntries));
|
||||||
|
|
||||||
|
|||||||
@@ -66,19 +66,33 @@ protected:
|
|||||||
{
|
{
|
||||||
setFilePathCache(&filePathCache);
|
setFilePathCache(&filePathCache);
|
||||||
|
|
||||||
collector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/main.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
|
collector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/main.cpp"),
|
||||||
collector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/main2.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
|
{"cc",
|
||||||
|
"-I",
|
||||||
|
TESTDATA_DIR "/builddependencycollector/external",
|
||||||
|
"-I",
|
||||||
|
TESTDATA_DIR "/builddependencycollector/project",
|
||||||
|
"-isystem",
|
||||||
|
TESTDATA_DIR "/builddependencycollector/system"});
|
||||||
|
collector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/main2.cpp"),
|
||||||
|
{"cc",
|
||||||
|
"-I",
|
||||||
|
TESTDATA_DIR "/builddependencycollector/external",
|
||||||
|
"-I",
|
||||||
|
TESTDATA_DIR "/builddependencycollector/project",
|
||||||
|
"-isystem",
|
||||||
|
TESTDATA_DIR "/builddependencycollector/system"});
|
||||||
|
|
||||||
collector.addUnsavedFiles({{{TESTDATA_DIR, "BuildDependencyCollector/project/generated_file.h"}, "#pragma once", {}}});
|
collector.addUnsavedFiles(
|
||||||
|
{{{TESTDATA_DIR, "BuildDependencyCollector/project/generated_file.h"},
|
||||||
|
"#pragma once",
|
||||||
|
{}}});
|
||||||
|
|
||||||
collector.setExcludedFilePaths(Utils::clone(excludePaths));
|
collector.setExcludedFilePaths(Utils::clone(excludePaths));
|
||||||
emptyCollector.setExcludedFilePaths(Utils::clone(excludePaths));
|
emptyCollector.setExcludedFilePaths(Utils::clone(excludePaths));
|
||||||
}
|
}
|
||||||
|
|
||||||
~BuildDependencyCollector()
|
~BuildDependencyCollector() { setFilePathCache(nullptr); }
|
||||||
{
|
|
||||||
setFilePathCache(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
FilePathId id(const Utils::SmallStringView &path) const
|
FilePathId id(const Utils::SmallStringView &path) const
|
||||||
{
|
{
|
||||||
@@ -90,7 +104,7 @@ protected:
|
|||||||
return QFileInfo(QString(filePath)).size();
|
return QFileInfo(QString(filePath)).size();
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::time_t lastModified(Utils::SmallStringView filePath)
|
static std::time_t lastModified(Utils::SmallStringView filePath)
|
||||||
{
|
{
|
||||||
return QFileInfo(QString(filePath)).lastModified().toTime_t();
|
return QFileInfo(QString(filePath)).lastModified().toTime_t();
|
||||||
}
|
}
|
||||||
@@ -100,9 +114,8 @@ protected:
|
|||||||
return {id(filePath), fileSize(filePath), lastModified(filePath), false};
|
return {id(filePath), fileSize(filePath), lastModified(filePath), false};
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static FilePathIds filteredIncludes(const ClangBackEnd::SourceEntries &includes,
|
||||||
FilePathIds filteredIncludes(const ClangBackEnd::SourceEntries &includes,
|
ClangBackEnd::SourceType includeType)
|
||||||
ClangBackEnd::SourceType includeType)
|
|
||||||
{
|
{
|
||||||
FilePathIds filteredIncludes;
|
FilePathIds filteredIncludes;
|
||||||
|
|
||||||
@@ -114,31 +127,32 @@ protected:
|
|||||||
return filteredIncludes;
|
return filteredIncludes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static FilePathIds topIncludes(const ClangBackEnd::SourceEntries &includes)
|
||||||
FilePathIds topIncludes(const ClangBackEnd::SourceEntries &includes)
|
|
||||||
{
|
{
|
||||||
return filteredIncludes(includes, ClangBackEnd::SourceType::TopInclude);
|
return filteredIncludes(includes, ClangBackEnd::SourceType::TopProjectInclude);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static FilePathIds systemTopIncludes(const ClangBackEnd::SourceEntries &includes)
|
||||||
FilePathIds systemTopIncludes(const ClangBackEnd::SourceEntries &includes)
|
|
||||||
{
|
{
|
||||||
return filteredIncludes(includes, ClangBackEnd::SourceType::TopSystemInclude);
|
return filteredIncludes(includes, ClangBackEnd::SourceType::TopSystemInclude);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static FilePathIds userIncludes(const ClangBackEnd::SourceEntries &includes)
|
||||||
FilePathIds userIncludes(const ClangBackEnd::SourceEntries &includes)
|
|
||||||
{
|
{
|
||||||
return filteredIncludes(includes, ClangBackEnd::SourceType::UserInclude);
|
return filteredIncludes(includes, ClangBackEnd::SourceType::UserInclude);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static FilePathIds projectPartIncludes(const ClangBackEnd::SourceEntries &includes)
|
||||||
FilePathIds allIncludes(const ClangBackEnd::SourceEntries &includes)
|
{
|
||||||
|
return filteredIncludes(includes, ClangBackEnd::SourceType::ProjectInclude);
|
||||||
|
}
|
||||||
|
|
||||||
|
static FilePathIds allIncludes(const ClangBackEnd::SourceEntries &includes)
|
||||||
{
|
{
|
||||||
FilePathIds filteredIncludes;
|
FilePathIds filteredIncludes;
|
||||||
|
|
||||||
for (const ClangBackEnd::SourceEntry &include : includes)
|
for (const ClangBackEnd::SourceEntry &include : includes)
|
||||||
filteredIncludes.push_back(include.sourceId);
|
filteredIncludes.push_back(include.sourceId);
|
||||||
|
|
||||||
return filteredIncludes;
|
return filteredIncludes;
|
||||||
}
|
}
|
||||||
@@ -564,17 +578,17 @@ TEST_F(BuildDependencyCollector, Create)
|
|||||||
HasInclude(id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
|
HasInclude(id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
|
||||||
SourceType::UserInclude),
|
SourceType::UserInclude),
|
||||||
HasInclude(id(TESTDATA_DIR "/builddependencycollector/external/external3.h"),
|
HasInclude(id(TESTDATA_DIR "/builddependencycollector/external/external3.h"),
|
||||||
SourceType::TopInclude),
|
SourceType::TopProjectInclude),
|
||||||
HasInclude(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
|
HasInclude(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
|
||||||
SourceType::TopInclude),
|
SourceType::TopProjectInclude),
|
||||||
HasInclude(id(TESTDATA_DIR
|
HasInclude(id(TESTDATA_DIR
|
||||||
"/builddependencycollector/external/indirect_external.h"),
|
"/builddependencycollector/external/indirect_external.h"),
|
||||||
SourceType::UserInclude),
|
SourceType::ProjectInclude),
|
||||||
HasInclude(id(TESTDATA_DIR
|
HasInclude(id(TESTDATA_DIR
|
||||||
"/builddependencycollector/external/indirect_external2.h"),
|
"/builddependencycollector/external/indirect_external2.h"),
|
||||||
SourceType::UserInclude),
|
SourceType::ProjectInclude),
|
||||||
HasInclude(id(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
|
HasInclude(id(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
|
||||||
SourceType::TopInclude),
|
SourceType::TopProjectInclude),
|
||||||
HasInclude(id(TESTDATA_DIR "/builddependencycollector/system/system1.h"),
|
HasInclude(id(TESTDATA_DIR "/builddependencycollector/system/system1.h"),
|
||||||
SourceType::TopSystemInclude),
|
SourceType::TopSystemInclude),
|
||||||
HasInclude(id(TESTDATA_DIR
|
HasInclude(id(TESTDATA_DIR
|
||||||
|
|||||||
@@ -1053,12 +1053,14 @@ const char *sourceTypeString(SourceType sourceType)
|
|||||||
using ClangBackEnd::SymbolTag;
|
using ClangBackEnd::SymbolTag;
|
||||||
|
|
||||||
switch (sourceType) {
|
switch (sourceType) {
|
||||||
case SourceType::TopInclude:
|
case SourceType::TopProjectInclude:
|
||||||
return "TopInclude";
|
return "TopProjectInclude";
|
||||||
case SourceType::TopSystemInclude:
|
case SourceType::TopSystemInclude:
|
||||||
return "TopSystemInclude";
|
return "TopSystemInclude";
|
||||||
case SourceType::SystemInclude:
|
case SourceType::SystemInclude:
|
||||||
return "SystemInclude";
|
return "SystemInclude";
|
||||||
|
case SourceType::ProjectInclude:
|
||||||
|
return "ProjectInclude";
|
||||||
case SourceType::UserInclude:
|
case SourceType::UserInclude:
|
||||||
return "UserInclude";
|
return "UserInclude";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,13 +100,13 @@ protected:
|
|||||||
ClangBackEnd::PchCreator creator{environment, database, mockPchManagerClient, mockClangPathWatcher};
|
ClangBackEnd::PchCreator creator{environment, database, mockPchManagerClient, mockClangPathWatcher};
|
||||||
ProjectPartContainer projectPart1{"project1",
|
ProjectPartContainer projectPart1{"project1",
|
||||||
{"-I", TESTDATA_DIR, "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system", "-Wno-pragma-once-outside-header"},
|
{"-I", TESTDATA_DIR, "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system", "-Wno-pragma-once-outside-header"},
|
||||||
{{"DEFINE", "1"}},
|
{{"DEFINE", "1", 1}},
|
||||||
{TESTDATA_DIR "/builddependencycollector/external", TESTDATA_DIR "/builddependencycollector/project"},
|
{TESTDATA_DIR "/builddependencycollector/external", TESTDATA_DIR "/builddependencycollector/project"},
|
||||||
{id(header1Path)},
|
{id(header1Path)},
|
||||||
{id(main1Path)}};
|
{id(main1Path)}};
|
||||||
ProjectPartContainer projectPart2{"project2",
|
ProjectPartContainer projectPart2{"project2",
|
||||||
{"-I", TESTDATA_DIR, "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
{"-I", TESTDATA_DIR, "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
||||||
{{"DEFINE", "1"}},
|
{{"DEFINE", "1", 1}},
|
||||||
{TESTDATA_DIR "/builddependencycollector/external", TESTDATA_DIR "/builddependencycollector/project"},
|
{TESTDATA_DIR "/builddependencycollector/external", TESTDATA_DIR "/builddependencycollector/project"},
|
||||||
{id(header2Path)},
|
{id(header2Path)},
|
||||||
{id(main2Path)}};
|
{id(main2Path)}};
|
||||||
@@ -153,7 +153,7 @@ TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludes)
|
|||||||
AllOf(
|
AllOf(
|
||||||
Contains(HasIdAndType(
|
Contains(HasIdAndType(
|
||||||
id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
|
id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
|
||||||
SourceType::TopInclude)),
|
SourceType::TopProjectInclude)),
|
||||||
Contains(HasIdAndType(
|
Contains(HasIdAndType(
|
||||||
id(TESTDATA_DIR "/builddependencycollector/system/system1.h"),
|
id(TESTDATA_DIR "/builddependencycollector/system/system1.h"),
|
||||||
SourceType::TopSystemInclude)),
|
SourceType::TopSystemInclude)),
|
||||||
@@ -164,11 +164,11 @@ TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludes)
|
|||||||
Contains(HasIdAndType(
|
Contains(HasIdAndType(
|
||||||
id(TESTDATA_DIR
|
id(TESTDATA_DIR
|
||||||
"/builddependencycollector/external/external1.h"),
|
"/builddependencycollector/external/external1.h"),
|
||||||
SourceType::TopInclude)),
|
SourceType::TopProjectInclude)),
|
||||||
Contains(HasIdAndType(
|
Contains(HasIdAndType(
|
||||||
id(TESTDATA_DIR
|
id(TESTDATA_DIR
|
||||||
"/builddependencycollector/external/external2.h"),
|
"/builddependencycollector/external/external2.h"),
|
||||||
SourceType::TopInclude))));
|
SourceType::TopProjectInclude))));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PchCreatorSlowTest, CreateProjectPartPchFileContent)
|
TEST_F(PchCreatorSlowTest, CreateProjectPartPchFileContent)
|
||||||
@@ -294,7 +294,7 @@ TEST_F(PchCreatorVerySlowTest, FaultyProjectPartPchForCreatesNoPchForProjectPart
|
|||||||
{
|
{
|
||||||
ProjectPartContainer faultyProjectPart{"faultyProject",
|
ProjectPartContainer faultyProjectPart{"faultyProject",
|
||||||
{"-I", TESTDATA_DIR},
|
{"-I", TESTDATA_DIR},
|
||||||
{{"DEFINE", "1"}},
|
{{"DEFINE", "1", 1}},
|
||||||
{"/includes"},
|
{"/includes"},
|
||||||
{},
|
{},
|
||||||
{id(TESTDATA_DIR "/builddependencycollector/project/faulty.cpp")}};
|
{id(TESTDATA_DIR "/builddependencycollector/project/faulty.cpp")}};
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ TEST_F(PchManagerClientServerInProcess, SendUpdateProjectPartsMessage)
|
|||||||
{
|
{
|
||||||
ProjectPartContainer projectPart2{"projectPartId",
|
ProjectPartContainer projectPart2{"projectPartId",
|
||||||
{"-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
{"-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
||||||
{{"DEFINE", "1"}},
|
{{"DEFINE", "1", 1}},
|
||||||
{"/includes"},
|
{"/includes"},
|
||||||
{{1, 1}},
|
{{1, 1}},
|
||||||
{{1, 2}}};
|
{{1, 2}}};
|
||||||
|
|||||||
@@ -82,13 +82,13 @@ protected:
|
|||||||
ClangBackEnd::IdPaths idPath{projectPartId1, {1, 2}};
|
ClangBackEnd::IdPaths idPath{projectPartId1, {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", "1"}},
|
{{"DEFINE", "1", 1}},
|
||||||
{"/includes"},
|
{"/includes"},
|
||||||
{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", "1"}},
|
{{"DEFINE", "1", 1}},
|
||||||
{"/includes"},
|
{"/includes"},
|
||||||
{id(header2Path)},
|
{id(header2Path)},
|
||||||
{id(main2Path)}};
|
{id(main2Path)}};
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ protected:
|
|||||||
ClangBackEnd::PchTaskGenerator generator{mockBuildDependenciesProvider};
|
ClangBackEnd::PchTaskGenerator generator{mockBuildDependenciesProvider};
|
||||||
ClangBackEnd::V2::ProjectPartContainer projectPart1{"ProjectPart1",
|
ClangBackEnd::V2::ProjectPartContainer projectPart1{"ProjectPart1",
|
||||||
{"--yi"},
|
{"--yi"},
|
||||||
{{"YI","1"}},
|
{{"YI", "1", 1}},
|
||||||
{"/yi"},
|
{"/yi"},
|
||||||
{{1, 1}},
|
{{1, 1}},
|
||||||
{{1, 2}}};
|
{{1, 2}}};
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ TEST(ProjectPartArtefact, CompilerMacros)
|
|||||||
ClangBackEnd::ProjectPartArtefact artefact{"", "{\"Foo\":\"1\",\"Bar\":\"42\"}", "", 1};
|
ClangBackEnd::ProjectPartArtefact artefact{"", "{\"Foo\":\"1\",\"Bar\":\"42\"}", "", 1};
|
||||||
|
|
||||||
ASSERT_THAT(artefact.compilerMacros,
|
ASSERT_THAT(artefact.compilerMacros,
|
||||||
UnorderedElementsAre(Eq(CompilerMacro{"Foo", "1"}), Eq(CompilerMacro{"Bar", "42"})));
|
UnorderedElementsAre(Eq(CompilerMacro{"Foo", "1", 1}), Eq(CompilerMacro{"Bar", "42", 2})));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ProjectPartArtefact, EmptyCompilerMacros)
|
TEST(ProjectPartArtefact, EmptyCompilerMacros)
|
||||||
|
|||||||
@@ -46,25 +46,25 @@ protected:
|
|||||||
ClangBackEnd::ProjectPartQueue queue{mockTaskScheduler, mockPrecompiledHeaderStorage, mockSqliteTransactionBackend, progressCounter};
|
ClangBackEnd::ProjectPartQueue queue{mockTaskScheduler, mockPrecompiledHeaderStorage, mockSqliteTransactionBackend, progressCounter};
|
||||||
ClangBackEnd::V2::ProjectPartContainer projectPart1{"ProjectPart1",
|
ClangBackEnd::V2::ProjectPartContainer projectPart1{"ProjectPart1",
|
||||||
{"--yi"},
|
{"--yi"},
|
||||||
{{"YI","1"}},
|
{{"YI","1", 1}},
|
||||||
{"/yi"},
|
{"/yi"},
|
||||||
{1},
|
{1},
|
||||||
{2}};
|
{2}};
|
||||||
ClangBackEnd::V2::ProjectPartContainer projectPart2{"ProjectPart2",
|
ClangBackEnd::V2::ProjectPartContainer projectPart2{"ProjectPart2",
|
||||||
{"--er"},
|
{"--er"},
|
||||||
{{"ER","2"}},
|
{{"ER","2", 1}},
|
||||||
{"/bar"},
|
{"/bar"},
|
||||||
{1},
|
{1},
|
||||||
{2}};
|
{2}};
|
||||||
ClangBackEnd::V2::ProjectPartContainer projectPart2b{"ProjectPart2",
|
ClangBackEnd::V2::ProjectPartContainer projectPart2b{"ProjectPart2",
|
||||||
{"--liang"},
|
{"--liang"},
|
||||||
{{"LIANG","3"}},
|
{{"LIANG","3", 1}},
|
||||||
{"/liang"},
|
{"/liang"},
|
||||||
{3},
|
{3},
|
||||||
{2, 4}};
|
{2, 4}};
|
||||||
ClangBackEnd::V2::ProjectPartContainer projectPart3{"ProjectPart3",
|
ClangBackEnd::V2::ProjectPartContainer projectPart3{"ProjectPart3",
|
||||||
{"--san"},
|
{"--san"},
|
||||||
{{"SAN","2"}},
|
{{"SAN","2", 1}},
|
||||||
{"/SAN"},
|
{"/SAN"},
|
||||||
{1},
|
{1},
|
||||||
{2}};
|
{2}};
|
||||||
|
|||||||
@@ -48,20 +48,20 @@ protected:
|
|||||||
FilePathId secondSource{12};
|
FilePathId secondSource{12};
|
||||||
FilePathId thirdSource{13};
|
FilePathId thirdSource{13};
|
||||||
ProjectPartContainer projectPartContainer1{"id",
|
ProjectPartContainer projectPartContainer1{"id",
|
||||||
{"-DUNIX", "-O2"},
|
{"-DUNIX", "-O2"},
|
||||||
{{"DEFINE", "1"}},
|
{{"DEFINE", "1", 1}},
|
||||||
{"/includes"},
|
{"/includes"},
|
||||||
{firstHeader, secondHeader},
|
{firstHeader, secondHeader},
|
||||||
{firstSource, secondSource}};
|
{firstSource, secondSource}};
|
||||||
ProjectPartContainer updatedProjectPartContainer1{"id",
|
ProjectPartContainer updatedProjectPartContainer1{"id",
|
||||||
{"-DUNIX", "-O2"},
|
{"-DUNIX", "-O2"},
|
||||||
{{"DEFINE", "1"}},
|
{{"DEFINE", "1", 1}},
|
||||||
{"/includes"},
|
{"/includes"},
|
||||||
{firstHeader, secondHeader},
|
{firstHeader, secondHeader},
|
||||||
{firstSource, secondSource, thirdSource}};
|
{firstSource, secondSource, thirdSource}};
|
||||||
ProjectPartContainer projectPartContainer2{"id2",
|
ProjectPartContainer projectPartContainer2{"id2",
|
||||||
{"-DUNIX", "-O2"},
|
{"-DUNIX", "-O2"},
|
||||||
{{"DEFINE", "1"}},
|
{{"DEFINE", "1", 1}},
|
||||||
{"/includes"},
|
{"/includes"},
|
||||||
{firstHeader, secondHeader},
|
{firstHeader, secondHeader},
|
||||||
{firstSource, secondSource}};
|
{firstSource, secondSource}};
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ protected:
|
|||||||
Utils::SmallString projectPartId2;
|
Utils::SmallString projectPartId2;
|
||||||
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"};
|
||||||
ClangBackEnd::CompilerMacros compilerMacros = {{"BAR", "1"}, {"FOO", "2"}};
|
ClangBackEnd::CompilerMacros compilerMacros = {{"BAR", "1", 1}, {"FOO", "2", 2}};
|
||||||
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};
|
||||||
@@ -246,9 +246,9 @@ TEST_F(ProjectUpdater, CreateSortedCompilerMacros)
|
|||||||
{
|
{
|
||||||
auto paths = updater.createCompilerMacros({{"DEFINE", "1"}, {"FOO", "2"}, {"BAR", "1"}});
|
auto paths = updater.createCompilerMacros({{"DEFINE", "1"}, {"FOO", "2"}, {"BAR", "1"}});
|
||||||
|
|
||||||
ASSERT_THAT(paths, ElementsAre(CompilerMacro{"BAR", "1"},
|
ASSERT_THAT(paths, ElementsAre(CompilerMacro{"BAR", "1", 1},
|
||||||
CompilerMacro{"FOO", "2"},
|
CompilerMacro{"FOO", "2", 2},
|
||||||
CompilerMacro{"DEFINE", "1"}));
|
CompilerMacro{"DEFINE", "1", 3}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ProjectUpdater, CreateSortedIncludeSearchPaths)
|
TEST_F(ProjectUpdater, CreateSortedIncludeSearchPaths)
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ TEST_F(RefactoringClientServerInProcess, SendUpdateProjectPartsMessage)
|
|||||||
{
|
{
|
||||||
ProjectPartContainer projectPart2{"projectPartId",
|
ProjectPartContainer projectPart2{"projectPartId",
|
||||||
{"-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
{"-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
||||||
{{"DEFINE", "1"}},
|
{{"DEFINE", "1", 1}},
|
||||||
{"/includes"},
|
{"/includes"},
|
||||||
{{1, 1}},
|
{{1, 1}},
|
||||||
{{1, 2}}};
|
{{1, 2}}};
|
||||||
|
|||||||
@@ -326,7 +326,7 @@ TEST_F(RefactoringServer, UpdateProjectPartsCallsSymbolIndexingUpdateProjectPart
|
|||||||
{
|
{
|
||||||
ProjectPartContainers projectParts{{{"projectPartId",
|
ProjectPartContainers projectParts{{{"projectPartId",
|
||||||
{"-I", TESTDATA_DIR},
|
{"-I", TESTDATA_DIR},
|
||||||
{{"DEFINE", "1"}},
|
{{"DEFINE", "1", 1}},
|
||||||
{"/includes"},
|
{"/includes"},
|
||||||
{filePathId("header1.h")},
|
{filePathId("header1.h")},
|
||||||
{filePathId("main.cpp")}}}};
|
{filePathId("main.cpp")}}}};
|
||||||
|
|||||||
@@ -166,19 +166,19 @@ protected:
|
|||||||
ClangBackEnd::FilePathId generatedFilePathId21;
|
ClangBackEnd::FilePathId generatedFilePathId21;
|
||||||
ProjectPartContainer projectPart1{"project1",
|
ProjectPartContainer projectPart1{"project1",
|
||||||
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
|
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
|
||||||
{{"BAR", "1"}, {"FOO", "1"}},
|
{{"BAR", "1", 1}, {"FOO", "1", 2}},
|
||||||
{"/includes"},
|
{"/includes"},
|
||||||
{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"},
|
||||||
{{"BAR", "1"}, {"FOO", "0"}},
|
{{"BAR", "1", 1}, {"FOO", "0", 2}},
|
||||||
{"/includes"},
|
{"/includes"},
|
||||||
{header2PathId},
|
{header2PathId},
|
||||||
{main2PathId}};
|
{main2PathId}};
|
||||||
ProjectPartContainer projectPart3{"project3",
|
ProjectPartContainer projectPart3{"project3",
|
||||||
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
|
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
|
||||||
{{"BAR", "1"}, {"FOO", "1"}},
|
{{"BAR", "1", 1}, {"FOO", "1", 2}},
|
||||||
{"/includes", "/other/includes"},
|
{"/includes", "/other/includes"},
|
||||||
{header1PathId},
|
{header1PathId},
|
||||||
{main1PathId}};
|
{main1PathId}};
|
||||||
@@ -315,11 +315,11 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartsInStorage)
|
|||||||
{
|
{
|
||||||
EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq("project1"),
|
EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq("project1"),
|
||||||
ElementsAre("-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"),
|
ElementsAre("-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"),
|
||||||
ElementsAre(CompilerMacro{"BAR", "1"}, CompilerMacro{"FOO", "1"}),
|
ElementsAre(CompilerMacro{"BAR", "1", 1}, CompilerMacro{"FOO", "1", 2}),
|
||||||
ElementsAre("/includes")));
|
ElementsAre("/includes")));
|
||||||
EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq("project2"),
|
EXPECT_CALL(mockSymbolStorage, 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(CompilerMacro{"BAR", "1"}, CompilerMacro{"FOO", "0"}),
|
ElementsAre(CompilerMacro{"BAR", "1", 1}, CompilerMacro{"FOO", "0", 2}),
|
||||||
ElementsAre("/includes")));
|
ElementsAre("/includes")));
|
||||||
|
|
||||||
indexer.updateProjectParts({projectPart1, projectPart2});
|
indexer.updateProjectParts({projectPart1, projectPart2});
|
||||||
@@ -535,7 +535,7 @@ TEST_F(SymbolIndexer, IncludeSearchPathsAreDifferent)
|
|||||||
{
|
{
|
||||||
ProjectPartContainer projectPart3{"project3",
|
ProjectPartContainer projectPart3{"project3",
|
||||||
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
|
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
|
||||||
{{"BAR", "1"}, {"FOO", "1"}},
|
{{"BAR", "1", 1}, {"FOO", "1", 2}},
|
||||||
{"/includes", "/other/includes"},
|
{"/includes", "/other/includes"},
|
||||||
{header1PathId},
|
{header1PathId},
|
||||||
{main1PathId}};
|
{main1PathId}};
|
||||||
|
|||||||
@@ -89,7 +89,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", "1"}},
|
{{"DEFINE", "1", 1}},
|
||||||
{"/includes"},
|
{"/includes"},
|
||||||
{},
|
{},
|
||||||
{filePathId(main1Path)}};
|
{filePathId(main1Path)}};
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ TEST_F(SymbolStorage, InsertProjectPart)
|
|||||||
TypedEq<Utils::SmallStringView>("[\"/includes\"]")));
|
TypedEq<Utils::SmallStringView>("[\"/includes\"]")));
|
||||||
EXPECT_CALL(mockDatabase, lastInsertedRowId()).Times(2);
|
EXPECT_CALL(mockDatabase, lastInsertedRowId()).Times(2);
|
||||||
|
|
||||||
storage.insertOrUpdateProjectPart("project", {"foo"}, {{"FOO", "1"}}, {"/includes"});
|
storage.insertOrUpdateProjectPart("project", {"foo"}, {{"FOO", "1", 1}}, {"/includes"});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SymbolStorage, UpdateProjectPart)
|
TEST_F(SymbolStorage, UpdateProjectPart)
|
||||||
@@ -202,7 +202,7 @@ TEST_F(SymbolStorage, UpdateProjectPart)
|
|||||||
TypedEq<Utils::SmallStringView>("project")));
|
TypedEq<Utils::SmallStringView>("project")));
|
||||||
EXPECT_CALL(mockDatabase, lastInsertedRowId());
|
EXPECT_CALL(mockDatabase, lastInsertedRowId());
|
||||||
|
|
||||||
storage.insertOrUpdateProjectPart("project", {"foo"}, {{"FOO", "1"}}, {"/includes"});
|
storage.insertOrUpdateProjectPart("project", {"foo"}, {{"FOO", "1", 1}}, {"/includes"});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SymbolStorage, UpdateProjectPartSources)
|
TEST_F(SymbolStorage, UpdateProjectPartSources)
|
||||||
|
|||||||
@@ -107,7 +107,8 @@ SOURCES += \
|
|||||||
pchtaskgenerator-test.cpp \
|
pchtaskgenerator-test.cpp \
|
||||||
compilationdatabaseutils-test.cpp \
|
compilationdatabaseutils-test.cpp \
|
||||||
builddependenciesprovider-test.cpp \
|
builddependenciesprovider-test.cpp \
|
||||||
builddependenciesstorage-test.cpp
|
builddependenciesstorage-test.cpp \
|
||||||
|
usedmacrofilter-test.cpp
|
||||||
|
|
||||||
!isEmpty(LIBCLANG_LIBS) {
|
!isEmpty(LIBCLANG_LIBS) {
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
|||||||
106
tests/unit/unittest/usedmacrofilter-test.cpp
Normal file
106
tests/unit/unittest/usedmacrofilter-test.cpp
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2018 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 <usedmacrofilter.h>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
using ClangBackEnd::FilePathId;
|
||||||
|
using ClangBackEnd::SourceEntries;
|
||||||
|
using ClangBackEnd::SourceEntry;
|
||||||
|
using ClangBackEnd::SourceType;
|
||||||
|
using ClangBackEnd::UsedMacro;
|
||||||
|
using ClangBackEnd::UsedMacros;
|
||||||
|
using ClangBackEnd::CompilerMacro;
|
||||||
|
using ClangBackEnd::CompilerMacros;
|
||||||
|
|
||||||
|
class UsedMacroFilter : public testing::Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
SourceEntries includes{{1, SourceType::UserInclude, 0},
|
||||||
|
{2, SourceType::SystemInclude, 0},
|
||||||
|
{3, SourceType::ProjectInclude, 0},
|
||||||
|
{4, SourceType::TopSystemInclude, 0},
|
||||||
|
{5, SourceType::TopProjectInclude, 0}};
|
||||||
|
UsedMacros usedMacros{{"YI", 1}, {"ER", 2}, {"SAN", 3}, {"SE", 4}, {"WU", 5}};
|
||||||
|
CompilerMacros compileMacros{{"YI", "1", 1},
|
||||||
|
{"ER", "2", 2},
|
||||||
|
{"SAN", "3", 3},
|
||||||
|
{"SE", "4", 4},
|
||||||
|
{"WU", "5", 5},
|
||||||
|
{"LIANG", "2", 6}};
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(UsedMacroFilter, SystemIncludes)
|
||||||
|
{
|
||||||
|
auto result = ClangBackEnd::UsedMacroFilter::filterIncludes(includes);
|
||||||
|
|
||||||
|
ASSERT_THAT(result.system, ElementsAre(FilePathId{2}, FilePathId{4}));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(UsedMacroFilter, ProjectIncludes)
|
||||||
|
{
|
||||||
|
auto result = ClangBackEnd::UsedMacroFilter::filterIncludes(includes);
|
||||||
|
|
||||||
|
ASSERT_THAT(result.project, ElementsAre(FilePathId{3}, FilePathId{5}));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(UsedMacroFilter, SystemUsedMacros)
|
||||||
|
{
|
||||||
|
ClangBackEnd::UsedMacroFilter filter(includes, usedMacros);
|
||||||
|
|
||||||
|
ASSERT_THAT(filter.systemUsedMacros(), ElementsAre("ER", "SE"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(UsedMacroFilter, ProjectUsedMacros)
|
||||||
|
{
|
||||||
|
ClangBackEnd::UsedMacroFilter filter(includes, usedMacros);
|
||||||
|
|
||||||
|
ASSERT_THAT(filter.projectUsedMacros(), ElementsAre("WU", "SAN"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(UsedMacroFilter, SystemCompileMacros)
|
||||||
|
{
|
||||||
|
ClangBackEnd::UsedMacroFilter filter(includes, usedMacros);
|
||||||
|
|
||||||
|
filter.filter(compileMacros);
|
||||||
|
|
||||||
|
ASSERT_THAT(filter.systemCompilerMacros(),
|
||||||
|
ElementsAre(CompilerMacro{"ER", "2", 2}, CompilerMacro{"SE", "4", 4}));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(UsedMacroFilter, ProjectCompileMacros)
|
||||||
|
{
|
||||||
|
ClangBackEnd::UsedMacroFilter filter(includes, usedMacros);
|
||||||
|
|
||||||
|
filter.filter(compileMacros);
|
||||||
|
|
||||||
|
ASSERT_THAT(filter.projectCompilerMacros(),
|
||||||
|
ElementsAre(CompilerMacro{"SAN", "3", 3}, CompilerMacro{"WU", "5", 5}));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
Reference in New Issue
Block a user