From 5c7f49f27841a4620fc6708d1c5fedce7c4eeca2 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 2 Feb 2017 11:46:19 +0100 Subject: [PATCH] Clang: Use the whole path in the IncludeCollector Change-Id: I406f0050b0c244b6c0d1352b5889d4e65a43fa33 Reviewed-by: Tim Jenssen --- .../collectincludespreprocessorcallbacks.h | 15 ++++++-- tests/unit/unittest/includecollector-test.cpp | 14 ++++---- tests/unit/unittest/pchcreator-test.cpp | 34 +++++++++---------- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/tools/clangpchmanagerbackend/source/collectincludespreprocessorcallbacks.h b/src/tools/clangpchmanagerbackend/source/collectincludespreprocessorcallbacks.h index 4c27e421d5d..137b462adaf 100644 --- a/src/tools/clangpchmanagerbackend/source/collectincludespreprocessorcallbacks.h +++ b/src/tools/clangpchmanagerbackend/source/collectincludespreprocessorcallbacks.h @@ -60,7 +60,7 @@ public: bool /*isAngled*/, clang::CharSourceRange /*fileNameRange*/, const clang::FileEntry *file, - llvm::StringRef /*searchPath*/, + llvm::StringRef searchPath, llvm::StringRef /*relativePath*/, const clang::Module * /*imported*/) override { @@ -73,7 +73,10 @@ public: auto notAlreadyIncluded = isNotAlreadyIncluded(fileUID); if (notAlreadyIncluded.first) { m_alreadyIncludedFileUIDs.insert(notAlreadyIncluded.second, fileUID); - uint includeId = m_filePathCache.stringId({fileName.data(), fileName.size()}); + Utils::PathString filePath = fromNativePath({{searchPath.data(), searchPath.size()}, + "/", + {fileName.data(), fileName.size()}}); + uint includeId = m_filePathCache.stringId(filePath); m_includeIds.emplace_back(includeId); } } @@ -105,6 +108,14 @@ public: } + Utils::PathString fromNativePath(Utils::PathString &&filePath) + { +#ifdef _WIN32 + filePath.replace('\\', '/'); +#endif + return std::move(filePath); + } + private: clang::HeaderSearch &m_headerSearch; std::vector &m_includeIds; diff --git a/tests/unit/unittest/includecollector-test.cpp b/tests/unit/unittest/includecollector-test.cpp index 50c0529e781..663de3feddc 100644 --- a/tests/unit/unittest/includecollector-test.cpp +++ b/tests/unit/unittest/includecollector-test.cpp @@ -52,15 +52,15 @@ TEST_F(IncludeCollector, IncludesExternalHeader) collector.collectIncludes(); ASSERT_THAT(collector.takeIncludeIds(), - AllOf(Contains(id("includecollector_external1.h")), - Contains(id("../data/includecollector_external2.h")))); + AllOf(Contains(id(TESTDATA_DIR "/includecollector_external1.h")), + Contains(id(TESTDATA_DIR "/../data/includecollector_external2.h")))); } TEST_F(IncludeCollector, DoesNotIncludesInternalHeader) { collector.collectIncludes(); - ASSERT_THAT(collector.takeIncludeIds(), Not(Contains(id("includecollector_header1.h")))); + ASSERT_THAT(collector.takeIncludeIds(), Not(Contains(id(TESTDATA_DIR "/includecollector_header1.h")))); } TEST_F(IncludeCollector, NoDuplicate) @@ -68,8 +68,8 @@ TEST_F(IncludeCollector, NoDuplicate) collector.collectIncludes(); ASSERT_THAT(collector.takeIncludeIds(), - UnorderedElementsAre(id("includecollector_external1.h"), - id("../data/includecollector_external2.h"))); + UnorderedElementsAre(id(TESTDATA_DIR "/includecollector_external1.h"), + id(TESTDATA_DIR "/../data/includecollector_external2.h"))); } TEST_F(IncludeCollector, IncludesAreSorted) @@ -77,8 +77,8 @@ TEST_F(IncludeCollector, IncludesAreSorted) collector.collectIncludes(); ASSERT_THAT(collector.takeIncludeIds(), - ElementsAre(id("includecollector_external1.h"), - id("../data/includecollector_external2.h"))); + ElementsAre(id(TESTDATA_DIR "/includecollector_external1.h"), + id(TESTDATA_DIR "/../data/includecollector_external2.h"))); } void IncludeCollector::SetUp() diff --git a/tests/unit/unittest/pchcreator-test.cpp b/tests/unit/unittest/pchcreator-test.cpp index 668704c3156..df6e5764bb0 100644 --- a/tests/unit/unittest/pchcreator-test.cpp +++ b/tests/unit/unittest/pchcreator-test.cpp @@ -132,16 +132,16 @@ TEST_F(PchCreatorVerySlowTest, CreateGlobalPchIncludes) auto includeIds = creator.generateGlobalPchIncludeIds(); ASSERT_THAT(includeIds, - UnorderedElementsAre(id("includecollector_external3.h"), - id("includecollector_external1.h"), - id("includecollector_external2.h"))); + UnorderedElementsAre(id(TESTDATA_DIR "/includecollector_external3.h"), + id(TESTDATA_DIR "/includecollector_external1.h"), + id(TESTDATA_DIR "/includecollector_external2.h"))); } TEST_F(PchCreatorVerySlowTest, CreateGlobalPchFileContent) { auto content = creator.generateGlobalPchHeaderFileContent(); - ASSERT_THAT(content, "#include \n#include \n#include \n"); + ASSERT_THAT(content, "#include <" TESTDATA_DIR "/includecollector_external3.h>\n#include <" TESTDATA_DIR "/includecollector_external1.h>\n#include <" TESTDATA_DIR "/includecollector_external2.h>\n"); } TEST_F(PchCreatorVerySlowTest, CreateGlobalPchHeaderFile) @@ -151,7 +151,7 @@ TEST_F(PchCreatorVerySlowTest, CreateGlobalPchHeaderFile) auto content = file->readAll(); - ASSERT_THAT(content, "#include \n#include \n#include \n"); + ASSERT_THAT(content, "#include <" TESTDATA_DIR "/includecollector_external3.h>\n#include <" TESTDATA_DIR "/includecollector_external1.h>\n#include <" TESTDATA_DIR "/includecollector_external2.h>\n"); } TEST_F(PchCreator, ConvertToQStringList) @@ -203,9 +203,9 @@ TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludes) { auto includeIds = creator.generateProjectPartPchIncludes(projectPart1); - ASSERT_THAT(includeIds, UnorderedElementsAre(id("includecollector_external1.h"), - id("includecollector_external2.h"), - id("includecollector_header2.h"))); + ASSERT_THAT(includeIds, UnorderedElementsAre(id(TESTDATA_DIR "/includecollector_external1.h"), + id(TESTDATA_DIR "/includecollector_external2.h"), + id(TESTDATA_DIR "/includecollector_header2.h"))); } TEST_F(PchCreatorSlowTest, CreateProjectPartPchFileContent) @@ -214,7 +214,7 @@ TEST_F(PchCreatorSlowTest, CreateProjectPartPchFileContent) auto content = creator.generatePchIncludeFileContent(includes); - ASSERT_THAT(content, "#include \n#include \n#include \n"); + ASSERT_THAT(content, "#include <" TESTDATA_DIR "/includecollector_header2.h>\n#include <" TESTDATA_DIR "/includecollector_external1.h>\n#include <" TESTDATA_DIR "/includecollector_external2.h>\n"); } TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludeFile) @@ -227,7 +227,7 @@ TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludeFile) auto fileContent = file->readAll(); - ASSERT_THAT(fileContent, "#include \n#include \n#include \n"); + ASSERT_THAT(fileContent, "#include <" TESTDATA_DIR "/includecollector_header2.h>\n#include <" TESTDATA_DIR "/includecollector_external1.h>\n#include <" TESTDATA_DIR "/includecollector_external2.h>\n"); } TEST_F(PchCreator, CreateProjectPartPchCompilerArguments) @@ -303,14 +303,14 @@ TEST_F(PchCreatorVerySlowTest, IdPathsForCreatePchsForProjectParts) ASSERT_THAT(creator.takeProjectsIncludes(), ElementsAre(AllOf(Field(&IdPaths::id, "project1"), - Field(&IdPaths::paths, UnorderedElementsAre(id("includecollector_header2.h"), - id("includecollector_external1.h"), - id("includecollector_external2.h")))), + Field(&IdPaths::paths, UnorderedElementsAre(id(TESTDATA_DIR "/includecollector_header2.h"), + id(TESTDATA_DIR "/includecollector_external1.h"), + id(TESTDATA_DIR "/includecollector_external2.h")))), AllOf(Field(&IdPaths::id, "project2"), - Field(&IdPaths::paths, UnorderedElementsAre(id("includecollector_external1.h"), - id("includecollector_external3.h"), - id("includecollector_header1.h"), - id("../data/includecollector_external2.h")))))); + Field(&IdPaths::paths, UnorderedElementsAre(id(TESTDATA_DIR "/includecollector_external1.h"), + id(TESTDATA_DIR "/includecollector_external3.h"), + id(TESTDATA_DIR "/includecollector_header1.h"), + id(TESTDATA_DIR "/../data/includecollector_external2.h")))))); } uint PchCreator::id(const Utils::SmallString &path)