14 #include "llvm/ADT/DenseMap.h" 15 #include "llvm/ADT/STLExtras.h" 16 #include "llvm/ADT/StringExtras.h" 17 #include "llvm/ADT/StringSet.h" 18 #include "llvm/ADT/iterator_range.h" 19 #include "llvm/Config/llvm-config.h" 20 #include "llvm/Support/Debug.h" 21 #include "llvm/Support/Errc.h" 22 #include "llvm/Support/MemoryBuffer.h" 23 #include "llvm/Support/Path.h" 24 #include "llvm/Support/Process.h" 25 #include "llvm/Support/YAMLParser.h" 30 using namespace clang;
33 using llvm::sys::fs::file_status;
34 using llvm::sys::fs::file_type;
35 using llvm::sys::fs::perms;
36 using llvm::sys::fs::UniqueID;
39 : UID(Status.getUniqueID()), MTime(Status.getLastModificationTime()),
40 User(Status.getUser()), Group(Status.getGroup()), Size(Status.getSize()),
41 Type(Status.
type()), Perms(Status.permissions()), IsVFSMapped(
false) {}
43 Status::Status(StringRef Name, UniqueID UID, sys::TimePoint<> MTime,
44 uint32_t User, uint32_t Group, uint64_t Size, file_type
Type,
46 : Name(Name), UID(UID), MTime(MTime), User(User), Group(Group), Size(Size),
47 Type(Type), Perms(Perms), IsVFSMapped(
false) {}
49 Status Status::copyWithNewName(
const Status &In, StringRef NewName) {
55 Status Status::copyWithNewName(
const file_status &In, StringRef NewName) {
56 return Status(NewName, In.getUniqueID(), In.getLastModificationTime(),
57 In.getUser(), In.getGroup(), In.getSize(), In.type(),
61 bool Status::equivalent(
const Status &Other)
const {
65 bool Status::isDirectory()
const {
66 return Type == file_type::directory_file;
68 bool Status::isRegularFile()
const {
69 return Type == file_type::regular_file;
71 bool Status::isOther()
const {
72 return exists() && !isRegularFile() && !isDirectory() && !isSymlink();
74 bool Status::isSymlink()
const {
75 return Type == file_type::symlink_file;
77 bool Status::isStatusKnown()
const {
78 return Type != file_type::status_error;
80 bool Status::exists()
const {
81 return isStatusKnown() &&
Type != file_type::file_not_found;
86 FileSystem::~FileSystem() {}
88 ErrorOr<std::unique_ptr<MemoryBuffer>>
89 FileSystem::getBufferForFile(
const llvm::Twine &Name, int64_t FileSize,
90 bool RequiresNullTerminator,
bool IsVolatile) {
91 auto F = openFileForRead(Name);
95 return (*F)->getBuffer(Name, FileSize, RequiresNullTerminator, IsVolatile);
99 if (llvm::sys::path::is_absolute(Path))
100 return std::error_code();
102 auto WorkingDir = getCurrentWorkingDirectory();
104 return WorkingDir.getError();
106 return llvm::sys::fs::make_absolute(WorkingDir.get(), Path);
109 bool FileSystem::exists(
const Twine &Path) {
110 auto Status = status(Path);
116 return Component.equals(
"..") || Component.equals(
".");
121 for (StringRef Comp : llvm::make_range(path::begin(Path), path::end(Path)))
134 class RealFile :
public File {
137 std::string RealName;
138 friend class RealFileSystem;
139 RealFile(
int FD, StringRef NewName, StringRef NewRealPathName)
140 : FD(FD), S(NewName, {}, {}, {}, {}, {},
141 llvm::sys::fs::file_type::status_error, {}),
142 RealName(NewRealPathName.str()) {
143 assert(FD >= 0 &&
"Invalid or inactive file descriptor");
147 ~RealFile()
override;
148 ErrorOr<Status> status()
override;
149 ErrorOr<std::string> getName()
override;
150 ErrorOr<std::unique_ptr<MemoryBuffer>> getBuffer(
const Twine &Name,
152 bool RequiresNullTerminator,
153 bool IsVolatile)
override;
154 std::error_code close()
override;
157 RealFile::~RealFile() { close(); }
159 ErrorOr<Status> RealFile::status() {
160 assert(FD != -1 &&
"cannot stat closed file");
161 if (!S.isStatusKnown()) {
162 file_status RealStatus;
163 if (std::error_code EC = sys::fs::status(FD, RealStatus))
165 S = Status::copyWithNewName(RealStatus, S.getName());
170 ErrorOr<std::string> RealFile::getName() {
171 return RealName.empty() ? S.getName().str() : RealName;
174 ErrorOr<std::unique_ptr<MemoryBuffer>>
175 RealFile::getBuffer(
const Twine &Name, int64_t FileSize,
176 bool RequiresNullTerminator,
bool IsVolatile) {
177 assert(FD != -1 &&
"cannot get buffer for closed file");
178 return MemoryBuffer::getOpenFile(FD, Name, FileSize, RequiresNullTerminator,
182 std::error_code RealFile::close() {
183 std::error_code EC = sys::Process::SafelyCloseFileDescriptor(FD);
192 ErrorOr<Status> status(
const Twine &Path)
override;
193 ErrorOr<std::unique_ptr<File>> openFileForRead(
const Twine &Path)
override;
196 llvm::ErrorOr<std::string> getCurrentWorkingDirectory()
const override;
197 std::error_code setCurrentWorkingDirectory(
const Twine &Path)
override;
201 ErrorOr<Status> RealFileSystem::status(
const Twine &Path) {
202 sys::fs::file_status RealStatus;
203 if (std::error_code EC = sys::fs::status(Path, RealStatus))
205 return Status::copyWithNewName(RealStatus, Path.str());
208 ErrorOr<std::unique_ptr<File>>
209 RealFileSystem::openFileForRead(
const Twine &Name) {
212 if (std::error_code EC = sys::fs::openFileForRead(Name, FD, &RealName))
214 return std::unique_ptr<File>(
new RealFile(FD, Name.str(), RealName.str()));
217 llvm::ErrorOr<std::string> RealFileSystem::getCurrentWorkingDirectory()
const {
219 if (std::error_code EC = llvm::sys::fs::current_path(Dir))
221 return Dir.str().str();
224 std::error_code RealFileSystem::setCurrentWorkingDirectory(
const Twine &Path) {
232 return llvm::sys::fs::set_current_path(Path);
242 llvm::sys::fs::directory_iterator Iter;
244 RealFSDirIter(
const Twine &Path, std::error_code &EC) : Iter(Path, EC) {
245 if (!EC && Iter != llvm::sys::fs::directory_iterator()) {
246 llvm::sys::fs::file_status S;
247 EC = llvm::sys::fs::status(Iter->path(), S,
true);
248 CurrentEntry = Status::copyWithNewName(S, Iter->path());
252 std::error_code increment()
override {
257 }
else if (Iter == llvm::sys::fs::directory_iterator()) {
260 llvm::sys::fs::file_status S;
261 EC = llvm::sys::fs::status(Iter->path(), S,
true);
262 CurrentEntry = Status::copyWithNewName(S, Iter->path());
270 std::error_code &EC) {
278 FSList.push_back(std::move(BaseFS));
282 FSList.push_back(FS);
285 FS->setCurrentWorkingDirectory(getCurrentWorkingDirectory().
get());
288 ErrorOr<Status> OverlayFileSystem::status(
const Twine &Path) {
290 for (
iterator I = overlays_begin(), E = overlays_end(); I != E; ++I) {
291 ErrorOr<Status>
Status = (*I)->status(Path);
292 if (Status || Status.getError() != llvm::errc::no_such_file_or_directory)
298 ErrorOr<std::unique_ptr<File>>
299 OverlayFileSystem::openFileForRead(
const llvm::Twine &Path) {
301 for (
iterator I = overlays_begin(), E = overlays_end(); I != E; ++I) {
302 auto Result = (*I)->openFileForRead(Path);
303 if (
Result ||
Result.getError() != llvm::errc::no_such_file_or_directory)
309 llvm::ErrorOr<std::string>
310 OverlayFileSystem::getCurrentWorkingDirectory()
const {
312 return FSList.front()->getCurrentWorkingDirectory();
315 OverlayFileSystem::setCurrentWorkingDirectory(
const Twine &Path) {
316 for (
auto &FS : FSList)
317 if (std::error_code EC = FS->setCurrentWorkingDirectory(Path))
319 return std::error_code();
330 llvm::StringSet<> SeenNames;
332 std::error_code incrementFS() {
333 assert(CurrentFS != Overlays.
overlays_end() &&
"incrementing past end");
335 for (
auto E = Overlays.
overlays_end(); CurrentFS != E; ++CurrentFS) {
337 CurrentDirIter = (*CurrentFS)->dir_begin(Path, EC);
338 if (EC && EC != errc::no_such_file_or_directory)
343 return std::error_code();
346 std::error_code incrementDirIter(
bool IsFirstTime) {
348 "incrementing past end");
357 std::error_code incrementImpl(
bool IsFirstTime) {
359 std::error_code EC = incrementDirIter(IsFirstTime);
364 CurrentEntry = *CurrentDirIter;
365 StringRef Name = llvm::sys::path::filename(CurrentEntry.getName());
366 if (SeenNames.insert(Name).second)
369 llvm_unreachable(
"returned above");
375 : Overlays(FS), Path(Path.str()), CurrentFS(Overlays.
overlays_begin()) {
376 CurrentDirIter = (*CurrentFS)->dir_begin(Path, EC);
377 EC = incrementImpl(
true);
380 std::error_code increment()
override {
return incrementImpl(
false); }
385 std::error_code &EC) {
387 std::make_shared<OverlayFSDirIterImpl>(Dir, *
this, EC));
404 : Stat(
std::move(Stat)), Kind(Kind) {}
408 virtual std::string
toString(
unsigned Indent)
const = 0;
413 std::unique_ptr<llvm::MemoryBuffer> Buffer;
416 InMemoryFile(
Status Stat, std::unique_ptr<llvm::MemoryBuffer> Buffer)
419 llvm::MemoryBuffer *getBuffer() {
return Buffer.get(); }
420 std::string
toString(
unsigned Indent)
const override {
421 return (std::string(Indent,
' ') + getStatus().getName() +
"\n").str();
429 class InMemoryFileAdaptor :
public File {
433 explicit InMemoryFileAdaptor(InMemoryFile &Node) :
Node(Node) {}
435 llvm::ErrorOr<Status> status()
override {
return Node.getStatus(); }
436 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
437 getBuffer(
const Twine &Name, int64_t FileSize,
bool RequiresNullTerminator,
438 bool IsVolatile)
override {
439 llvm::MemoryBuffer *Buf = Node.getBuffer();
440 return llvm::MemoryBuffer::getMemBuffer(
441 Buf->getBuffer(), Buf->getBufferIdentifier(), RequiresNullTerminator);
443 std::error_code close()
override {
return std::error_code(); }
448 std::map<std::string, std::unique_ptr<InMemoryNode>> Entries;
454 auto I = Entries.find(Name);
455 if (I != Entries.end())
456 return I->second.get();
460 return Entries.insert(make_pair(Name, std::move(Child)))
461 .first->second.get();
464 typedef decltype(Entries)::const_iterator const_iterator;
465 const_iterator
begin()
const {
return Entries.begin(); }
466 const_iterator
end()
const {
return Entries.end(); }
468 std::string
toString(
unsigned Indent)
const override {
470 (std::string(Indent,
' ') + getStatus().getName() +
"\n").str();
471 for (
const auto &Entry : Entries) {
472 Result += Entry.second->toString(Indent + 2);
482 InMemoryFileSystem::InMemoryFileSystem(
bool UseNormalizedPaths)
483 : Root(new detail::InMemoryDirectory(
485 0,
llvm::sys::fs::file_type::directory_file,
486 llvm::sys::fs::perms::all_all))),
487 UseNormalizedPaths(UseNormalizedPaths) {}
492 return Root->toString(0);
496 std::unique_ptr<llvm::MemoryBuffer> Buffer,
510 llvm::sys::path::remove_dots(Path,
true);
516 auto I = llvm::sys::path::begin(Path), E = sys::path::end(Path);
517 const auto ResolvedUser = User.getValueOr(0);
518 const auto ResolvedGroup = Group.getValueOr(0);
519 const auto ResolvedType = Type.getValueOr(sys::fs::file_type::regular_file);
520 const auto ResolvedPerms = Perms.getValueOr(sys::fs::all_all);
523 const auto NewDirectoryPerms = ResolvedPerms | sys::fs::owner_all;
532 llvm::sys::toTimePoint(ModificationTime), ResolvedUser,
533 ResolvedGroup, Buffer->getBufferSize(), ResolvedType,
535 std::unique_ptr<detail::InMemoryNode> Child;
536 if (ResolvedType == sys::fs::file_type::directory_file) {
539 Child.reset(
new detail::InMemoryFile(std::move(Stat),
542 Dir->
addChild(Name, std::move(Child));
548 StringRef(Path.str().begin(), Name.end() - Path.str().begin()),
550 ResolvedUser, ResolvedGroup, Buffer->getBufferSize(),
551 sys::fs::file_type::directory_file, NewDirectoryPerms);
552 Dir = cast<detail::InMemoryDirectory>(Dir->addChild(
553 Name, llvm::make_unique<detail::InMemoryDirectory>(std::move(Stat))));
557 if (
auto *NewDir = dyn_cast<detail::InMemoryDirectory>(Node)) {
560 assert(isa<detail::InMemoryFile>(Node) &&
561 "Must be either file or directory!");
568 return cast<detail::InMemoryFile>(
Node)->getBuffer()->getBuffer() ==
575 llvm::MemoryBuffer *Buffer,
580 return addFile(P, ModificationTime,
581 llvm::MemoryBuffer::getMemBuffer(
582 Buffer->getBuffer(), Buffer->getBufferIdentifier()),
583 std::move(User), std::move(Group), std::move(Type),
587 static ErrorOr<detail::InMemoryNode *>
599 llvm::sys::path::remove_dots(Path,
true);
604 auto I = llvm::sys::path::begin(Path), E = llvm::sys::path::end(Path);
609 return errc::no_such_file_or_directory;
612 if (
auto File = dyn_cast<detail::InMemoryFile>(Node)) {
615 return errc::no_such_file_or_directory;
619 Dir = cast<detail::InMemoryDirectory>(
Node);
628 return (*Node)->getStatus();
629 return Node.getError();
632 llvm::ErrorOr<std::unique_ptr<File>>
636 return Node.getError();
640 if (
auto *F = dyn_cast<detail::InMemoryFile>(*
Node))
641 return std::unique_ptr<File>(
new detail::InMemoryFileAdaptor(*F));
654 InMemoryDirIterator() {}
658 CurrentEntry = I->second->getStatus();
661 std::error_code increment()
override {
665 CurrentEntry = I != E ? I->second->getStatus() :
Status();
666 return std::error_code();
672 std::error_code &EC) {
675 EC =
Node.getError();
679 if (
auto *DirNode = dyn_cast<detail::InMemoryDirectory>(*
Node))
696 llvm::sys::path::remove_dots(Path,
true);
699 WorkingDirectory = Path.str();
700 return std::error_code();
724 StringRef getName()
const {
return Name; }
728 class RedirectingDirectoryEntry :
public Entry {
729 std::vector<std::unique_ptr<Entry>> Contents;
733 RedirectingDirectoryEntry(StringRef Name,
734 std::vector<std::unique_ptr<Entry>> Contents,
736 : Entry(EK_Directory, Name), Contents(std::move(Contents)),
738 RedirectingDirectoryEntry(StringRef Name,
Status S)
739 : Entry(EK_Directory, Name), S(std::move(S)) {}
740 Status getStatus() {
return S; }
741 void addContent(std::unique_ptr<Entry> Content) {
742 Contents.push_back(std::move(Content));
744 Entry *getLastContent()
const {
return Contents.back().get(); }
745 typedef decltype(Contents)::iterator iterator;
746 iterator contents_begin() {
return Contents.begin(); }
747 iterator contents_end() {
return Contents.end(); }
748 static bool classof(
const Entry *E) {
return E->getKind() == EK_Directory; }
751 class RedirectingFileEntry :
public Entry {
759 std::string ExternalContentsPath;
762 RedirectingFileEntry(StringRef Name, StringRef ExternalContentsPath,
764 : Entry(EK_File, Name), ExternalContentsPath(ExternalContentsPath),
766 StringRef getExternalContentsPath()
const {
return ExternalContentsPath; }
768 bool useExternalName(
bool GlobalUseExternalName)
const {
769 return UseName == NK_NotSet ? GlobalUseExternalName
770 : (UseName == NK_External);
772 NameKind getUseName()
const {
return UseName; }
773 static bool classof(
const Entry *E) {
return E->getKind() == EK_File; }
776 class RedirectingFileSystem;
780 RedirectingFileSystem &FS;
781 RedirectingDirectoryEntry::iterator Current,
End;
784 VFSFromYamlDirIterImpl(
const Twine &Path, RedirectingFileSystem &FS,
785 RedirectingDirectoryEntry::iterator
Begin,
786 RedirectingDirectoryEntry::iterator End,
787 std::error_code &EC);
788 std::error_code increment()
override;
848 std::vector<std::unique_ptr<Entry>> Roots;
854 std::string ExternalContentsPrefixDir;
862 bool CaseSensitive =
true;
866 bool IsRelativeOverlay =
false;
870 bool UseExternalNames =
true;
878 bool IgnoreNonExistentContents =
true;
884 bool UseCanonicalizedPaths =
891 friend class RedirectingFileSystemParser;
895 : ExternalFS(std::move(ExternalFS)) {}
899 ErrorOr<Entry *> lookupPath(sys::path::const_iterator Start,
900 sys::path::const_iterator
End, Entry *From);
903 ErrorOr<Status>
status(
const Twine &Path, Entry *E);
907 ErrorOr<Entry *> lookupPath(
const Twine &Path);
911 static RedirectingFileSystem *
912 create(std::unique_ptr<MemoryBuffer> Buffer,
913 SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath,
916 ErrorOr<Status>
status(
const Twine &Path)
override;
917 ErrorOr<std::unique_ptr<File>>
openFileForRead(
const Twine &Path)
override;
920 return ExternalFS->getCurrentWorkingDirectory();
923 return ExternalFS->setCurrentWorkingDirectory(Path);
927 ErrorOr<Entry *> E = lookupPath(Dir);
932 ErrorOr<Status> S =
status(Dir, *E);
937 if (!S->isDirectory()) {
938 EC = std::error_code(static_cast<int>(errc::not_a_directory),
939 std::system_category());
943 auto *D = cast<RedirectingDirectoryEntry>(*E);
945 *
this, D->contents_begin(), D->contents_end(), EC));
948 void setExternalContentsPrefixDir(StringRef PrefixDir) {
949 ExternalContentsPrefixDir = PrefixDir.str();
952 StringRef getExternalContentsPrefixDir()
const {
953 return ExternalContentsPrefixDir;
956 bool ignoreNonExistentContents()
const {
957 return IgnoreNonExistentContents;
960 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 961 LLVM_DUMP_METHOD
void dump()
const {
962 for (
const std::unique_ptr<Entry> &Root : Roots)
963 dumpEntry(Root.get());
966 LLVM_DUMP_METHOD
void dumpEntry(Entry *E,
int NumSpaces = 0)
const {
967 StringRef Name = E->getName();
968 for (
int i = 0, e = NumSpaces; i < e; ++i)
970 dbgs() <<
"'" << Name.str().c_str() <<
"'" <<
"\n";
972 if (E->getKind() == EK_Directory) {
973 auto *DE = dyn_cast<RedirectingDirectoryEntry>(E);
974 assert(DE &&
"Should be a directory");
976 for (std::unique_ptr<Entry> &SubEntry :
977 llvm::make_range(DE->contents_begin(), DE->contents_end()))
978 dumpEntry(SubEntry.get(), NumSpaces+2);
986 class RedirectingFileSystemParser {
987 yaml::Stream &Stream;
990 Stream.printError(N, Msg);
994 bool parseScalarString(
yaml::Node *N, StringRef &Result,
996 yaml::ScalarNode *S = dyn_cast<yaml::ScalarNode>(N);
998 error(N,
"expected string");
1001 Result = S->getValue(Storage);
1006 bool parseScalarBool(
yaml::Node *N,
bool &Result) {
1009 if (!parseScalarString(N, Value, Storage))
1012 if (Value.equals_lower(
"true") || Value.equals_lower(
"on") ||
1013 Value.equals_lower(
"yes") || Value ==
"1") {
1016 }
else if (Value.equals_lower(
"false") || Value.equals_lower(
"off") ||
1017 Value.equals_lower(
"no") || Value ==
"0") {
1022 error(N,
"expected boolean value");
1027 KeyStatus(
bool Required=
false) : Required(Required), Seen(
false) {}
1031 typedef std::pair<StringRef, KeyStatus> KeyStatusPair;
1034 bool checkDuplicateOrUnknownKey(
yaml::Node *KeyNode, StringRef Key,
1035 DenseMap<StringRef, KeyStatus> &Keys) {
1036 if (!Keys.count(Key)) {
1037 error(KeyNode,
"unknown key");
1040 KeyStatus &S = Keys[Key];
1042 error(KeyNode, Twine(
"duplicate key '") + Key +
"'");
1050 bool checkMissingKeys(
yaml::Node *Obj, DenseMap<StringRef, KeyStatus> &Keys) {
1051 for (DenseMap<StringRef, KeyStatus>::iterator I = Keys.begin(),
1054 if (I->second.Required && !I->second.Seen) {
1055 error(Obj, Twine(
"missing key '") + I->first +
"'");
1062 Entry *lookupOrCreateEntry(RedirectingFileSystem *FS, StringRef Name,
1063 Entry *ParentEntry =
nullptr) {
1065 for (
const std::unique_ptr<Entry> &Root : FS->Roots) {
1066 if (Name.equals(Root->getName())) {
1067 ParentEntry = Root.get();
1072 auto *DE = dyn_cast<RedirectingDirectoryEntry>(ParentEntry);
1073 for (std::unique_ptr<Entry> &Content :
1074 llvm::make_range(DE->contents_begin(), DE->contents_end())) {
1075 auto *DirContent = dyn_cast<RedirectingDirectoryEntry>(Content.get());
1076 if (DirContent && Name.equals(Content->getName()))
1082 std::unique_ptr<Entry> E = llvm::make_unique<RedirectingDirectoryEntry>(
1085 0, 0, 0, file_type::directory_file, sys::fs::all_all));
1088 FS->Roots.push_back(std::move(E));
1089 ParentEntry = FS->Roots.back().get();
1093 auto *DE = dyn_cast<RedirectingDirectoryEntry>(ParentEntry);
1094 DE->addContent(std::move(E));
1095 return DE->getLastContent();
1098 void uniqueOverlayTree(RedirectingFileSystem *FS, Entry *SrcE,
1099 Entry *NewParentE =
nullptr) {
1100 StringRef Name = SrcE->getName();
1101 switch (SrcE->getKind()) {
1102 case EK_Directory: {
1103 auto *DE = dyn_cast<RedirectingDirectoryEntry>(SrcE);
1104 assert(DE &&
"Must be a directory");
1109 NewParentE = lookupOrCreateEntry(FS, Name, NewParentE);
1110 for (std::unique_ptr<Entry> &SubEntry :
1111 llvm::make_range(DE->contents_begin(), DE->contents_end()))
1112 uniqueOverlayTree(FS, SubEntry.get(), NewParentE);
1116 auto *FE = dyn_cast<RedirectingFileEntry>(SrcE);
1117 assert(FE &&
"Must be a file");
1118 assert(NewParentE &&
"Parent entry must exist");
1119 auto *DE = dyn_cast<RedirectingDirectoryEntry>(NewParentE);
1120 DE->addContent(llvm::make_unique<RedirectingFileEntry>(
1121 Name, FE->getExternalContentsPath(), FE->getUseName()));
1127 std::unique_ptr<Entry> parseEntry(
yaml::Node *N, RedirectingFileSystem *FS) {
1128 yaml::MappingNode *M = dyn_cast<yaml::MappingNode>(N);
1130 error(N,
"expected mapping node for file or directory entry");
1134 KeyStatusPair Fields[] = {
1135 KeyStatusPair(
"name",
true),
1136 KeyStatusPair(
"type",
true),
1137 KeyStatusPair(
"contents",
false),
1138 KeyStatusPair(
"external-contents",
false),
1139 KeyStatusPair(
"use-external-name",
false),
1142 DenseMap<StringRef, KeyStatus> Keys(std::begin(Fields), std::end(Fields));
1144 bool HasContents =
false;
1145 std::vector<std::unique_ptr<Entry>> EntryArrayContents;
1146 std::string ExternalContentsPath;
1148 auto UseExternalName = RedirectingFileEntry::NK_NotSet;
1151 for (yaml::MappingNode::iterator I = M->begin(), E = M->end(); I != E;
1157 if (!parseScalarString(I->getKey(), Key, Buffer))
1160 if (!checkDuplicateOrUnknownKey(I->getKey(), Key, Keys))
1164 if (Key ==
"name") {
1165 if (!parseScalarString(I->getValue(),
Value, Buffer))
1168 if (FS->UseCanonicalizedPaths) {
1172 Path = sys::path::remove_leading_dotslash(Path);
1173 sys::path::remove_dots(Path,
true);
1178 }
else if (Key ==
"type") {
1179 if (!parseScalarString(I->getValue(),
Value, Buffer))
1181 if (Value ==
"file")
1183 else if (Value ==
"directory")
1184 Kind = EK_Directory;
1186 error(I->getValue(),
"unknown value for 'type'");
1189 }
else if (Key ==
"contents") {
1192 "entry already has 'contents' or 'external-contents'");
1196 yaml::SequenceNode *Contents =
1197 dyn_cast<yaml::SequenceNode>(I->getValue());
1200 error(I->getValue(),
"expected array");
1204 for (yaml::SequenceNode::iterator I = Contents->begin(),
1205 E = Contents->end();
1207 if (std::unique_ptr<Entry> E = parseEntry(&*I, FS))
1208 EntryArrayContents.push_back(std::move(E));
1212 }
else if (Key ==
"external-contents") {
1215 "entry already has 'contents' or 'external-contents'");
1219 if (!parseScalarString(I->getValue(),
Value, Buffer))
1223 if (FS->IsRelativeOverlay) {
1224 FullPath = FS->getExternalContentsPrefixDir();
1225 assert(!FullPath.empty() &&
1226 "External contents prefix directory must exist");
1227 llvm::sys::path::append(FullPath, Value);
1232 if (FS->UseCanonicalizedPaths) {
1235 FullPath = sys::path::remove_leading_dotslash(FullPath);
1236 sys::path::remove_dots(FullPath,
true);
1238 ExternalContentsPath = FullPath.str();
1239 }
else if (Key ==
"use-external-name") {
1241 if (!parseScalarBool(I->getValue(), Val))
1243 UseExternalName = Val ? RedirectingFileEntry::NK_External
1244 : RedirectingFileEntry::NK_Virtual;
1246 llvm_unreachable(
"key missing from Keys");
1250 if (Stream.failed())
1255 error(N,
"missing key 'contents' or 'external-contents'");
1258 if (!checkMissingKeys(N, Keys))
1262 if (Kind == EK_Directory &&
1263 UseExternalName != RedirectingFileEntry::NK_NotSet) {
1264 error(N,
"'use-external-name' is not supported for directories");
1269 StringRef Trimmed(Name);
1270 size_t RootPathLen = sys::path::root_path(Trimmed).size();
1271 while (Trimmed.size() > RootPathLen &&
1272 sys::path::is_separator(Trimmed.back()))
1273 Trimmed = Trimmed.slice(0, Trimmed.size()-1);
1275 StringRef LastComponent = sys::path::filename(Trimmed);
1277 std::unique_ptr<Entry> Result;
1280 Result = llvm::make_unique<RedirectingFileEntry>(
1281 LastComponent, std::move(ExternalContentsPath), UseExternalName);
1284 Result = llvm::make_unique<RedirectingDirectoryEntry>(
1285 LastComponent, std::move(EntryArrayContents),
1287 0, 0, 0, file_type::directory_file, sys::fs::all_all));
1291 StringRef
Parent = sys::path::parent_path(Trimmed);
1296 for (sys::path::reverse_iterator I = sys::path::rbegin(Parent),
1297 E = sys::path::rend(Parent);
1299 std::vector<std::unique_ptr<Entry>> Entries;
1300 Entries.push_back(std::move(Result));
1301 Result = llvm::make_unique<RedirectingDirectoryEntry>(
1302 *I, std::move(Entries),
1304 0, 0, 0, file_type::directory_file, sys::fs::all_all));
1310 RedirectingFileSystemParser(yaml::Stream &S) : Stream(S) {}
1313 bool parse(
yaml::Node *Root, RedirectingFileSystem *FS) {
1314 yaml::MappingNode *Top = dyn_cast<yaml::MappingNode>(Root);
1316 error(Root,
"expected mapping node");
1320 KeyStatusPair Fields[] = {
1321 KeyStatusPair(
"version",
true),
1322 KeyStatusPair(
"case-sensitive",
false),
1323 KeyStatusPair(
"use-external-names",
false),
1324 KeyStatusPair(
"overlay-relative",
false),
1325 KeyStatusPair(
"ignore-non-existent-contents",
false),
1326 KeyStatusPair(
"roots",
true),
1329 DenseMap<StringRef, KeyStatus> Keys(std::begin(Fields), std::end(Fields));
1330 std::vector<std::unique_ptr<Entry>> RootEntries;
1333 for (yaml::MappingNode::iterator I = Top->begin(), E = Top->end(); I != E;
1337 if (!parseScalarString(I->getKey(), Key, KeyBuffer))
1340 if (!checkDuplicateOrUnknownKey(I->getKey(), Key, Keys))
1343 if (Key ==
"roots") {
1344 yaml::SequenceNode *Roots = dyn_cast<yaml::SequenceNode>(I->getValue());
1346 error(I->getValue(),
"expected array");
1350 for (yaml::SequenceNode::iterator I = Roots->begin(), E = Roots->end();
1352 if (std::unique_ptr<Entry> E = parseEntry(&*I, FS))
1353 RootEntries.push_back(std::move(E));
1357 }
else if (Key ==
"version") {
1358 StringRef VersionString;
1360 if (!parseScalarString(I->getValue(), VersionString, Storage))
1363 if (VersionString.getAsInteger<
int>(10, Version)) {
1364 error(I->getValue(),
"expected integer");
1368 error(I->getValue(),
"invalid version number");
1372 error(I->getValue(),
"version mismatch, expected 0");
1375 }
else if (Key ==
"case-sensitive") {
1376 if (!parseScalarBool(I->getValue(), FS->CaseSensitive))
1378 }
else if (Key ==
"overlay-relative") {
1379 if (!parseScalarBool(I->getValue(), FS->IsRelativeOverlay))
1381 }
else if (Key ==
"use-external-names") {
1382 if (!parseScalarBool(I->getValue(), FS->UseExternalNames))
1384 }
else if (Key ==
"ignore-non-existent-contents") {
1385 if (!parseScalarBool(I->getValue(), FS->IgnoreNonExistentContents))
1388 llvm_unreachable(
"key missing from Keys");
1392 if (Stream.failed())
1395 if (!checkMissingKeys(Top, Keys))
1401 for (std::unique_ptr<Entry> &E : RootEntries)
1402 uniqueOverlayTree(FS, E.get());
1409 Entry::~Entry() =
default;
1411 RedirectingFileSystem *
1413 SourceMgr::DiagHandlerTy DiagHandler,
1414 StringRef YAMLFilePath,
void *DiagContext,
1418 yaml::Stream Stream(Buffer->getMemBufferRef(),
SM);
1420 SM.setDiagHandler(DiagHandler, DiagContext);
1421 yaml::document_iterator DI = Stream.begin();
1423 if (DI == Stream.end() || !Root) {
1424 SM.PrintMessage(SMLoc(), SourceMgr::DK_Error,
"expected root node");
1428 RedirectingFileSystemParser
P(Stream);
1430 std::unique_ptr<RedirectingFileSystem> FS(
1431 new RedirectingFileSystem(std::move(ExternalFS)));
1433 if (!YAMLFilePath.empty()) {
1443 std::error_code EC = llvm::sys::fs::make_absolute(OverlayAbsDir);
1444 assert(!EC &&
"Overlay dir final path must be absolute");
1446 FS->setExternalContentsPrefixDir(OverlayAbsDir);
1449 if (!P.parse(Root, FS.get()))
1452 return FS.release();
1455 ErrorOr<Entry *> RedirectingFileSystem::lookupPath(
const Twine &Path_) {
1457 Path_.toVector(Path);
1466 if (UseCanonicalizedPaths) {
1467 Path = sys::path::remove_leading_dotslash(Path);
1468 sys::path::remove_dots(Path,
true);
1474 sys::path::const_iterator Start = sys::path::begin(Path);
1475 sys::path::const_iterator
End = sys::path::end(Path);
1476 for (
const std::unique_ptr<Entry> &Root : Roots) {
1477 ErrorOr<Entry *> Result = lookupPath(Start, End, Root.get());
1478 if (Result || Result.getError() != llvm::errc::no_such_file_or_directory)
1485 RedirectingFileSystem::lookupPath(sys::path::const_iterator Start,
1486 sys::path::const_iterator
End, Entry *From) {
1487 #ifndef LLVM_ON_WIN32 1490 "Paths should not contain traversal components");
1494 if (Start->equals(
"."))
1498 StringRef FromName = From->getName();
1501 if (!FromName.empty()) {
1502 if (CaseSensitive ? !Start->equals(FromName)
1503 : !Start->equals_lower(FromName))
1515 auto *DE = dyn_cast<RedirectingDirectoryEntry>(From);
1519 for (
const std::unique_ptr<Entry> &DirEntry :
1520 llvm::make_range(DE->contents_begin(), DE->contents_end())) {
1521 ErrorOr<Entry *> Result = lookupPath(Start, End, DirEntry.get());
1522 if (Result || Result.getError() != llvm::errc::no_such_file_or_directory)
1530 Status S = ExternalStatus;
1531 if (!UseExternalNames)
1537 ErrorOr<Status> RedirectingFileSystem::status(
const Twine &Path, Entry *E) {
1538 assert(E !=
nullptr);
1539 if (
auto *F = dyn_cast<RedirectingFileEntry>(E)) {
1540 ErrorOr<Status> S = ExternalFS->status(F->getExternalContentsPath());
1541 assert(!S || S->getName() == F->getExternalContentsPath());
1547 auto *DE = cast<RedirectingDirectoryEntry>(E);
1552 ErrorOr<Status> RedirectingFileSystem::status(
const Twine &Path) {
1553 ErrorOr<Entry *> Result = lookupPath(Path);
1555 return Result.getError();
1556 return status(Path, *Result);
1561 class FileWithFixedStatus :
public File {
1562 std::unique_ptr<File> InnerFile;
1566 FileWithFixedStatus(std::unique_ptr<File> InnerFile,
Status S)
1567 : InnerFile(std::move(InnerFile)), S(std::move(S)) {}
1569 ErrorOr<Status>
status()
override {
return S; }
1570 ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
1571 getBuffer(
const Twine &Name, int64_t FileSize,
bool RequiresNullTerminator,
1572 bool IsVolatile)
override {
1573 return InnerFile->getBuffer(Name, FileSize, RequiresNullTerminator,
1576 std::error_code close()
override {
return InnerFile->close(); }
1580 ErrorOr<std::unique_ptr<File>>
1581 RedirectingFileSystem::openFileForRead(
const Twine &Path) {
1582 ErrorOr<Entry *> E = lookupPath(Path);
1584 return E.getError();
1586 auto *F = dyn_cast<RedirectingFileEntry>(*E);
1590 auto Result = ExternalFS->openFileForRead(F->getExternalContentsPath());
1594 auto ExternalStatus = (*Result)->status();
1595 if (!ExternalStatus)
1596 return ExternalStatus.getError();
1601 return std::unique_ptr<File>(
1602 llvm::make_unique<FileWithFixedStatus>(std::move(*Result), S));
1607 SourceMgr::DiagHandlerTy DiagHandler,
1608 StringRef YAMLFilePath,
1612 YAMLFilePath, DiagContext,
1613 std::move(ExternalFS));
1618 auto Kind = SrcE->getKind();
1619 if (
Kind == EK_Directory) {
1620 auto *DE = dyn_cast<RedirectingDirectoryEntry>(SrcE);
1621 assert(DE &&
"Must be a directory");
1622 for (std::unique_ptr<Entry> &SubEntry :
1623 llvm::make_range(DE->contents_begin(), DE->contents_end())) {
1624 Path.push_back(SubEntry->getName());
1631 assert(
Kind == EK_File &&
"Must be a EK_File");
1632 auto *FE = dyn_cast<RedirectingFileEntry>(SrcE);
1633 assert(FE &&
"Must be a file");
1635 for (
auto &Comp : Path)
1636 llvm::sys::path::append(VPath, Comp);
1637 Entries.push_back(
YAMLVFSEntry(VPath.c_str(), FE->getExternalContentsPath()));
1641 SourceMgr::DiagHandlerTy DiagHandler,
1642 StringRef YAMLFilePath,
1647 std::move(Buffer), DiagHandler, YAMLFilePath, DiagContext,
1648 std::move(ExternalFS));
1649 ErrorOr<Entry *> RootE = VFS->lookupPath(
"/");
1653 Components.push_back(
"/");
1658 static std::atomic<unsigned> UID;
1659 unsigned ID = ++UID;
1666 assert(sys::path::is_absolute(VirtualPath) &&
"virtual path not absolute");
1667 assert(sys::path::is_absolute(RealPath) &&
"real path not absolute");
1668 assert(!
pathHasTraversal(VirtualPath) &&
"path traversal is not supported");
1669 Mappings.emplace_back(VirtualPath, RealPath);
1674 llvm::raw_ostream &OS;
1676 inline unsigned getDirIndent() {
return 4 * DirStack.size(); }
1677 inline unsigned getFileIndent() {
return 4 * (DirStack.size() + 1); }
1678 bool containedIn(StringRef
Parent, StringRef Path);
1679 StringRef containedPart(StringRef Parent, StringRef Path);
1680 void startDirectory(StringRef Path);
1681 void endDirectory();
1682 void writeEntry(StringRef VPath, StringRef RPath);
1685 JSONWriter(llvm::raw_ostream &OS) : OS(OS) {}
1692 bool JSONWriter::containedIn(StringRef
Parent, StringRef Path) {
1695 auto IParent = path::begin(Parent), EParent = path::end(Parent);
1696 for (
auto IChild = path::begin(Path), EChild = path::end(Path);
1697 IParent != EParent && IChild != EChild; ++IParent, ++IChild) {
1698 if (*IParent != *IChild)
1702 return IParent == EParent;
1705 StringRef JSONWriter::containedPart(StringRef Parent, StringRef Path) {
1706 assert(!Parent.empty());
1707 assert(containedIn(Parent, Path));
1708 return Path.slice(Parent.size() + 1, StringRef::npos);
1711 void JSONWriter::startDirectory(StringRef Path) {
1713 DirStack.empty() ? Path : containedPart(DirStack.back(), Path);
1714 DirStack.push_back(Path);
1715 unsigned Indent = getDirIndent();
1716 OS.indent(Indent) <<
"{\n";
1717 OS.indent(Indent + 2) <<
"'type': 'directory',\n";
1718 OS.indent(Indent + 2) <<
"'name': \"" << llvm::yaml::escape(Name) <<
"\",\n";
1719 OS.indent(Indent + 2) <<
"'contents': [\n";
1722 void JSONWriter::endDirectory() {
1723 unsigned Indent = getDirIndent();
1724 OS.indent(Indent + 2) <<
"]\n";
1725 OS.indent(Indent) <<
"}";
1727 DirStack.pop_back();
1730 void JSONWriter::writeEntry(StringRef VPath, StringRef RPath) {
1731 unsigned Indent = getFileIndent();
1732 OS.indent(Indent) <<
"{\n";
1733 OS.indent(Indent + 2) <<
"'type': 'file',\n";
1734 OS.indent(Indent + 2) <<
"'name': \"" << llvm::yaml::escape(VPath) <<
"\",\n";
1735 OS.indent(Indent + 2) <<
"'external-contents': \"" 1736 << llvm::yaml::escape(RPath) <<
"\"\n";
1737 OS.indent(Indent) <<
"}";
1745 StringRef OverlayDir) {
1750 if (IsCaseSensitive.hasValue())
1751 OS <<
" 'case-sensitive': '" 1752 << (IsCaseSensitive.getValue() ?
"true" :
"false") <<
"',\n";
1753 if (UseExternalNames.hasValue())
1754 OS <<
" 'use-external-names': '" 1755 << (UseExternalNames.getValue() ?
"true" :
"false") <<
"',\n";
1756 bool UseOverlayRelative =
false;
1757 if (IsOverlayRelative.hasValue()) {
1758 UseOverlayRelative = IsOverlayRelative.getValue();
1759 OS <<
" 'overlay-relative': '" 1760 << (UseOverlayRelative ?
"true" :
"false") <<
"',\n";
1762 if (IgnoreNonExistentContents.hasValue())
1763 OS <<
" 'ignore-non-existent-contents': '" 1764 << (IgnoreNonExistentContents.getValue() ?
"true" :
"false") <<
"',\n";
1765 OS <<
" 'roots': [\n";
1767 if (!Entries.empty()) {
1769 startDirectory(path::parent_path(Entry.
VPath));
1771 StringRef RPath = Entry.
RPath;
1772 if (UseOverlayRelative) {
1773 unsigned OverlayDirLen = OverlayDir.size();
1774 assert(RPath.substr(0, OverlayDirLen) == OverlayDir &&
1775 "Overlay dir must be contained in RPath");
1776 RPath = RPath.slice(OverlayDirLen, RPath.size());
1779 writeEntry(path::filename(Entry.
VPath), RPath);
1781 for (
const auto &Entry : Entries.slice(1)) {
1782 StringRef Dir = path::parent_path(Entry.
VPath);
1783 if (Dir == DirStack.back())
1786 while (!DirStack.empty() && !containedIn(DirStack.back(), Dir)) {
1791 startDirectory(Dir);
1793 StringRef RPath = Entry.
RPath;
1794 if (UseOverlayRelative) {
1795 unsigned OverlayDirLen = OverlayDir.size();
1796 assert(RPath.substr(0, OverlayDirLen) == OverlayDir &&
1797 "Overlay dir must be contained in RPath");
1798 RPath = RPath.slice(OverlayDirLen, RPath.size());
1800 writeEntry(path::filename(Entry.
VPath), RPath);
1803 while (!DirStack.empty()) {
1815 std::sort(Mappings.begin(), Mappings.end(),
1817 return LHS.
VPath < RHS.VPath;
1820 JSONWriter(OS).write(Mappings, UseExternalNames, IsCaseSensitive,
1821 IsOverlayRelative, IgnoreNonExistentContents,
1825 VFSFromYamlDirIterImpl::VFSFromYamlDirIterImpl(
1826 const Twine &_Path, RedirectingFileSystem &FS,
1827 RedirectingDirectoryEntry::iterator
Begin,
1828 RedirectingDirectoryEntry::iterator End, std::error_code &EC)
1829 : Dir(_Path.str()), FS(FS), Current(Begin),
End(End) {
1830 while (Current != End) {
1832 llvm::sys::path::append(PathStr, (*Current)->getName());
1833 llvm::ErrorOr<vfs::Status> S = FS.status(PathStr);
1839 if (FS.ignoreNonExistentContents() &&
1840 S.getError() == llvm::errc::no_such_file_or_directory) {
1850 std::error_code VFSFromYamlDirIterImpl::increment() {
1851 assert(Current != End &&
"cannot iterate past end");
1852 while (++Current != End) {
1854 llvm::sys::path::append(PathStr, (*Current)->getName());
1855 llvm::ErrorOr<vfs::Status> S = FS.status(PathStr);
1858 if (FS.ignoreNonExistentContents() &&
1859 S.getError() == llvm::errc::no_such_file_or_directory) {
1862 return S.getError();
1871 return std::error_code();
1876 std::error_code &EC)
1880 State = std::make_shared<IterState>();
1887 assert(FS && State && !State->empty() &&
"incrementing past end");
1888 assert(State->top()->isStatusKnown() &&
"non-canonical end iterator");
1890 if (State->top()->isDirectory()) {
1898 while (!State->empty() && State->top().increment(EC) ==
End)
static Status getRedirectedFileStatus(const Twine &Path, bool UseExternalNames, Status ExternalStatus)
decltype(Entries) typedef ::const_iterator const_iterator
static bool classof(const InMemoryNode *N)
Defines the clang::FileManager interface and associated types.
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
IntrusiveRefCntPtr< FileSystem > getRealFileSystem()
Gets an vfs::FileSystem for the 'real' file system, as seen by the operating system.
llvm::sys::fs::perms getPermissions() const
The base class of the type hierarchy.
InMemoryNode * getChild(StringRef Name)
The virtual file system interface.
llvm::ErrorOr< std::string > getCurrentWorkingDirectory() const override
Get the working directory of this file system.
void write(llvm::raw_ostream &OS)
IntrusiveRefCntPtr< FileSystem > getVFSFromYAML(std::unique_ptr< llvm::MemoryBuffer > Buffer, llvm::SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath, void *DiagContext=nullptr, IntrusiveRefCntPtr< FileSystem > ExternalFS=getRealFileSystem())
Gets a FileSystem for a virtual file system described in YAML format.
bool isStatusKnown() const
An input iterator over the recursive contents of a virtual path, similar to llvm::sys::fs::recursive_...
const_iterator end() const
An in-memory file system.
bool useNormalizedPaths() const
Return true if this file system normalizes . and .. in paths.
directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override
Get a directory_iterator for Dir.
A file system that allows overlaying one AbstractFileSystem on top of another.
std::error_code make_error_code(BuildPreambleError Error)
directory_iterator & increment(std::error_code &EC)
Equivalent to operator++, with an error code.
InMemoryDirectory(Status Stat)
static void getVFSEntries(Entry *SrcE, SmallVectorImpl< StringRef > &Path, SmallVectorImpl< YAMLVFSEntry > &Entries)
void addFileMapping(StringRef VirtualPath, StringRef RealPath)
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
InMemoryNode(Status Stat, InMemoryNodeKind Kind)
FileSystemList::reverse_iterator iterator
llvm::ErrorOr< std::unique_ptr< File > > openFileForRead(const Twine &Path) override
Get a File object for the file at Path, if one exists.
The result of a status operation.
const_iterator begin() const
The in memory file system is a tree of Nodes.
static Status copyWithNewName(const Status &In, StringRef NewName)
Get a copy of a Status with a different name.
iterator overlays_end()
Get an iterator pointing one-past the least recently added file system.
static bool pathHasTraversal(StringRef Path)
static bool isTraversalComponent(StringRef Component)
std::string toString() const
The result type of a method or function.
~InMemoryFileSystem() override
const Status & getStatus() const
llvm::sys::fs::file_type getType() const
recursive_directory_iterator & increment(std::error_code &EC)
Equivalent to operator++, with an error code.
void collectVFSFromYAML(std::unique_ptr< llvm::MemoryBuffer > Buffer, llvm::SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath, SmallVectorImpl< YAMLVFSEntry > &CollectedEntries, void *DiagContext=nullptr, IntrusiveRefCntPtr< FileSystem > ExternalFS=getRealFileSystem())
Collect all pairs of <virtual path, real path> entries from the YAMLFilePath.
iterator overlays_begin()
Get an iterator pointing to the most recently added file system.
llvm::sys::TimePoint getLastModificationTime() const
std::error_code makeAbsolute(SmallVectorImpl< char > &Path) const
Make Path an absolute path.
recursive_directory_iterator()=default
Construct an 'end' iterator.
InMemoryNode * addChild(StringRef Name, std::unique_ptr< InMemoryNode > Child)
ast_type_traits::DynTypedNode Node
Dataflow Directional Tag Classes.
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
Defines the virtual file system interface vfs::FileSystem.
llvm::sys::fs::UniqueID getNextVirtualUniqueID()
Get a globally unique ID for a virtual file or directory.
static ErrorOr< detail::InMemoryNode * > lookupInMemoryNode(const InMemoryFileSystem &FS, detail::InMemoryDirectory *Dir, const Twine &P)
std::string toString(const til::SExpr *E)
static bool classof(const OMPClause *T)
llvm::sys::fs::UniqueID getUniqueID() const
std::string toString(unsigned Indent) const override
char __ovld __cnfn max(char x, char y)
Returns y if x < y, otherwise it returns x.
An input iterator over the entries in a virtual path, similar to llvm::sys::fs::directory_iterator.
llvm::ErrorOr< Status > status(const Twine &Path) override
Get the status of the entry at Path, if one exists.
std::error_code setCurrentWorkingDirectory(const Twine &Path) override
Set the working directory.
static Decl::Kind getKind(const Decl *D)
An interface for virtual file systems to provide an iterator over the (non-recursive) contents of a d...
bool addFileNoOwn(const Twine &Path, time_t ModificationTime, llvm::MemoryBuffer *Buffer, Optional< uint32_t > User=None, Optional< uint32_t > Group=None, Optional< llvm::sys::fs::file_type > Type=None, Optional< llvm::sys::fs::perms > Perms=None)
Add a buffer to the VFS with a path.
uint32_t getGroup() const
InMemoryNodeKind getKind() const
bool addFile(const Twine &Path, time_t ModificationTime, std::unique_ptr< llvm::MemoryBuffer > Buffer, Optional< uint32_t > User=None, Optional< uint32_t > Group=None, Optional< llvm::sys::fs::file_type > Type=None, Optional< llvm::sys::fs::perms > Perms=None)
Add a file containing a buffer or a directory to the VFS with a path.