]> granicus.if.org Git - clang/commitdiff
VirtualFileSystem: Correctly generate the mapping for an empty VFS
authorJustin Bogner <mail@justinbogner.com>
Tue, 15 Jul 2014 01:24:35 +0000 (01:24 +0000)
committerJustin Bogner <mail@justinbogner.com>
Tue, 15 Jul 2014 01:24:35 +0000 (01:24 +0000)
In r209332 I accidentally broke generation of empty VFS maps. This
fixes the issue and adds a test.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213028 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/VirtualFileSystem.cpp
unittests/libclang/LibclangTest.cpp

index 1f2a856b5c4e98215b136dc9fecdb85d93bc2c98..a5c83b88af50010fd6047fc4559d4c3073744afe 100644 (file)
@@ -1101,35 +1101,34 @@ void JSONWriter::write(ArrayRef<YAMLVFSEntry> Entries,
        << (IsCaseSensitive.getValue() ? "true" : "false") << "',\n";
   OS << "  'roots': [\n";
 
-  if (Entries.empty())
-    return;
-
-  const YAMLVFSEntry &Entry = Entries.front();
-  startDirectory(path::parent_path(Entry.VPath));
-  writeEntry(path::filename(Entry.VPath), Entry.RPath);
-
-  for (const auto &Entry : Entries.slice(1)) {
-    StringRef Dir = path::parent_path(Entry.VPath);
-    if (Dir == DirStack.back())
-      OS << ",\n";
-    else {
-      while (!DirStack.empty() && !containedIn(DirStack.back(), Dir)) {
-        OS << "\n";
-        endDirectory();
+  if (!Entries.empty()) {
+    const YAMLVFSEntry &Entry = Entries.front();
+    startDirectory(path::parent_path(Entry.VPath));
+    writeEntry(path::filename(Entry.VPath), Entry.RPath);
+
+    for (const auto &Entry : Entries.slice(1)) {
+      StringRef Dir = path::parent_path(Entry.VPath);
+      if (Dir == DirStack.back())
+        OS << ",\n";
+      else {
+        while (!DirStack.empty() && !containedIn(DirStack.back(), Dir)) {
+          OS << "\n";
+          endDirectory();
+        }
+        OS << ",\n";
+        startDirectory(Dir);
       }
-      OS << ",\n";
-      startDirectory(Dir);
+      writeEntry(path::filename(Entry.VPath), Entry.RPath);
     }
-    writeEntry(path::filename(Entry.VPath), Entry.RPath);
-  }
 
-  while (!DirStack.empty()) {
+    while (!DirStack.empty()) {
+      OS << "\n";
+      endDirectory();
+    }
     OS << "\n";
-    endDirectory();
   }
 
-  OS << "\n"
-     << "  ]\n"
+  OS << "  ]\n"
      << "}\n";
 }
 
index ef162bccc019b1c1aa7751150d540d8683918c4b..ee56e229367bb13bf98ba0d8af7762d8377728b3 100644 (file)
@@ -316,6 +316,16 @@ TEST(libclang, VirtualFileOverlay_TopLevel) {
   T.map("/foo.h", "/real/foo.h");
 }
 
+TEST(libclang, VirtualFileOverlay_Empty) {
+  const char *contents =
+      "{\n"
+      "  'version': 0,\n"
+      "  'roots': [\n"
+      "  ]\n"
+      "}\n";
+  TestVFO T(contents);
+}
+
 TEST(libclang, ModuleMapDescriptor) {
   const char *Contents =
     "framework module TestFrame {\n"