CppTools: Turn some classes into pure value types

ProjectInfo, ProjectPart and ProjectUpdateInfo used to carry pointers
to Project and/or Toolchain, even though they were used in contexts
where these pointers were either unsafe to access or not guaranteed to
be valid anymore, which made their use difficult and error-prone.
We turn these classes into pure value types by copying in all relevant
information before the first async operation takes place.

Fixes: QTCREATORBUG-25678
Change-Id: I1914b0dbda6c7dfba6c95e5e92f2d69977755590
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Christian Kandeler
2021-05-07 16:10:07 +02:00
parent 3143ba79e3
commit 33108795d6
61 changed files with 1086 additions and 958 deletions

View File

@@ -60,19 +60,22 @@ public:
const ProjectPartInfo choose()
{
return chooser.choose(filePath, currentProjectPartInfo, preferredProjectPartId,
activeProject, languagePreference, projectsChanged);
projectMap.value(activeProject).get(),
languagePreference, projectsChanged);
}
static QList<ProjectPart::Ptr> createProjectPartsWithDifferentProjects()
{
QList<ProjectPart::Ptr> projectParts;
const ProjectPart::Ptr p1{new ProjectPart};
p1->project = reinterpret_cast<Project *>(1 << 0);
projectParts.append(p1);
const ProjectPart::Ptr p2{new ProjectPart};
p2->project = reinterpret_cast<Project *>(1 << 1);
projectParts.append(p2);
const auto p1 = std::make_shared<Project>(
QString(), Utils::FilePath::fromString("p1.pro"));
projectMap.insert(p1->projectFilePath(), p1);
projectParts.append(ProjectPart::create(p1->projectFilePath()));
const auto p2 = std::make_shared<Project>(
QString(), Utils::FilePath::fromString("p2.pro"));
projectMap.insert(p2->projectFilePath(), p2);
projectParts.append(ProjectPart::create(p2->projectFilePath()));
return projectParts;
}
@@ -80,27 +83,34 @@ public:
static QList<ProjectPart::Ptr> createCAndCxxProjectParts()
{
QList<ProjectPart::Ptr> projectParts;
ToolChainInfo tcInfo;
// Create project part for C
const ProjectPart::Ptr cprojectpart{new ProjectPart};
cprojectpart->languageVersion = Utils::LanguageVersion::C11;
tcInfo.macroInspectionRunner = [](const QStringList &) {
return ToolChain::MacroInspectionReport{{}, Utils::LanguageVersion::C11};
};
const ProjectPart::Ptr cprojectpart = ProjectPart::create({}, {}, {}, {}, {}, {}, {},
tcInfo);
projectParts.append(cprojectpart);
// Create project part for CXX
const ProjectPart::Ptr cxxprojectpart{new ProjectPart};
cxxprojectpart->languageVersion = Utils::LanguageVersion::CXX98;
tcInfo.macroInspectionRunner = [](const QStringList &) {
return ToolChain::MacroInspectionReport{{}, Utils::LanguageVersion::CXX98};
};
const ProjectPart::Ptr cxxprojectpart = ProjectPart::create({}, {}, {}, {}, {}, {}, {},
tcInfo);
projectParts.append(cxxprojectpart);
return projectParts;
}
QString filePath;
ProjectPart::Ptr currentProjectPart{new ProjectPart};
ProjectPart::Ptr currentProjectPart = ProjectPart::create({});
ProjectPartInfo currentProjectPartInfo{currentProjectPart,
{currentProjectPart},
ProjectPartInfo::NoHint};
QString preferredProjectPartId;
const Project *activeProject = nullptr;
Utils::FilePath activeProject;
Language languagePreference = Language::Cxx;
bool projectsChanged = false;
ProjectPartChooser chooser;
@@ -108,15 +118,21 @@ public:
QList<ProjectPart::Ptr> projectPartsForFile;
QList<ProjectPart::Ptr> projectPartsFromDependenciesForFile;
ProjectPart::Ptr fallbackProjectPart;
static QHash<Utils::FilePath, std::shared_ptr<Project>> projectMap;
};
QHash<Utils::FilePath, std::shared_ptr<Project>>
ProjectPartChooserTest::projectMap;
}
void CppToolsPlugin::test_projectPartChooser_chooseManuallySet()
{
ProjectPart::Ptr p1(new ProjectPart);
ProjectPart::Ptr p2(new ProjectPart);
ProjectPart::Ptr p1 = ProjectPart::create({});
RawProjectPart rpp2;
rpp2.setProjectFileLocation("someId");
ProjectPart::Ptr p2 = ProjectPart::create({}, rpp2);
ProjectPartChooserTest t;
p2->projectFile = "someId";
t.preferredProjectPartId = p2->projectFile;
t.projectPartsForFile += {p1, p2};
@@ -125,10 +141,11 @@ void CppToolsPlugin::test_projectPartChooser_chooseManuallySet()
void CppToolsPlugin::test_projectPartChooser_indicateManuallySet()
{
ProjectPart::Ptr p1(new ProjectPart);
ProjectPart::Ptr p2(new ProjectPart);
ProjectPart::Ptr p1 = ProjectPart::create({});
RawProjectPart rpp2;
rpp2.setProjectFileLocation("someId");
ProjectPart::Ptr p2 = ProjectPart::create({}, rpp2);
ProjectPartChooserTest t;
p2->projectFile = "someId";
t.preferredProjectPartId = p2->projectFile;
t.projectPartsForFile += {p1, p2};
@@ -137,10 +154,11 @@ void CppToolsPlugin::test_projectPartChooser_indicateManuallySet()
void CppToolsPlugin::test_projectPartChooser_indicateManuallySetForFallbackToProjectPartFromDependencies()
{
ProjectPart::Ptr p1(new ProjectPart);
ProjectPart::Ptr p2(new ProjectPart);
ProjectPart::Ptr p1 = ProjectPart::create({});
RawProjectPart rpp2;
rpp2.setProjectFileLocation("someId");
ProjectPart::Ptr p2 = ProjectPart::create({}, rpp2);
ProjectPartChooserTest t;
p2->projectFile = "someId";
t.preferredProjectPartId = p2->projectFile;
t.projectPartsFromDependenciesForFile += {p1, p2};
@@ -158,17 +176,19 @@ void CppToolsPlugin::test_projectPartChooser_forMultipleChooseFromActiveProject(
const QList<ProjectPart::Ptr> projectParts = t.createProjectPartsWithDifferentProjects();
const ProjectPart::Ptr secondProjectPart = projectParts.at(1);
t.projectPartsForFile += projectParts;
t.activeProject = secondProjectPart->project;
t.activeProject = secondProjectPart->topLevelProject;
QCOMPARE(t.choose().projectPart, secondProjectPart);
}
void CppToolsPlugin::test_projectPartChooser_forMultiplePreferSelectedForBuilding()
{
const ProjectPart::Ptr firstProjectPart{new ProjectPart};
const ProjectPart::Ptr secondProjectPart{new ProjectPart};
firstProjectPart->selectedForBuilding = false;
secondProjectPart->selectedForBuilding = true;
RawProjectPart rpp1;
rpp1.setSelectedForBuilding(false);
RawProjectPart rpp2;
rpp1.setSelectedForBuilding(true);
const ProjectPart::Ptr firstProjectPart = ProjectPart::create({}, rpp1);
const ProjectPart::Ptr secondProjectPart = ProjectPart::create({}, rpp2);
ProjectPartChooserTest t;
t.projectPartsForFile += firstProjectPart;
t.projectPartsForFile += secondProjectPart;
@@ -182,7 +202,7 @@ void CppToolsPlugin::test_projectPartChooser_forMultipleFromDependenciesChooseFr
const QList<ProjectPart::Ptr> projectParts = t.createProjectPartsWithDifferentProjects();
const ProjectPart::Ptr secondProjectPart = projectParts.at(1);
t.projectPartsFromDependenciesForFile += projectParts;
t.activeProject = secondProjectPart->project;
t.activeProject = secondProjectPart->topLevelProject;
QCOMPARE(t.choose().projectPart, secondProjectPart);
}
@@ -195,7 +215,7 @@ void CppToolsPlugin::test_projectPartChooser_forMultipleCheckIfActiveProjectChan
const ProjectPart::Ptr secondProjectPart = projectParts.at(1);
t.projectPartsForFile += projectParts;
t.currentProjectPartInfo.projectPart = firstProjectPart;
t.activeProject = secondProjectPart->project;
t.activeProject = secondProjectPart->topLevelProject;
QCOMPARE(t.choose().projectPart, secondProjectPart);
}
@@ -222,27 +242,27 @@ void CppToolsPlugin::test_projectPartChooser_forMultipleAndAmbigiousHeaderPrefer
void CppToolsPlugin::test_projectPartChooser_indicateMultiple()
{
const ProjectPart::Ptr p1{new ProjectPart};
const ProjectPart::Ptr p2{new ProjectPart};
const ProjectPart::Ptr p1 = ProjectPart::create({});
const ProjectPart::Ptr p2 = ProjectPart::create({});
ProjectPartChooserTest t;
t.projectPartsForFile += { p1, p2 };
t.projectPartsForFile += {p1, p2};
QVERIFY(t.choose().hints & ProjectPartInfo::IsAmbiguousMatch);
}
void CppToolsPlugin::test_projectPartChooser_indicateMultipleForFallbackToProjectPartFromDependencies()
{
const ProjectPart::Ptr p1{new ProjectPart};
const ProjectPart::Ptr p2{new ProjectPart};
const ProjectPart::Ptr p1 = ProjectPart::create({});
const ProjectPart::Ptr p2 = ProjectPart::create({});
ProjectPartChooserTest t;
t.projectPartsFromDependenciesForFile += { p1, p2 };
t.projectPartsFromDependenciesForFile += {p1, p2};
QVERIFY(t.choose().hints & ProjectPartInfo::IsAmbiguousMatch);
}
void CppToolsPlugin::test_projectPartChooser_forMultipleChooseNewIfPreviousIsGone()
{
const ProjectPart::Ptr newProjectPart{new ProjectPart};
const ProjectPart::Ptr newProjectPart = ProjectPart::create({});
ProjectPartChooserTest t;
t.projectPartsForFile += newProjectPart;
@@ -251,7 +271,7 @@ void CppToolsPlugin::test_projectPartChooser_forMultipleChooseNewIfPreviousIsGon
void CppToolsPlugin::test_projectPartChooser_fallbackToProjectPartFromDependencies()
{
const ProjectPart::Ptr fromDependencies{new ProjectPart};
const ProjectPart::Ptr fromDependencies = ProjectPart::create({});
ProjectPartChooserTest t;
t.projectPartsFromDependenciesForFile += fromDependencies;
@@ -261,7 +281,7 @@ void CppToolsPlugin::test_projectPartChooser_fallbackToProjectPartFromDependenci
void CppToolsPlugin::test_projectPartChooser_fallbackToProjectPartFromModelManager()
{
ProjectPartChooserTest t;
t.fallbackProjectPart.reset(new ProjectPart);
t.fallbackProjectPart = ProjectPart::create({});
QCOMPARE(t.choose().projectPart, t.fallbackProjectPart);
}
@@ -270,10 +290,10 @@ void CppToolsPlugin::test_projectPartChooser_continueUsingFallbackFromModelManag
{
// ...without re-calculating the dependency table.
ProjectPartChooserTest t;
t.fallbackProjectPart.reset(new ProjectPart);
t.fallbackProjectPart = ProjectPart::create({});
t.currentProjectPartInfo.projectPart = t.fallbackProjectPart;
t.currentProjectPartInfo.hints |= ProjectPartInfo::IsFallbackMatch;
t.projectPartsFromDependenciesForFile += ProjectPart::Ptr(new ProjectPart);
t.projectPartsFromDependenciesForFile += ProjectPart::create({});
QCOMPARE(t.choose().projectPart, t.fallbackProjectPart);
}
@@ -281,10 +301,10 @@ void CppToolsPlugin::test_projectPartChooser_continueUsingFallbackFromModelManag
void CppToolsPlugin::test_projectPartChooser_stopUsingFallbackFromModelManagerIfProjectChanges1()
{
ProjectPartChooserTest t;
t.fallbackProjectPart.reset(new ProjectPart);
t.fallbackProjectPart = ProjectPart::create({});
t.currentProjectPartInfo.projectPart = t.fallbackProjectPart;
t.currentProjectPartInfo.hints |= ProjectPartInfo::IsFallbackMatch;
const ProjectPart::Ptr addedProject(new ProjectPart);
const ProjectPart::Ptr addedProject = ProjectPart::create({});
t.projectPartsForFile += addedProject;
QCOMPARE(t.choose().projectPart, addedProject);
@@ -293,10 +313,10 @@ void CppToolsPlugin::test_projectPartChooser_stopUsingFallbackFromModelManagerIf
void CppToolsPlugin::test_projectPartChooser_stopUsingFallbackFromModelManagerIfProjectChanges2()
{
ProjectPartChooserTest t;
t.fallbackProjectPart.reset(new ProjectPart);
t.fallbackProjectPart = ProjectPart::create({});
t.currentProjectPartInfo.projectPart = t.fallbackProjectPart;
t.currentProjectPartInfo.hints |= ProjectPartInfo::IsFallbackMatch;
const ProjectPart::Ptr addedProject(new ProjectPart);
const ProjectPart::Ptr addedProject = ProjectPart::create({});
t.projectPartsFromDependenciesForFile += addedProject;
t.projectsChanged = true;
@@ -306,7 +326,7 @@ void CppToolsPlugin::test_projectPartChooser_stopUsingFallbackFromModelManagerIf
void CppToolsPlugin::test_projectPartChooser_indicateFallbacktoProjectPartFromModelManager()
{
ProjectPartChooserTest t;
t.fallbackProjectPart.reset(new ProjectPart);
t.fallbackProjectPart = ProjectPart::create({});
QVERIFY(t.choose().hints & ProjectPartInfo::IsFallbackMatch);
}
@@ -314,7 +334,7 @@ void CppToolsPlugin::test_projectPartChooser_indicateFallbacktoProjectPartFromMo
void CppToolsPlugin::test_projectPartChooser_indicateFromDependencies()
{
ProjectPartChooserTest t;
t.projectPartsFromDependenciesForFile += ProjectPart::Ptr(new ProjectPart);
t.projectPartsFromDependenciesForFile += ProjectPart::create({});
QVERIFY(t.choose().hints & ProjectPartInfo::IsFromDependenciesMatch);
}
@@ -322,7 +342,7 @@ void CppToolsPlugin::test_projectPartChooser_indicateFromDependencies()
void CppToolsPlugin::test_projectPartChooser_doNotIndicateFromDependencies()
{
ProjectPartChooserTest t;
t.projectPartsForFile += ProjectPart::Ptr(new ProjectPart);
t.projectPartsForFile += ProjectPart::create({});
QVERIFY(!(t.choose().hints & ProjectPartInfo::IsFromDependenciesMatch));
}
@@ -351,14 +371,18 @@ private:
class ProjectInfoGeneratorTest
{
public:
ProjectInfo generate()
ProjectInfoGeneratorTest()
{
QFutureInterface<ProjectInfo> fi;
TestToolchain aToolChain;
projectUpdateInfo.cxxToolChainInfo = {&aToolChain, {}, {}};
projectUpdateInfo.cToolChainInfo = {&aToolChain, {}, {}};
}
ProjectInfo::Ptr generate()
{
QFutureInterface<ProjectInfo::Ptr> fi;
projectUpdateInfo.rawProjectParts += rawProjectPart;
projectUpdateInfo.cxxToolChain = &aToolChain;
projectUpdateInfo.cToolChain = &aToolChain;
ProjectInfoGenerator generator(fi, projectUpdateInfo);
return generator.generate();
@@ -372,37 +396,37 @@ public:
void CppToolsPlugin::test_projectInfoGenerator_createNoProjectPartsForEmptyFileList()
{
ProjectInfoGeneratorTest t;
const ProjectInfo projectInfo = t.generate();
const ProjectInfo::Ptr projectInfo = t.generate();
QVERIFY(projectInfo.projectParts().isEmpty());
QVERIFY(projectInfo->projectParts().isEmpty());
}
void CppToolsPlugin::test_projectInfoGenerator_createSingleProjectPart()
{
ProjectInfoGeneratorTest t;
t.rawProjectPart.files = QStringList{ "foo.cpp", "foo.h"};
const ProjectInfo projectInfo = t.generate();
const ProjectInfo::Ptr projectInfo = t.generate();
QCOMPARE(projectInfo.projectParts().size(), 1);
QCOMPARE(projectInfo->projectParts().size(), 1);
}
void CppToolsPlugin::test_projectInfoGenerator_createMultipleProjectParts()
{
ProjectInfoGeneratorTest t;
t.rawProjectPart.files = QStringList{ "foo.cpp", "foo.h", "bar.c", "bar.h" };
const ProjectInfo projectInfo = t.generate();
const ProjectInfo::Ptr projectInfo = t.generate();
QCOMPARE(projectInfo.projectParts().size(), 2);
QCOMPARE(projectInfo->projectParts().size(), 2);
}
void CppToolsPlugin::test_projectInfoGenerator_projectPartIndicatesObjectiveCExtensionsByDefault()
{
ProjectInfoGeneratorTest t;
t.rawProjectPart.files = QStringList{ "foo.mm" };
const ProjectInfo projectInfo = t.generate();
QCOMPARE(projectInfo.projectParts().size(), 1);
const ProjectInfo::Ptr projectInfo = t.generate();
QCOMPARE(projectInfo->projectParts().size(), 1);
const ProjectPart &projectPart = *projectInfo.projectParts().at(0);
const ProjectPart &projectPart = *projectInfo->projectParts().at(0);
QVERIFY(projectPart.languageExtensions & Utils::LanguageExtension::ObjectiveC);
}
@@ -410,10 +434,10 @@ void CppToolsPlugin::test_projectInfoGenerator_projectPartHasLatestLanguageVersi
{
ProjectInfoGeneratorTest t;
t.rawProjectPart.files = QStringList{ "foo.cpp" };
const ProjectInfo projectInfo = t.generate();
QCOMPARE(projectInfo.projectParts().size(), 1);
const ProjectInfo::Ptr projectInfo = t.generate();
QCOMPARE(projectInfo->projectParts().size(), 1);
const ProjectPart &projectPart = *projectInfo.projectParts().at(0);
const ProjectPart &projectPart = *projectInfo->projectParts().at(0);
QCOMPARE(projectPart.languageVersion, Utils::LanguageVersion::LatestCxx);
}
@@ -424,11 +448,11 @@ void CppToolsPlugin::test_projectInfoGenerator_useMacroInspectionReportForLangua
return TestToolchain::MacroInspectionReport{Macros(), Utils::LanguageVersion::CXX17};
};
t.rawProjectPart.files = QStringList{ "foo.cpp" };
const ProjectInfo projectInfo = t.generate();
const ProjectInfo::Ptr projectInfo = t.generate();
QCOMPARE(projectInfo.projectParts().size(), 1);
QCOMPARE(projectInfo->projectParts().size(), 1);
const ProjectPart &projectPart = *projectInfo.projectParts().at(0);
const ProjectPart &projectPart = *projectInfo->projectParts().at(0);
QCOMPARE(projectPart.languageVersion, Utils::LanguageVersion::CXX17);
}
@@ -437,11 +461,11 @@ void CppToolsPlugin::test_projectInfoGenerator_useCompilerFlagsForLanguageExtens
ProjectInfoGeneratorTest t;
t.rawProjectPart.files = QStringList{ "foo.cpp" };
t.rawProjectPart.flagsForCxx.languageExtensions = Utils::LanguageExtension::Microsoft;
const ProjectInfo projectInfo = t.generate();
const ProjectInfo::Ptr projectInfo = t.generate();
QCOMPARE(projectInfo.projectParts().size(), 1);
QCOMPARE(projectInfo->projectParts().size(), 1);
const ProjectPart &projectPart = *projectInfo.projectParts().at(0);
const ProjectPart &projectPart = *projectInfo->projectParts().at(0);
QVERIFY(projectPart.languageExtensions & Utils::LanguageExtension::Microsoft);
}
@@ -449,22 +473,22 @@ void CppToolsPlugin::test_projectInfoGenerator_projectFileKindsMatchProjectPartV
{
ProjectInfoGeneratorTest t;
t.rawProjectPart.files = QStringList{ "foo.h" };
const ProjectInfo projectInfo = t.generate();
const ProjectInfo::Ptr projectInfo = t.generate();
QCOMPARE(projectInfo.projectParts().size(), 4);
QVERIFY(Utils::contains(projectInfo.projectParts(), [](const ProjectPart::Ptr &p) {
QCOMPARE(projectInfo->projectParts().size(), 4);
QVERIFY(Utils::contains(projectInfo->projectParts(), [](const ProjectPart::Ptr &p) {
return p->languageVersion == Utils::LanguageVersion::LatestC
&& p->files.first().kind == ProjectFile::CHeader;
}));
QVERIFY(Utils::contains(projectInfo.projectParts(), [](const ProjectPart::Ptr &p) {
QVERIFY(Utils::contains(projectInfo->projectParts(), [](const ProjectPart::Ptr &p) {
return p->languageVersion == Utils::LanguageVersion::LatestC
&& p->files.first().kind == ProjectFile::ObjCHeader;
}));
QVERIFY(Utils::contains(projectInfo.projectParts(), [](const ProjectPart::Ptr &p) {
QVERIFY(Utils::contains(projectInfo->projectParts(), [](const ProjectPart::Ptr &p) {
return p->languageVersion == Utils::LanguageVersion::LatestCxx
&& p->files.first().kind == ProjectFile::CXXHeader;
}));
QVERIFY(Utils::contains(projectInfo.projectParts(), [](const ProjectPart::Ptr &p) {
QVERIFY(Utils::contains(projectInfo->projectParts(), [](const ProjectPart::Ptr &p) {
return p->languageVersion == Utils::LanguageVersion::LatestCxx
&& p->files.first().kind == ProjectFile::ObjCXXHeader;
}));
@@ -474,20 +498,18 @@ namespace {
class HeaderPathFilterTest
{
public:
HeaderPathFilterTest() : project({}, Utils::FilePath::fromString("test"))
ProjectPart finalize()
{
const auto headerPaths = HeaderPaths{
HeaderPath{"", HeaderPathType::BuiltIn},
HeaderPath{"/builtin_path", HeaderPathType::BuiltIn},
HeaderPath{"/system_path", HeaderPathType::System},
HeaderPath{"/framework_path", HeaderPathType::Framework},
HeaderPath{"/outside_project_user_path", HeaderPathType::User},
HeaderPath{"/build/user_path", HeaderPathType::User},
HeaderPath{"/buildb/user_path", HeaderPathType::User},
HeaderPath{"/projectb/user_path", HeaderPathType::User},
HeaderPath{"/project/user_path", HeaderPathType::User}};
projectPart.headerPaths = headerPaths;
projectPart.project = &project;
RawProjectPart rpp;
rpp.setHeaderPaths(headerPaths);
ToolChainInfo tcInfo;
tcInfo.type = toolchainType;
tcInfo.targetTriple = targetTriple;
tcInfo.installDir = toolchainInstallDir;
projectPart = ProjectPart::create({}, rpp, {}, {}, {}, {}, {}, tcInfo);
filter.emplace(HeaderPathFilter(*projectPart, UseTweakedHeaderPaths::No, {}, {},
"/project", "/build"));
return *projectPart;
}
static HeaderPath builtIn(const QString &path)
@@ -507,26 +529,43 @@ public:
return HeaderPath{path, HeaderPathType::User};
}
Project project;
ProjectPart projectPart;
HeaderPathFilter filter{projectPart, UseTweakedHeaderPaths::No, {}, {}, "/project", "/build"};
QString targetTriple;
Utils::Id toolchainType;
Utils::FilePath toolchainInstallDir;
HeaderPaths headerPaths = {
HeaderPath{"", HeaderPathType::BuiltIn},
HeaderPath{"/builtin_path", HeaderPathType::BuiltIn},
HeaderPath{"/system_path", HeaderPathType::System},
HeaderPath{"/framework_path", HeaderPathType::Framework},
HeaderPath{"/outside_project_user_path", HeaderPathType::User},
HeaderPath{"/build/user_path", HeaderPathType::User},
HeaderPath{"/buildb/user_path", HeaderPathType::User},
HeaderPath{"/projectb/user_path", HeaderPathType::User},
HeaderPath{"/project/user_path", HeaderPathType::User}};
Utils::optional<HeaderPathFilter> filter;
private:
ProjectPart::Ptr projectPart;
};
}
void CppToolsPlugin::test_headerPathFilter_builtin()
{
HeaderPathFilterTest t;
t.filter.process();
t.finalize();
t.filter->process();
QCOMPARE(t.filter.builtInHeaderPaths, (HeaderPaths{t.builtIn("/builtin_path")}));
QCOMPARE(t.filter->builtInHeaderPaths, (HeaderPaths{t.builtIn("/builtin_path")}));
}
void CppToolsPlugin::test_headerPathFilter_system()
{
HeaderPathFilterTest t;
t.filter.process();
t.finalize();
t.filter->process();
QCOMPARE(t.filter.systemHeaderPaths, (HeaderPaths{
QCOMPARE(t.filter->systemHeaderPaths, (HeaderPaths{
t.system("/project/.pre_includes"), t.system("/system_path"),
t.framework("/framework_path"), t.user("/outside_project_user_path"),
t.user("/buildb/user_path"), t.user("/projectb/user_path")}));
@@ -535,16 +574,16 @@ void CppToolsPlugin::test_headerPathFilter_system()
void CppToolsPlugin::test_headerPathFilter_user()
{
HeaderPathFilterTest t;
t.filter.process();
t.filter->process();
QCOMPARE(t.filter.userHeaderPaths, (HeaderPaths{t.user("/build/user_path"),
t.user("/project/user_path")}));
QCOMPARE(t.filter->userHeaderPaths, (HeaderPaths{t.user("/build/user_path"),
t.user("/project/user_path")}));
}
void CppToolsPlugin::test_headerPathFilter_noProjectPathSet()
{
HeaderPathFilterTest t;
HeaderPathFilter filter{t.projectPart, UseTweakedHeaderPaths::No};
HeaderPathFilter filter{t.finalize(), UseTweakedHeaderPaths::No};
filter.process();
QCOMPARE(filter.userHeaderPaths, (HeaderPaths{
@@ -556,20 +595,21 @@ void CppToolsPlugin::test_headerPathFilter_noProjectPathSet()
void CppToolsPlugin::test_headerPathFilter_dontAddInvalidPath()
{
HeaderPathFilterTest t;
t.filter.process();
QCOMPARE(t.filter.builtInHeaderPaths, (HeaderPaths{t.builtIn("/builtin_path")}));
QCOMPARE(t.filter.systemHeaderPaths, HeaderPaths({
t.finalize();
t.filter->process();
QCOMPARE(t.filter->builtInHeaderPaths, (HeaderPaths{t.builtIn("/builtin_path")}));
QCOMPARE(t.filter->systemHeaderPaths, HeaderPaths({
t.system("/project/.pre_includes"), t.system("/system_path"),
t.framework("/framework_path"), t.user("/outside_project_user_path"),
t.user("/buildb/user_path"), t.user("/projectb/user_path")}));
QCOMPARE(t.filter.userHeaderPaths, HeaderPaths({t.user("/build/user_path"),
t.user("/project/user_path")}));
QCOMPARE(t.filter->userHeaderPaths, HeaderPaths({t.user("/build/user_path"),
t.user("/project/user_path")}));
}
void CppToolsPlugin::test_headerPathFilter_clangHeadersPath()
{
HeaderPathFilterTest t;
HeaderPathFilter filter(t.projectPart, UseTweakedHeaderPaths::Yes, "6.0", "clang_dir");
HeaderPathFilter filter(t.finalize(), UseTweakedHeaderPaths::Yes, "6.0", "clang_dir");
filter.process();
QCOMPARE(filter.builtInHeaderPaths, (HeaderPaths{t.builtIn("clang_dir"),
@@ -579,7 +619,7 @@ void CppToolsPlugin::test_headerPathFilter_clangHeadersPath()
void CppToolsPlugin::test_headerPathFilter_clangHeadersPathWitoutClangVersion()
{
HeaderPathFilterTest t;
HeaderPathFilter filter(t.projectPart, UseTweakedHeaderPaths::Yes);
HeaderPathFilter filter(t.finalize(), UseTweakedHeaderPaths::Yes);
filter.process();
QCOMPARE(filter.builtInHeaderPaths, (HeaderPaths{t.builtIn("/builtin_path")}));
@@ -588,6 +628,7 @@ void CppToolsPlugin::test_headerPathFilter_clangHeadersPathWitoutClangVersion()
void CppToolsPlugin::test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderMacOs()
{
HeaderPathFilterTest t;
t.targetTriple = "x86_64-apple-darwin10";
const auto builtIns = {
t.builtIn("/usr/include/c++/4.2.1"), t.builtIn("/usr/include/c++/4.2.1/backward"),
t.builtIn("/usr/local/include"),
@@ -595,10 +636,9 @@ void CppToolsPlugin::test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderM
t.builtIn("/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include"),
t.builtIn("/usr/include")
};
t.projectPart.toolChainTargetTriple = "x86_64-apple-darwin10";
std::copy(builtIns.begin(), builtIns.end(),
std::inserter(t.projectPart.headerPaths, t.projectPart.headerPaths.begin()));
HeaderPathFilter filter(t.projectPart, UseTweakedHeaderPaths::Yes, "6.0", "clang_dir");
std::inserter(t.headerPaths, t.headerPaths.begin()));
HeaderPathFilter filter(t.finalize(), UseTweakedHeaderPaths::Yes, "6.0", "clang_dir");
filter.process();
QCOMPARE(filter.builtInHeaderPaths, (HeaderPaths{
@@ -612,15 +652,15 @@ void CppToolsPlugin::test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderM
void CppToolsPlugin::test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderLinux()
{
HeaderPathFilterTest t;
t.targetTriple = "x86_64-linux-gnu";
const auto builtIns = {
t.builtIn("/usr/include/c++/4.8"), t.builtIn("/usr/include/c++/4.8/backward"),
t.builtIn("/usr/include/x86_64-linux-gnu/c++/4.8"),
t.builtIn("/usr/local/include"), t.builtIn("/usr/lib/gcc/x86_64-linux-gnu/4.8/include"),
t.builtIn("/usr/include/x86_64-linux-gnu"), t.builtIn("/usr/include")};
std::copy(builtIns.begin(), builtIns.end(),
std::inserter(t.projectPart.headerPaths, t.projectPart.headerPaths.begin()));
t.projectPart.toolChainTargetTriple = "x86_64-linux-gnu";
HeaderPathFilter filter(t.projectPart, UseTweakedHeaderPaths::Yes, "6.0", "clang_dir");
std::inserter(t.headerPaths, t.headerPaths.begin()));
HeaderPathFilter filter(t.finalize(), UseTweakedHeaderPaths::Yes, "6.0", "clang_dir");
filter.process();
QCOMPARE(filter.builtInHeaderPaths, (HeaderPaths{
@@ -636,13 +676,13 @@ void CppToolsPlugin::test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderL
void CppToolsPlugin::test_headerPathFilter_removeGccInternalPaths()
{
HeaderPathFilterTest t;
t.projectPart.toolChainInstallDir = Utils::FilePath::fromUtf8("/usr/lib/gcc/x86_64-linux-gnu/7");
t.projectPart.toolchainType = Constants::GCC_TOOLCHAIN_TYPEID;
t.projectPart.headerPaths = {
t.toolchainInstallDir = Utils::FilePath::fromUtf8("/usr/lib/gcc/x86_64-linux-gnu/7");
t.toolchainType = Constants::GCC_TOOLCHAIN_TYPEID;
t.headerPaths = {
t.builtIn("/usr/lib/gcc/x86_64-linux-gnu/7/include"),
t.builtIn("/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed"),
};
HeaderPathFilter filter(t.projectPart, UseTweakedHeaderPaths::Yes, "6.0", "clang_dir");
HeaderPathFilter filter(t.finalize(), UseTweakedHeaderPaths::Yes, "6.0", "clang_dir");
filter.process();
QCOMPARE(filter.builtInHeaderPaths, (HeaderPaths{t.builtIn("clang_dir")}));
@@ -654,18 +694,17 @@ void CppToolsPlugin::test_headerPathFilter_removeGccInternalPaths()
void CppToolsPlugin::test_headerPathFilter_removeGccInternalPathsExceptForStandardPaths()
{
HeaderPathFilterTest t;
t.projectPart.toolChainInstallDir = Utils::FilePath::fromUtf8(
"c:/mingw/lib/gcc/x86_64-w64-mingw32/7.3.0");
t.projectPart.toolchainType = Constants::MINGW_TOOLCHAIN_TYPEID;
t.projectPart.headerPaths = {
t.toolchainInstallDir = Utils::FilePath::fromUtf8("c:/mingw/lib/gcc/x86_64-w64-mingw32/7.3.0");
t.toolchainType = Constants::MINGW_TOOLCHAIN_TYPEID;
t.headerPaths = {
t.builtIn("c:/mingw/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++"),
t.builtIn("c:/mingw/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/x86_64-w64-mingw32"),
t.builtIn("c:/mingw/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/backward"),
};
HeaderPaths expected = t.projectPart.headerPaths;
HeaderPaths expected = t.headerPaths;
expected.append(t.builtIn("clang_dir"));
HeaderPathFilter filter(t.projectPart, UseTweakedHeaderPaths::Yes, "6.0", "clang_dir");
HeaderPathFilter filter(t.finalize(), UseTweakedHeaderPaths::Yes, "6.0", "clang_dir");
filter.process();
QCOMPARE(filter.builtInHeaderPaths, expected);
@@ -674,14 +713,14 @@ void CppToolsPlugin::test_headerPathFilter_removeGccInternalPathsExceptForStanda
void CppToolsPlugin::test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderNoVersion()
{
HeaderPathFilterTest t;
t.projectPart.headerPaths = {
t.headerPaths = {
t.builtIn("C:/mingw/i686-w64-mingw32/include"),
t.builtIn("C:/mingw/i686-w64-mingw32/include/c++"),
t.builtIn("C:/mingw/i686-w64-mingw32/include/c++/i686-w64-mingw32"),
t.builtIn("C:/mingw/i686-w64-mingw32/include/c++/backward"),
};
t.projectPart.toolChainTargetTriple = "x86_64-w64-windows-gnu";
HeaderPathFilter filter(t.projectPart, UseTweakedHeaderPaths::Yes, "6.0", "clang_dir");
t.targetTriple = "x86_64-w64-windows-gnu";
HeaderPathFilter filter(t.finalize(), UseTweakedHeaderPaths::Yes, "6.0", "clang_dir");
filter.process();
QCOMPARE(filter.builtInHeaderPaths, (HeaderPaths{
@@ -695,15 +734,15 @@ void CppToolsPlugin::test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderN
void CppToolsPlugin::test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderAndroidClang()
{
HeaderPathFilterTest t;
t.projectPart.headerPaths = {
t.headerPaths = {
t.builtIn("C:/Android/sdk/ndk-bundle/sysroot/usr/include/i686-linux-android"),
t.builtIn("C:/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include"),
t.builtIn("C:/Android/sdk/ndk-bundle/sources/android/support/include"),
t.builtIn("C:/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++abi/include"),
t.builtIn("C:/Android/sdk/ndk-bundle/sysroot/usr/include")
};
t.projectPart.toolChainTargetTriple = "i686-linux-android";
HeaderPathFilter filter(t.projectPart, UseTweakedHeaderPaths::Yes, "6.0", "clang_dir");
t.targetTriple = "i686-linux-android";
HeaderPathFilter filter(t.finalize(), UseTweakedHeaderPaths::Yes, "6.0", "clang_dir");
filter.process();
QCOMPARE(filter.builtInHeaderPaths, (HeaderPaths{