Skip to content

Commit

Permalink
[YAMLVFSWriter] Fix for delimiters
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D79809
  • Loading branch information
jkorous-apple committed May 12, 2020
1 parent f490ca7 commit 759465e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
27 changes: 18 additions & 9 deletions llvm/lib/Support/VirtualFileSystem.cpp
Expand Up @@ -2027,10 +2027,10 @@ void JSONWriter::write(ArrayRef<YAMLVFSEntry> Entries,

if (!Entries.empty()) {
const YAMLVFSEntry &Entry = Entries.front();
bool first_entry_is_directory = Entry.IsDirectory;
StringRef Dir =
first_entry_is_directory ? Entry.VPath : path::parent_path(Entry.VPath);
startDirectory(Dir);

startDirectory(
Entry.IsDirectory ? Entry.VPath : path::parent_path(Entry.VPath)
);

StringRef RPath = Entry.RPath;
if (UseOverlayRelative) {
Expand All @@ -2040,24 +2040,31 @@ void JSONWriter::write(ArrayRef<YAMLVFSEntry> Entries,
RPath = RPath.slice(OverlayDirLen, RPath.size());
}

if (!first_entry_is_directory)
bool IsCurrentDirEmpty = true;
if (!Entry.IsDirectory) {
writeEntry(path::filename(Entry.VPath), RPath);
IsCurrentDirEmpty = false;
}

for (const auto &Entry : Entries.slice(1)) {
StringRef Dir =
Entry.IsDirectory ? Entry.VPath : path::parent_path(Entry.VPath);
if (Dir == DirStack.back()) {
if (!first_entry_is_directory) {
if (!IsCurrentDirEmpty) {
OS << ",\n";
first_entry_is_directory = false;
}
} else {
bool IsDirPoppedFromStack = false;
while (!DirStack.empty() && !containedIn(DirStack.back(), Dir)) {
OS << "\n";
endDirectory();
IsDirPoppedFromStack = true;
}
if (IsDirPoppedFromStack || !IsCurrentDirEmpty) {
OS << ",\n";
}
OS << ",\n";
startDirectory(Dir);
IsCurrentDirEmpty = true;
}
StringRef RPath = Entry.RPath;
if (UseOverlayRelative) {
Expand All @@ -2066,8 +2073,10 @@ void JSONWriter::write(ArrayRef<YAMLVFSEntry> Entries,
"Overlay dir must be contained in RPath");
RPath = RPath.slice(OverlayDirLen, RPath.size());
}
if (!Entry.IsDirectory)
if (!Entry.IsDirectory) {
writeEntry(path::filename(Entry.VPath), RPath);
IsCurrentDirEmpty = false;
}
}

while (!DirStack.empty()) {
Expand Down
6 changes: 2 additions & 4 deletions llvm/unittests/Support/VirtualFileSystemTest.cpp
Expand Up @@ -2267,8 +2267,7 @@ TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest2) {

IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem());
IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLRawString(Buffer, Lower);
// FIXME: Missing comma separator between file entries.
EXPECT_FALSE(FS.get() != nullptr);
EXPECT_TRUE(FS.get() != nullptr);
}

TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest3) {
Expand Down Expand Up @@ -2301,8 +2300,7 @@ TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest3) {

IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem());
IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLRawString(Buffer, Lower);
// FIXME: Spurious comma separator before first file entry in directory.
EXPECT_FALSE(FS.get() != nullptr);
EXPECT_TRUE(FS.get() != nullptr);
}

TEST_F(VFSFromYAMLTest, YAMLVFSWriterTestHandleDirs) {
Expand Down

0 comments on commit 759465e

Please sign in to comment.