1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[YAMLVFSWriter] Fix for delimiters

Differential Revision: https://reviews.llvm.org/D79809
This commit is contained in:
Jan Korous 2020-05-12 14:42:22 -07:00
parent 9477aee8a4
commit 0033cbcfd8
2 changed files with 20 additions and 13 deletions

View File

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

View File

@ -2267,8 +2267,7 @@ TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest2) {
IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem()); IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem());
IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLRawString(Buffer, Lower); IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLRawString(Buffer, Lower);
// FIXME: Missing comma separator between file entries. EXPECT_TRUE(FS.get() != nullptr);
EXPECT_FALSE(FS.get() != nullptr);
} }
TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest3) { TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest3) {
@ -2301,8 +2300,7 @@ TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest3) {
IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem()); IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem());
IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLRawString(Buffer, Lower); IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLRawString(Buffer, Lower);
// FIXME: Spurious comma separator before first file entry in directory. EXPECT_TRUE(FS.get() != nullptr);
EXPECT_FALSE(FS.get() != nullptr);
} }
TEST_F(VFSFromYAMLTest, YAMLVFSWriterTestHandleDirs) { TEST_F(VFSFromYAMLTest, YAMLVFSWriterTestHandleDirs) {