dgoldman created this revision. dgoldman added a reviewer: sammccall. dgoldman requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Previously, the Framework name was only set if the file came from a header mapped framework; now we'll always set the framework name if the file is in a framework. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D117830 Files: clang/lib/Lex/HeaderSearch.cpp clang/unittests/Lex/HeaderSearchTest.cpp Index: clang/unittests/Lex/HeaderSearchTest.cpp =================================================================== --- clang/unittests/Lex/HeaderSearchTest.cpp +++ clang/unittests/Lex/HeaderSearchTest.cpp @@ -187,6 +187,32 @@ "Sub/Sub.h"); } +TEST_F(HeaderSearchTest, HeaderFrameworkLookup) { + std::string HeaderPath = "/tmp/Frameworks/Foo.framework/Headers/Foo.h"; + addSystemFrameworkSearchDir("/tmp/Frameworks"); + VFS->addFile( + HeaderPath, 0, + llvm::MemoryBuffer::getMemBufferCopy("", HeaderPath), + /*User=*/None, /*Group=*/None, llvm::sys::fs::file_type::regular_file); + + bool IsFrameworkFound = false; + const DirectoryLookup *CurDir = nullptr; + auto FoundFile = Search.LookupFile( + "Foo/Foo.h", SourceLocation(), /*isAngled=*/true, /*FromDir=*/nullptr, + CurDir, /*Includers=*/{}, /*SearchPath=*/nullptr, + /*RelativePath=*/nullptr, /*RequestingModule=*/nullptr, + /*SuggestedModule=*/nullptr, /*IsMapped=*/nullptr, + &IsFrameworkFound); + + EXPECT_TRUE(FoundFile.hasValue()); + EXPECT_TRUE(IsFrameworkFound); + auto &FE = FoundFile.getValue(); + auto FI = Search.getExistingFileInfo(FE); + EXPECT_TRUE(FI); + EXPECT_TRUE(FI->IsValid); + EXPECT_EQ(FI->Framework.str(), "Foo"); +} + // Helper struct with null terminator character to make MemoryBuffer happy. template <class FileTy, class PaddingTy> struct NullTerminatedFile : public FileTy { Index: clang/lib/Lex/HeaderSearch.cpp =================================================================== --- clang/lib/Lex/HeaderSearch.cpp +++ clang/lib/Lex/HeaderSearch.cpp @@ -1049,6 +1049,11 @@ getUniqueFrameworkName(StringRef(Filename.begin(), SlashPos)); if (CurDir->isIndexHeaderMap()) HFI.IndexHeaderMapHeader = 1; + } else if (CurDir->isFramework()) { + size_t SlashPos = Filename.find('/'); + if (SlashPos != StringRef::npos) + HFI.Framework = + getUniqueFrameworkName(StringRef(Filename.begin(), SlashPos)); } if (checkMSVCHeaderSearch(Diags, MSFE ? &MSFE->getFileEntry() : nullptr,
Index: clang/unittests/Lex/HeaderSearchTest.cpp =================================================================== --- clang/unittests/Lex/HeaderSearchTest.cpp +++ clang/unittests/Lex/HeaderSearchTest.cpp @@ -187,6 +187,32 @@ "Sub/Sub.h"); } +TEST_F(HeaderSearchTest, HeaderFrameworkLookup) { + std::string HeaderPath = "/tmp/Frameworks/Foo.framework/Headers/Foo.h"; + addSystemFrameworkSearchDir("/tmp/Frameworks"); + VFS->addFile( + HeaderPath, 0, + llvm::MemoryBuffer::getMemBufferCopy("", HeaderPath), + /*User=*/None, /*Group=*/None, llvm::sys::fs::file_type::regular_file); + + bool IsFrameworkFound = false; + const DirectoryLookup *CurDir = nullptr; + auto FoundFile = Search.LookupFile( + "Foo/Foo.h", SourceLocation(), /*isAngled=*/true, /*FromDir=*/nullptr, + CurDir, /*Includers=*/{}, /*SearchPath=*/nullptr, + /*RelativePath=*/nullptr, /*RequestingModule=*/nullptr, + /*SuggestedModule=*/nullptr, /*IsMapped=*/nullptr, + &IsFrameworkFound); + + EXPECT_TRUE(FoundFile.hasValue()); + EXPECT_TRUE(IsFrameworkFound); + auto &FE = FoundFile.getValue(); + auto FI = Search.getExistingFileInfo(FE); + EXPECT_TRUE(FI); + EXPECT_TRUE(FI->IsValid); + EXPECT_EQ(FI->Framework.str(), "Foo"); +} + // Helper struct with null terminator character to make MemoryBuffer happy. template <class FileTy, class PaddingTy> struct NullTerminatedFile : public FileTy { Index: clang/lib/Lex/HeaderSearch.cpp =================================================================== --- clang/lib/Lex/HeaderSearch.cpp +++ clang/lib/Lex/HeaderSearch.cpp @@ -1049,6 +1049,11 @@ getUniqueFrameworkName(StringRef(Filename.begin(), SlashPos)); if (CurDir->isIndexHeaderMap()) HFI.IndexHeaderMapHeader = 1; + } else if (CurDir->isFramework()) { + size_t SlashPos = Filename.find('/'); + if (SlashPos != StringRef::npos) + HFI.Framework = + getUniqueFrameworkName(StringRef(Filename.begin(), SlashPos)); } if (checkMSVCHeaderSearch(Diags, MSFE ? &MSFE->getFileEntry() : nullptr,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits