I wonder if '-ivfsoverlay' is the right name for this? I have two nits: 1. If we ever added non-overlay operations into the format, it would be a misnomer. 2. While the implementation of the option requires using the VFS, the name is loaded enough that I think it might be good to call it something more related to its function (like c-index-test's '-remap-file', or "header maps"). I don't have a suggestion I am in love with though, the best alternative I can think of at the moment is '-ifsmap' (or '-ifs-map', or maybe just '-iremap' since the -i already indicates it is include path specific).
- Daniel On Tue, Feb 25, 2014 at 10:23 AM, Ben Langmuir <[email protected]> wrote: > Author: benlangmuir > Date: Tue Feb 25 12:23:47 2014 > New Revision: 202176 > > URL: http://llvm.org/viewvc/llvm-project?rev=202176&view=rev > Log: > Add a driver option -ivfsoverlay > > Reads the description of a virtual filesystem from a file and overlays > it over the real file system. > > Added: > cfe/trunk/test/Driver/vfsoverlay.c > cfe/trunk/test/VFS/ > cfe/trunk/test/VFS/Inputs/ > cfe/trunk/test/VFS/Inputs/actual_header.h > cfe/trunk/test/VFS/Inputs/actual_module.map > cfe/trunk/test/VFS/Inputs/include_real.h > cfe/trunk/test/VFS/Inputs/invalid-yaml.yaml > cfe/trunk/test/VFS/Inputs/missing-key.yaml > cfe/trunk/test/VFS/Inputs/public_header.h > cfe/trunk/test/VFS/Inputs/unknown-key.yaml > cfe/trunk/test/VFS/Inputs/unknown-value.yaml > cfe/trunk/test/VFS/Inputs/vfsoverlay.yaml > cfe/trunk/test/VFS/framework-import.m > cfe/trunk/test/VFS/implicit-include.c > cfe/trunk/test/VFS/include-mixed-real-and-virtual.c > cfe/trunk/test/VFS/include-real-from-virtual.c > cfe/trunk/test/VFS/include-virtual-from-real.c > cfe/trunk/test/VFS/include.c > cfe/trunk/test/VFS/module-import.m > cfe/trunk/test/VFS/parse-errors.c > Modified: > cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td > cfe/trunk/include/clang/Driver/Options.td > cfe/trunk/include/clang/Lex/HeaderSearchOptions.h > cfe/trunk/lib/Basic/VirtualFileSystem.cpp > cfe/trunk/lib/Frontend/CompilerInvocation.cpp > cfe/trunk/lib/Frontend/FrontendAction.cpp > > Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=202176&r1=202175&r2=202176&view=diff > > ============================================================================== > --- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original) > +++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Tue Feb 25 > 12:23:47 2014 > @@ -158,4 +158,9 @@ def warn_module_config_macro_undef : War > InGroup<ConfigMacros>; > def note_module_def_undef_here : Note< > "macro was %select{defined|#undef'd}0 here">; > + > +def err_missing_vfs_overlay_file : Error< > + "virtual filesystem overlay file '%0' not found">, DefaultFatal; > +def err_invalid_vfs_overlay : Error< > + "invalid virtual filesystem overlay file '%0'">, DefaultFatal; > } > > Modified: cfe/trunk/include/clang/Driver/Options.td > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=202176&r1=202175&r2=202176&view=diff > > ============================================================================== > --- cfe/trunk/include/clang/Driver/Options.td (original) > +++ cfe/trunk/include/clang/Driver/Options.td Tue Feb 25 12:23:47 2014 > @@ -966,6 +966,8 @@ def iwithsysroot : JoinedOrSeparate<["-" > HelpText<"Add directory to SYSTEM include search path, " > "absolute paths are relative to -isysroot">, > MetaVarName<"<directory>">, > Flags<[CC1Option]>; > +def ivfsoverlay : JoinedOrSeparate<["-"], "ivfsoverlay">, > Group<clang_i_Group>, Flags<[CC1Option]>, > + HelpText<"Overlay the virtual filesystem described by file over the > real file system">; > def i : Joined<["-"], "i">, Group<i_Group>; > def keep__private__externs : Flag<["-"], "keep_private_externs">; > def l : JoinedOrSeparate<["-"], "l">, Flags<[LinkerInput, RenderJoined]>; > > Modified: cfe/trunk/include/clang/Lex/HeaderSearchOptions.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearchOptions.h?rev=202176&r1=202175&r2=202176&view=diff > > ============================================================================== > --- cfe/trunk/include/clang/Lex/HeaderSearchOptions.h (original) > +++ cfe/trunk/include/clang/Lex/HeaderSearchOptions.h Tue Feb 25 12:23:47 > 2014 > @@ -129,6 +129,9 @@ public: > /// \brief The set of user-provided module-map-files. > llvm::SetVector<std::string> ModuleMapFiles; > > + /// \brief The set of user-provided virtual filesystem overlay files. > + std::vector<std::string> VFSOverlayFiles; > + > /// Include the compiler builtin includes. > unsigned UseBuiltinIncludes : 1; > > @@ -172,6 +175,10 @@ public: > void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) { > SystemHeaderPrefixes.push_back(SystemHeaderPrefix(Prefix, > IsSystemHeader)); > } > + > + void AddVFSOverlayFile(StringRef Name) { > + VFSOverlayFiles.push_back(Name); > + } > }; > > } // end namespace clang > > Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=202176&r1=202175&r2=202176&view=diff > > ============================================================================== > --- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original) > +++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Tue Feb 25 12:23:47 2014 > @@ -761,7 +761,7 @@ error_code VFSFromYAML::openFileForRead( > if (!F) // FIXME: errc::not_a_file? > return error_code(errc::invalid_argument, system_category()); > > - return ExternalFS->openFileForRead(Path, Result); > + return ExternalFS->openFileForRead(F->getExternalContentsPath(), > Result); > } > > IntrusiveRefCntPtr<FileSystem> > > Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=202176&r1=202175&r2=202176&view=diff > > ============================================================================== > --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) > +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Feb 25 12:23:47 2014 > @@ -1020,6 +1020,10 @@ static void ParseHeaderSearchArgs(Header > I != E; ++I) > Opts.AddSystemHeaderPrefix((*I)->getValue(), > > (*I)->getOption().matches(OPT_isystem_prefix)); > + > + for (arg_iterator I = Args.filtered_begin(OPT_ivfsoverlay), > + E = Args.filtered_end(); I != E; ++I) > + Opts.AddVFSOverlayFile((*I)->getValue()); > } > > void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, > > Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=202176&r1=202175&r2=202176&view=diff > > ============================================================================== > --- cfe/trunk/lib/Frontend/FrontendAction.cpp (original) > +++ cfe/trunk/lib/Frontend/FrontendAction.cpp Tue Feb 25 12:23:47 2014 > @@ -211,6 +211,32 @@ bool FrontendAction::BeginSourceFile(Com > return true; > } > > + if (!CI.getHeaderSearchOpts().VFSOverlayFiles.empty()) { > + IntrusiveRefCntPtr<vfs::OverlayFileSystem> > + Overlay(new vfs::OverlayFileSystem(vfs::getRealFileSystem())); > + // earlier vfs files are on the bottom > + const std::vector<std::string> &Files = > + CI.getHeaderSearchOpts().VFSOverlayFiles; > + for (std::vector<std::string>::const_iterator I = Files.begin(), > + E = Files.end(); > + I != E; ++I) { > + OwningPtr<llvm::MemoryBuffer> Buffer; > + if (llvm::errc::success != llvm::MemoryBuffer::getFile(*I, Buffer)) > { > + CI.getDiagnostics().Report(diag::err_missing_vfs_overlay_file) << > *I; > + goto failure; > + } > + > + IntrusiveRefCntPtr<vfs::FileSystem> FS = > + vfs::getVFSFromYAML(Buffer.take(), /*DiagHandler*/0); > + if (!FS.getPtr()) { > + CI.getDiagnostics().Report(diag::err_invalid_vfs_overlay) << *I; > + goto failure; > + } > + Overlay->pushOverlay(FS); > + } > + CI.setVirtualFileSystem(Overlay); > + } > + > // Set up the file and source managers, if needed. > if (!CI.hasFileManager()) > CI.createFileManager(); > > Added: cfe/trunk/test/Driver/vfsoverlay.c > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/vfsoverlay.c?rev=202176&view=auto > > ============================================================================== > --- cfe/trunk/test/Driver/vfsoverlay.c (added) > +++ cfe/trunk/test/Driver/vfsoverlay.c Tue Feb 25 12:23:47 2014 > @@ -0,0 +1,5 @@ > +// RUN: %clang -ivfsoverlay foo.h -### %s 2>&1 | FileCheck %s > +// CHECK: "-ivfsoverlay" "foo.h" > + > +// RUN: not %clang -ivfsoverlay foo.h %s 2>&1 | FileCheck > -check-prefix=CHECK-MISSING %s > +// CHECK-MISSING: virtual filesystem overlay file 'foo.h' not found > > Added: cfe/trunk/test/VFS/Inputs/actual_header.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/actual_header.h?rev=202176&view=auto > > ============================================================================== > --- cfe/trunk/test/VFS/Inputs/actual_header.h (added) > +++ cfe/trunk/test/VFS/Inputs/actual_header.h Tue Feb 25 12:23:47 2014 > @@ -0,0 +1 @@ > +void bar(void); > > Added: cfe/trunk/test/VFS/Inputs/actual_module.map > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/actual_module.map?rev=202176&view=auto > > ============================================================================== > --- cfe/trunk/test/VFS/Inputs/actual_module.map (added) > +++ cfe/trunk/test/VFS/Inputs/actual_module.map Tue Feb 25 12:23:47 2014 > @@ -0,0 +1,4 @@ > +module not_real { > + header "not_real.h" > + export * > +} > > Added: cfe/trunk/test/VFS/Inputs/include_real.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/include_real.h?rev=202176&view=auto > > ============================================================================== > --- cfe/trunk/test/VFS/Inputs/include_real.h (added) > +++ cfe/trunk/test/VFS/Inputs/include_real.h Tue Feb 25 12:23:47 2014 > @@ -0,0 +1 @@ > +#include "real.h" > > Added: cfe/trunk/test/VFS/Inputs/invalid-yaml.yaml > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/invalid-yaml.yaml?rev=202176&view=auto > > ============================================================================== > --- cfe/trunk/test/VFS/Inputs/invalid-yaml.yaml (added) > +++ cfe/trunk/test/VFS/Inputs/invalid-yaml.yaml Tue Feb 25 12:23:47 2014 > @@ -0,0 +1,4 @@ > +{ > + 'version': 0, > + 'roots': [] > +] > > Added: cfe/trunk/test/VFS/Inputs/missing-key.yaml > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/missing-key.yaml?rev=202176&view=auto > > ============================================================================== > --- cfe/trunk/test/VFS/Inputs/missing-key.yaml (added) > +++ cfe/trunk/test/VFS/Inputs/missing-key.yaml Tue Feb 25 12:23:47 2014 > @@ -0,0 +1,4 @@ > +{ > + 'version': 0, > + 'roots': [ { 'name' : 'foo', 'external-contents': 'bar' } ] > +} > > Added: cfe/trunk/test/VFS/Inputs/public_header.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/public_header.h?rev=202176&view=auto > > ============================================================================== > --- cfe/trunk/test/VFS/Inputs/public_header.h (added) > +++ cfe/trunk/test/VFS/Inputs/public_header.h Tue Feb 25 12:23:47 2014 > @@ -0,0 +1 @@ > +void from_framework(void); > > Added: cfe/trunk/test/VFS/Inputs/unknown-key.yaml > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/unknown-key.yaml?rev=202176&view=auto > > ============================================================================== > --- cfe/trunk/test/VFS/Inputs/unknown-key.yaml (added) > +++ cfe/trunk/test/VFS/Inputs/unknown-key.yaml Tue Feb 25 12:23:47 2014 > @@ -0,0 +1,5 @@ > +{ > + 'version': 0, > + 'unknown-key': 'value', > + 'roots': [] > +} > > Added: cfe/trunk/test/VFS/Inputs/unknown-value.yaml > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/unknown-value.yaml?rev=202176&view=auto > > ============================================================================== > --- cfe/trunk/test/VFS/Inputs/unknown-value.yaml (added) > +++ cfe/trunk/test/VFS/Inputs/unknown-value.yaml Tue Feb 25 12:23:47 2014 > @@ -0,0 +1,5 @@ > +{ > + 'version': 0, > + 'case-sensitive': 'Maybe?', > + 'roots': [] > +} > > Added: cfe/trunk/test/VFS/Inputs/vfsoverlay.yaml > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/vfsoverlay.yaml?rev=202176&view=auto > > ============================================================================== > --- cfe/trunk/test/VFS/Inputs/vfsoverlay.yaml (added) > +++ cfe/trunk/test/VFS/Inputs/vfsoverlay.yaml Tue Feb 25 12:23:47 2014 > @@ -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' > + } > + ] > + } > + ] > +} > > Added: cfe/trunk/test/VFS/framework-import.m > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/framework-import.m?rev=202176&view=auto > > ============================================================================== > --- cfe/trunk/test/VFS/framework-import.m (added) > +++ cfe/trunk/test/VFS/framework-import.m Tue Feb 25 12:23:47 2014 > @@ -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(); > +} > > Added: cfe/trunk/test/VFS/implicit-include.c > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/implicit-include.c?rev=202176&view=auto > > ============================================================================== > --- cfe/trunk/test/VFS/implicit-include.c (added) > +++ cfe/trunk/test/VFS/implicit-include.c Tue Feb 25 12:23:47 2014 > @@ -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(); > +} > > Added: cfe/trunk/test/VFS/include-mixed-real-and-virtual.c > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/include-mixed-real-and-virtual.c?rev=202176&view=auto > > ============================================================================== > --- cfe/trunk/test/VFS/include-mixed-real-and-virtual.c (added) > +++ cfe/trunk/test/VFS/include-mixed-real-and-virtual.c Tue Feb 25 > 12:23:47 2014 > @@ -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(); > +} > > Added: cfe/trunk/test/VFS/include-real-from-virtual.c > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/include-real-from-virtual.c?rev=202176&view=auto > > ============================================================================== > --- cfe/trunk/test/VFS/include-real-from-virtual.c (added) > +++ cfe/trunk/test/VFS/include-real-from-virtual.c Tue Feb 25 12:23:47 2014 > @@ -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(); > +} > > Added: cfe/trunk/test/VFS/include-virtual-from-real.c > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/include-virtual-from-real.c?rev=202176&view=auto > > ============================================================================== > --- cfe/trunk/test/VFS/include-virtual-from-real.c (added) > +++ cfe/trunk/test/VFS/include-virtual-from-real.c Tue Feb 25 12:23:47 2014 > @@ -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(); > +} > > Added: cfe/trunk/test/VFS/include.c > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/include.c?rev=202176&view=auto > > ============================================================================== > --- cfe/trunk/test/VFS/include.c (added) > +++ cfe/trunk/test/VFS/include.c Tue Feb 25 12:23:47 2014 > @@ -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(); > +} > > Added: cfe/trunk/test/VFS/module-import.m > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/module-import.m?rev=202176&view=auto > > ============================================================================== > --- cfe/trunk/test/VFS/module-import.m (added) > +++ cfe/trunk/test/VFS/module-import.m Tue Feb 25 12:23:47 2014 > @@ -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(); > +} > > Added: cfe/trunk/test/VFS/parse-errors.c > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/parse-errors.c?rev=202176&view=auto > > ============================================================================== > --- cfe/trunk/test/VFS/parse-errors.c (added) > +++ cfe/trunk/test/VFS/parse-errors.c Tue Feb 25 12:23:47 2014 > @@ -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 > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
