Add a driver option -ivfsoverlay
Reads the description of a virtual filesystem from a file and overlays
it over the real file system.
llvm-svn: 202176
diff --git a/clang/test/VFS/Inputs/actual_header.h b/clang/test/VFS/Inputs/actual_header.h
new file mode 100644
index 0000000..f61e586
--- /dev/null
+++ b/clang/test/VFS/Inputs/actual_header.h
@@ -0,0 +1 @@
+void bar(void);
diff --git a/clang/test/VFS/Inputs/actual_module.map b/clang/test/VFS/Inputs/actual_module.map
new file mode 100644
index 0000000..282dac3
--- /dev/null
+++ b/clang/test/VFS/Inputs/actual_module.map
@@ -0,0 +1,4 @@
+module not_real {
+  header "not_real.h"
+  export *
+}
diff --git a/clang/test/VFS/Inputs/include_real.h b/clang/test/VFS/Inputs/include_real.h
new file mode 100644
index 0000000..0750c65
--- /dev/null
+++ b/clang/test/VFS/Inputs/include_real.h
@@ -0,0 +1 @@
+#include "real.h"
diff --git a/clang/test/VFS/Inputs/invalid-yaml.yaml b/clang/test/VFS/Inputs/invalid-yaml.yaml
new file mode 100644
index 0000000..2a6c666
--- /dev/null
+++ b/clang/test/VFS/Inputs/invalid-yaml.yaml
@@ -0,0 +1,4 @@
+{
+  'version': 0,
+  'roots': []
+]
diff --git a/clang/test/VFS/Inputs/missing-key.yaml b/clang/test/VFS/Inputs/missing-key.yaml
new file mode 100644
index 0000000..5d18c24
--- /dev/null
+++ b/clang/test/VFS/Inputs/missing-key.yaml
@@ -0,0 +1,4 @@
+{
+  'version': 0,
+  'roots': [ { 'name' : 'foo', 'external-contents': 'bar' } ]
+}
diff --git a/clang/test/VFS/Inputs/public_header.h b/clang/test/VFS/Inputs/public_header.h
new file mode 100644
index 0000000..4711077
--- /dev/null
+++ b/clang/test/VFS/Inputs/public_header.h
@@ -0,0 +1 @@
+void from_framework(void);
diff --git a/clang/test/VFS/Inputs/unknown-key.yaml b/clang/test/VFS/Inputs/unknown-key.yaml
new file mode 100644
index 0000000..ec7d826
--- /dev/null
+++ b/clang/test/VFS/Inputs/unknown-key.yaml
@@ -0,0 +1,5 @@
+{
+  'version': 0,
+  'unknown-key': 'value',
+  'roots': []
+}
diff --git a/clang/test/VFS/Inputs/unknown-value.yaml b/clang/test/VFS/Inputs/unknown-value.yaml
new file mode 100644
index 0000000..4e90b21
--- /dev/null
+++ b/clang/test/VFS/Inputs/unknown-value.yaml
@@ -0,0 +1,5 @@
+{
+  'version': 0,
+  'case-sensitive': 'Maybe?',
+  'roots': []
+}
diff --git a/clang/test/VFS/Inputs/vfsoverlay.yaml b/clang/test/VFS/Inputs/vfsoverlay.yaml
new file mode 100644
index 0000000..331ed33
--- /dev/null
+++ b/clang/test/VFS/Inputs/vfsoverlay.yaml
@@ -0,0 +1,21 @@
+{
+  'version': 0,
+  'roots': [
+    { 'name': 'OUT_DIR', 'type': 'directory',
+      'contents': [
+        { 'name': 'not_real.h', 'type': 'file',
+          'external-contents': 'INPUT_DIR/actual_header.h'
+        },
+        { 'name': 'module.map', 'type': 'file',
+          'external-contents': 'INPUT_DIR/actual_module.map'
+        },
+        { 'name': 'include_real.h', 'type': 'file',
+          'external-contents': 'INPUT_DIR/include_real.h'
+        },
+        { 'name': 'SomeFramework.framework/Headers/public_header.h', 'type': 'file',
+          'external-contents': 'INPUT_DIR/public_header.h'
+        }
+      ]
+    }
+  ]
+}
diff --git a/clang/test/VFS/framework-import.m b/clang/test/VFS/framework-import.m
new file mode 100644
index 0000000..b40bc54
--- /dev/null
+++ b/clang/test/VFS/framework-import.m
@@ -0,0 +1,9 @@
+// RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: %clang_cc1 -Werror -F %t -ivfsoverlay %t.yaml -fsyntax-only %s
+// REQUIRES: shell
+
+#import <SomeFramework/public_header.h>
+
+void foo() {
+  from_framework();
+}
diff --git a/clang/test/VFS/implicit-include.c b/clang/test/VFS/implicit-include.c
new file mode 100644
index 0000000..acf665b
--- /dev/null
+++ b/clang/test/VFS/implicit-include.c
@@ -0,0 +1,7 @@
+// RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: %clang_cc1 -Werror -ivfsoverlay %t.yaml -I %t -include "not_real.h" -fsyntax-only %s
+// REQUIRES: shell
+
+void foo() {
+  bar();
+}
diff --git a/clang/test/VFS/include-mixed-real-and-virtual.c b/clang/test/VFS/include-mixed-real-and-virtual.c
new file mode 100644
index 0000000..e1f5f95
--- /dev/null
+++ b/clang/test/VFS/include-mixed-real-and-virtual.c
@@ -0,0 +1,14 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: echo "void baz(void);" > %t/real.h
+// RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: %clang_cc1 -Werror -ivfsoverlay %t.yaml -I %t -fsyntax-only %s
+// REQUIRES: shell
+
+#include "not_real.h"
+#include "real.h"
+
+void foo() {
+  bar();
+  baz();
+}
diff --git a/clang/test/VFS/include-real-from-virtual.c b/clang/test/VFS/include-real-from-virtual.c
new file mode 100644
index 0000000..65707b5
--- /dev/null
+++ b/clang/test/VFS/include-real-from-virtual.c
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: echo "void baz(void);" > %t/real.h
+// RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: %clang_cc1 -Werror -ivfsoverlay %t.yaml -I %t -fsyntax-only %s
+// REQUIRES: shell
+
+#include "include_real.h"
+
+void foo() {
+  baz();
+}
diff --git a/clang/test/VFS/include-virtual-from-real.c b/clang/test/VFS/include-virtual-from-real.c
new file mode 100644
index 0000000..c8f6059
--- /dev/null
+++ b/clang/test/VFS/include-virtual-from-real.c
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: echo '#include "not_real.h"' > %t/include_not_real.h
+// RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: %clang_cc1 -Werror -ivfsoverlay %t.yaml -I %t -fsyntax-only %s
+// REQUIRES: shell
+
+#include "include_not_real.h"
+
+void foo() {
+  bar();
+}
diff --git a/clang/test/VFS/include.c b/clang/test/VFS/include.c
new file mode 100644
index 0000000..8cd04dd
--- /dev/null
+++ b/clang/test/VFS/include.c
@@ -0,0 +1,9 @@
+// RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: %clang_cc1 -Werror -I %t -ivfsoverlay %t.yaml -fsyntax-only %s
+// REQUIRES: shell
+
+#include "not_real.h"
+
+void foo() {
+  bar();
+}
diff --git a/clang/test/VFS/module-import.m b/clang/test/VFS/module-import.m
new file mode 100644
index 0000000..80f0ea5
--- /dev/null
+++ b/clang/test/VFS/module-import.m
@@ -0,0 +1,9 @@
+// RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" %S/Inputs/vfsoverlay.yaml > %t.yaml
+// RUN: %clang_cc1 -Werror -fmodules -fmodules-cache-path=%t -ivfsoverlay %t.yaml -I %t -fsyntax-only %s
+// REQUIRES: shell
+
+@import not_real;
+
+void foo() {
+  bar();
+}
diff --git a/clang/test/VFS/parse-errors.c b/clang/test/VFS/parse-errors.c
new file mode 100644
index 0000000..7194efc
--- /dev/null
+++ b/clang/test/VFS/parse-errors.c
@@ -0,0 +1,14 @@
+// RUN: not %clang_cc1 -ivfsoverlay %S/Inputs/invalid-yaml.yaml -fsyntax-only %s 2>&1 | FileCheck %s
+// CHECK: invalid virtual filesystem overlay file
+
+// RUN: not %clang_cc1 -ivfsoverlay %S/Inputs/missing-key.yaml -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-MISSING-TYPE %s
+// CHECK-MISSING-TYPE: missing key 'type'
+// CHECK-MISSING-TYPE: invalid virtual filesystem overlay file
+
+// RUN: not %clang_cc1 -ivfsoverlay %S/Inputs/unknown-key.yaml -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-UNKNOWN-KEY %s
+// CHECK-UNKNOWN-KEY: unknown key
+// CHECK-UNKNOWN-KEY: invalid virtual filesystem overlay file
+
+// RUN: not %clang_cc1 -ivfsoverlay %S/Inputs/unknown-value.yaml -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-UNKNOWN-VALUE %s
+// CHECK-UNKNOWN-VALUE: expected boolean value
+// CHECK-UNKNOWN-VALUE: invalid virtual filesystem overlay file