rmaz created this revision.
Herald added subscribers: dexonsmith, hiraditya.
rmaz requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This diff adds support for relative roots to VFS overlays.
The directory root will be made absolute from the current
working directory and will be used to determine the path
style to use.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116174

Files:
  clang/test/VFS/Inputs/vfsoverlay-root-relative.yaml
  clang/test/VFS/vfsoverlay-relative-root.c
  llvm/lib/Support/VirtualFileSystem.cpp


Index: llvm/lib/Support/VirtualFileSystem.cpp
===================================================================
--- llvm/lib/Support/VirtualFileSystem.cpp
+++ llvm/lib/Support/VirtualFileSystem.cpp
@@ -1649,10 +1649,17 @@
                                         sys::path::Style::windows_backslash)) {
         path_style = sys::path::Style::windows_backslash;
       } else {
-        assert(NameValueNode && "Name presence should be checked earlier");
-        error(NameValueNode,
-              "entry with relative path at the root level is not 
discoverable");
-        return nullptr;
+        // Relative VFS root entries are made absolute to the current working
+        // directory, then we can determine the path style from that.
+        auto EC = sys::fs::make_absolute(Name);
+        if (EC) {
+          assert(NameValueNode && "Name presence should be checked earlier");
+          error(NameValueNode,
+                "entry with relative path at the root level is not 
discoverable");
+          return nullptr;
+        }
+        path_style = sys::path::is_absolute(Name, sys::path::Style::posix) ?
+          sys::path::Style::posix : sys::path::Style::windows_backslash;
       }
     }
 
Index: clang/test/VFS/vfsoverlay-relative-root.c
===================================================================
--- /dev/null
+++ clang/test/VFS/vfsoverlay-relative-root.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -Werror -ivfsoverlay 
%S/Inputs/vfsoverlay-root-relative.yaml -I virtual -fsyntax-only %s
+
+#include "virtual_header.h"
+
Index: clang/test/VFS/Inputs/vfsoverlay-root-relative.yaml
===================================================================
--- /dev/null
+++ clang/test/VFS/Inputs/vfsoverlay-root-relative.yaml
@@ -0,0 +1,17 @@
+{
+  'version': 0,
+  'fallthrough': true,
+  'overlay-relative': true,
+  'roots': [
+    { 'name': 'virtual',
+      'type': 'directory',
+      'contents': [
+        {
+          'external-contents': 'actual_header.h',
+          'type': 'file',
+          'name': 'virtual_header.h',
+        }
+      ]
+    }
+  ]
+}


Index: llvm/lib/Support/VirtualFileSystem.cpp
===================================================================
--- llvm/lib/Support/VirtualFileSystem.cpp
+++ llvm/lib/Support/VirtualFileSystem.cpp
@@ -1649,10 +1649,17 @@
                                         sys::path::Style::windows_backslash)) {
         path_style = sys::path::Style::windows_backslash;
       } else {
-        assert(NameValueNode && "Name presence should be checked earlier");
-        error(NameValueNode,
-              "entry with relative path at the root level is not discoverable");
-        return nullptr;
+        // Relative VFS root entries are made absolute to the current working
+        // directory, then we can determine the path style from that.
+        auto EC = sys::fs::make_absolute(Name);
+        if (EC) {
+          assert(NameValueNode && "Name presence should be checked earlier");
+          error(NameValueNode,
+                "entry with relative path at the root level is not discoverable");
+          return nullptr;
+        }
+        path_style = sys::path::is_absolute(Name, sys::path::Style::posix) ?
+          sys::path::Style::posix : sys::path::Style::windows_backslash;
       }
     }
 
Index: clang/test/VFS/vfsoverlay-relative-root.c
===================================================================
--- /dev/null
+++ clang/test/VFS/vfsoverlay-relative-root.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -Werror -ivfsoverlay %S/Inputs/vfsoverlay-root-relative.yaml -I virtual -fsyntax-only %s
+
+#include "virtual_header.h"
+
Index: clang/test/VFS/Inputs/vfsoverlay-root-relative.yaml
===================================================================
--- /dev/null
+++ clang/test/VFS/Inputs/vfsoverlay-root-relative.yaml
@@ -0,0 +1,17 @@
+{
+  'version': 0,
+  'fallthrough': true,
+  'overlay-relative': true,
+  'roots': [
+    { 'name': 'virtual',
+      'type': 'directory',
+      'contents': [
+        {
+          'external-contents': 'actual_header.h',
+          'type': 'file',
+          'name': 'virtual_header.h',
+        }
+      ]
+    }
+  ]
+}
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to