Clang: Add defineName to ProjectPart

We need them later to find out if the defines have changes.

Change-Id: Iaaa14df3dc6f50cb286c2dac37db13c975063c1e
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2018-01-25 13:08:02 +01:00
parent 8beb205ee0
commit 22b5bbbff3
13 changed files with 50 additions and 3 deletions

View File

@@ -40,10 +40,12 @@ public:
ProjectPartContainer() = default; ProjectPartContainer() = default;
ProjectPartContainer(Utils::SmallString &&projectPartId, ProjectPartContainer(Utils::SmallString &&projectPartId,
Utils::SmallStringVector &&arguments, Utils::SmallStringVector &&arguments,
Utils::SmallStringVector &&defineNames,
FilePathIds &&headerPathIds, FilePathIds &&headerPathIds,
FilePathIds &&sourcePathIds) FilePathIds &&sourcePathIds)
: m_projectPartId(std::move(projectPartId)), : m_projectPartId(std::move(projectPartId)),
m_arguments(std::move(arguments)), m_arguments(std::move(arguments)),
m_defineNames(std::move(defineNames)),
m_headerPathIds(std::move(headerPathIds)), m_headerPathIds(std::move(headerPathIds)),
m_sourcePathIds(std::move(sourcePathIds)) m_sourcePathIds(std::move(sourcePathIds))
{ {
@@ -64,6 +66,11 @@ public:
return std::move(m_arguments); return std::move(m_arguments);
} }
const Utils::SmallStringVector &defineNames() const
{
return m_defineNames;
}
const FilePathIds &sourcePathIds() const const FilePathIds &sourcePathIds() const
{ {
return m_sourcePathIds; return m_sourcePathIds;
@@ -78,6 +85,7 @@ public:
{ {
out << container.m_projectPartId; out << container.m_projectPartId;
out << container.m_arguments; out << container.m_arguments;
out << container.m_defineNames;
out << container.m_headerPathIds; out << container.m_headerPathIds;
out << container.m_sourcePathIds; out << container.m_sourcePathIds;
@@ -88,6 +96,7 @@ public:
{ {
in >> container.m_projectPartId; in >> container.m_projectPartId;
in >> container.m_arguments; in >> container.m_arguments;
in >> container.m_defineNames;
in >> container.m_headerPathIds; in >> container.m_headerPathIds;
in >> container.m_sourcePathIds; in >> container.m_sourcePathIds;
@@ -98,14 +107,23 @@ public:
{ {
return first.m_projectPartId == second.m_projectPartId return first.m_projectPartId == second.m_projectPartId
&& first.m_arguments == second.m_arguments && first.m_arguments == second.m_arguments
&& first.m_defineNames == second.m_defineNames
&& first.m_headerPathIds == second.m_headerPathIds && first.m_headerPathIds == second.m_headerPathIds
&& first.m_sourcePathIds == second.m_sourcePathIds; && first.m_sourcePathIds == second.m_sourcePathIds;
} }
friend bool operator<(const ProjectPartContainer &first, const ProjectPartContainer &second) friend bool operator<(const ProjectPartContainer &first, const ProjectPartContainer &second)
{ {
return std::tie(first.m_projectPartId, first.m_arguments, first.m_headerPathIds, first.m_sourcePathIds) return std::tie(first.m_projectPartId,
< std::tie(second.m_projectPartId, second.m_arguments, second.m_headerPathIds, second.m_sourcePathIds); first.m_arguments,
first.m_defineNames,
first.m_headerPathIds,
first.m_sourcePathIds)
< std::tie(second.m_projectPartId,
second.m_arguments,
second.m_defineNames,
second.m_headerPathIds,
second.m_sourcePathIds);
} }
ProjectPartContainer clone() const ProjectPartContainer clone() const
@@ -116,6 +134,7 @@ public:
private: private:
Utils::SmallString m_projectPartId; Utils::SmallString m_projectPartId;
Utils::SmallStringVector m_arguments; Utils::SmallStringVector m_arguments;
Utils::SmallStringVector m_defineNames;
FilePathIds m_headerPathIds; FilePathIds m_headerPathIds;
FilePathIds m_sourcePathIds; FilePathIds m_sourcePathIds;
}; };

View File

@@ -35,6 +35,8 @@
#include <cpptools/compileroptionsbuilder.h> #include <cpptools/compileroptionsbuilder.h>
#include <cpptools/projectpart.h> #include <cpptools/projectpart.h>
#include <utils/algorithm.h>
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
@@ -119,6 +121,14 @@ QStringList ProjectUpdater::compilerArguments(CppTools::ProjectPart *projectPart
return builder.build(CppTools::ProjectFile::CXXHeader, CompilerOptionsBuilder::PchUsage::None); return builder.build(CppTools::ProjectFile::CXXHeader, CompilerOptionsBuilder::PchUsage::None);
} }
Utils::SmallStringVector ProjectUpdater::createDefineNames(CppTools::ProjectPart *projectPart)
{
return Utils::transform<Utils::SmallStringVector>(projectPart->projectMacros,
[] (const ProjectExplorer::Macro &macro) {
return macro.key;
});
}
ClangBackEnd::V2::ProjectPartContainer ProjectUpdater::toProjectPartContainer( ClangBackEnd::V2::ProjectPartContainer ProjectUpdater::toProjectPartContainer(
CppTools::ProjectPart *projectPart) const CppTools::ProjectPart *projectPart) const
{ {
@@ -129,6 +139,7 @@ ClangBackEnd::V2::ProjectPartContainer ProjectUpdater::toProjectPartContainer(
return ClangBackEnd::V2::ProjectPartContainer(projectPart->displayName, return ClangBackEnd::V2::ProjectPartContainer(projectPart->displayName,
Utils::SmallStringVector(arguments), Utils::SmallStringVector(arguments),
createDefineNames(projectPart),
std::move(headerAndSources.headers), std::move(headerAndSources.headers),
std::move(headerAndSources.sources)); std::move(headerAndSources.sources));
} }

View File

@@ -73,6 +73,7 @@ unittest_public:
void addToHeaderAndSources(HeaderAndSources &headerAndSources, void addToHeaderAndSources(HeaderAndSources &headerAndSources,
const CppTools::ProjectFile &projectFile) const; const CppTools::ProjectFile &projectFile) const;
static QStringList compilerArguments(CppTools::ProjectPart *projectPart); static QStringList compilerArguments(CppTools::ProjectPart *projectPart);
static Utils::SmallStringVector createDefineNames(CppTools::ProjectPart *projectPart);
static Utils::PathStringVector createExcludedPaths( static Utils::PathStringVector createExcludedPaths(
const ClangBackEnd::V2::FileContainers &generatedFiles); const ClangBackEnd::V2::FileContainers &generatedFiles);

View File

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

View File

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

View File

@@ -70,10 +70,12 @@ protected:
std::vector<ClangBackEnd::IdPaths> idPaths = {{projectPartId1, {{1, 1}, {1, 2}}}}; std::vector<ClangBackEnd::IdPaths> idPaths = {{projectPartId1, {{1, 1}, {1, 2}}}};
ProjectPartContainer projectPart1{projectPartId1.clone(), ProjectPartContainer projectPart1{projectPartId1.clone(),
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"}, {"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
{"DEFINE"},
{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"},
{id(header2Path)}, {id(header2Path)},
{id(main2Path)}}; {id(main2Path)}};
std::vector<ProjectPartContainer> projectParts{projectPart1, projectPart2}; std::vector<ProjectPartContainer> projectParts{projectPart1, projectPart2};

View File

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

View File

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

View File

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

View File

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

View File

@@ -76,10 +76,12 @@ protected:
ClangBackEnd::FilePathId generatedFilePathId{1, 21}; ClangBackEnd::FilePathId generatedFilePathId{1, 21};
ProjectPartContainer projectPart1{"project1", ProjectPartContainer projectPart1{"project1",
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"}, {"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
{"DEFINE"},
{header1PathId}, {header1PathId},
{main1PathId}}; {main1PathId}};
ProjectPartContainer projectPart2{"project2", ProjectPartContainer projectPart2{"project2",
{"-I", TESTDATA_DIR, "-x", "c++-header", "-Wno-pragma-once-outside-header"}, {"-I", TESTDATA_DIR, "-x", "c++-header", "-Wno-pragma-once-outside-header"},
{"DEFINE"},
{header2PathId}, {header2PathId},
{main2PathId}}; {main2PathId}};
FileContainers unsaved{{{TESTDATA_DIR, "query_simplefunction.h"}, FileContainers unsaved{{{TESTDATA_DIR, "query_simplefunction.h"},

View File

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