From: Bruno Cardoso Lopes Date: Tue, 23 Feb 2016 07:06:12 +0000 (+0000) Subject: Revert "[VFS] Add 'overlay-relative' field to YAML files" and "[VFS] Fix call to... X-Git-Tag: llvmorg-3.9.0-rc1~13485 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b7eb8db02369b7abf72ba6d06f9064c05f76cbb7;p=platform%2Fupstream%2Fllvm.git Revert "[VFS] Add 'overlay-relative' field to YAML files" and "[VFS] Fix call to getVFSFromYAML in unittests" This reverts commit r261552 and r261556 because of failing unittests on windows: Failing Tests (4): Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.CaseInsensitive Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.DirectoryIteration Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.MappedFiles Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.UseExternalName llvm-svn: 261613 --- diff --git a/clang/include/clang/Basic/VirtualFileSystem.h b/clang/include/clang/Basic/VirtualFileSystem.h index cc13d72..bab88c9 100644 --- a/clang/include/clang/Basic/VirtualFileSystem.h +++ b/clang/include/clang/Basic/VirtualFileSystem.h @@ -310,7 +310,6 @@ llvm::sys::fs::UniqueID getNextVirtualUniqueID(); IntrusiveRefCntPtr getVFSFromYAML(std::unique_ptr Buffer, llvm::SourceMgr::DiagHandlerTy DiagHandler, - StringRef YAMLFilePath, void *DiagContext = nullptr, IntrusiveRefCntPtr ExternalFS = getRealFileSystem()); @@ -324,8 +323,6 @@ struct YAMLVFSEntry { class YAMLVFSWriter { std::vector Mappings; Optional IsCaseSensitive; - Optional IsOverlayRelative; - std::string OverlayDir; public: YAMLVFSWriter() {} @@ -333,11 +330,6 @@ public: void setCaseSensitivity(bool CaseSensitive) { IsCaseSensitive = CaseSensitive; } - void setOverlayDir(StringRef OverlayDirectory) { - IsOverlayRelative = true; - OverlayDir.assign(OverlayDirectory.str()); - } - void write(llvm::raw_ostream &OS); }; diff --git a/clang/lib/Basic/VirtualFileSystem.cpp b/clang/lib/Basic/VirtualFileSystem.cpp index cfe61dc..68ad428 100644 --- a/clang/lib/Basic/VirtualFileSystem.cpp +++ b/clang/lib/Basic/VirtualFileSystem.cpp @@ -790,7 +790,6 @@ public: /// All configuration options are optional. /// 'case-sensitive': /// 'use-external-names': -/// 'overlay-relative': /// /// Virtual directories are represented as /// \verbatim @@ -833,10 +832,6 @@ class RedirectingFileSystem : public vfs::FileSystem { std::vector> Roots; /// \brief The file system to use for external references. IntrusiveRefCntPtr ExternalFS; - /// If IsRelativeOverlay is set, this represents the directory - /// path that should be prefixed to each 'external-contents' entry - /// when reading from YAML files. - std::string ExternalContentsPrefixDir; /// @name Configuration /// @{ @@ -846,10 +841,6 @@ class RedirectingFileSystem : public vfs::FileSystem { /// Currently, case-insensitive matching only works correctly with ASCII. bool CaseSensitive; - /// IsRelativeOverlay marks whether a IsExternalContentsPrefixDir path must - /// be prefixed in every 'external-contents' when reading from YAML files. - bool IsRelativeOverlay = false; - /// \brief Whether to use to use the value of 'external-contents' for the /// names of files. This global value is overridable on a per-file basis. bool UseExternalNames; @@ -877,8 +868,8 @@ public: /// returns a virtual file system representing its contents. static RedirectingFileSystem * create(std::unique_ptr Buffer, - SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath, - void *DiagContext, IntrusiveRefCntPtr ExternalFS); + SourceMgr::DiagHandlerTy DiagHandler, void *DiagContext, + IntrusiveRefCntPtr ExternalFS); ErrorOr status(const Twine &Path) override; ErrorOr> openFileForRead(const Twine &Path) override; @@ -911,15 +902,6 @@ public: return directory_iterator(std::make_shared(Dir, *this, D->contents_begin(), D->contents_end(), EC)); } - - void setExternalContentsPrefixDir(StringRef PrefixDir) { - ExternalContentsPrefixDir = PrefixDir.str(); - } - - StringRef getExternalContentsPrefixDir() const { - return ExternalContentsPrefixDir; - } - }; /// \brief A helper class to hold the common YAML parsing state. @@ -999,7 +981,7 @@ class RedirectingFileSystemParser { return true; } - std::unique_ptr parseEntry(yaml::Node *N, RedirectingFileSystem *FS) { + std::unique_ptr parseEntry(yaml::Node *N) { yaml::MappingNode *M = dyn_cast(N); if (!M) { error(N, "expected mapping node for file or directory entry"); @@ -1075,7 +1057,7 @@ class RedirectingFileSystemParser { for (yaml::SequenceNode::iterator I = Contents->begin(), E = Contents->end(); I != E; ++I) { - if (std::unique_ptr E = parseEntry(&*I, FS)) + if (std::unique_ptr E = parseEntry(&*I)) EntryArrayContents.push_back(std::move(E)); else return nullptr; @@ -1089,22 +1071,12 @@ class RedirectingFileSystemParser { HasContents = true; if (!parseScalarString(I->getValue(), Value, Buffer)) return nullptr; - - SmallString<128> FullPath; - if (FS->IsRelativeOverlay) { - FullPath = FS->getExternalContentsPrefixDir(); - assert(!FullPath.empty() && - "External contents prefix directory must exist"); - llvm::sys::path::append(FullPath, Value); - } else { - FullPath = Value; - } - + SmallString<256> Path(Value); // Guarantee that old YAML files containing paths with ".." and "." are // properly canonicalized before read into the VFS. - FullPath = sys::path::remove_leading_dotslash(FullPath); - sys::path::remove_dots(FullPath, /*remove_dot_dot=*/true); - ExternalContentsPath = FullPath.str(); + Path = sys::path::remove_leading_dotslash(Path); + sys::path::remove_dots(Path, /*remove_dot_dot=*/true); + ExternalContentsPath = Path.str(); } else if (Key == "use-external-name") { bool Val; if (!parseScalarBool(I->getValue(), Val)) @@ -1190,7 +1162,6 @@ public: KeyStatusPair("version", true), KeyStatusPair("case-sensitive", false), KeyStatusPair("use-external-names", false), - KeyStatusPair("overlay-relative", false), KeyStatusPair("roots", true), }; @@ -1216,7 +1187,7 @@ public: for (yaml::SequenceNode::iterator I = Roots->begin(), E = Roots->end(); I != E; ++I) { - if (std::unique_ptr E = parseEntry(&*I, FS)) + if (std::unique_ptr E = parseEntry(&*I)) FS->Roots.push_back(std::move(E)); else return false; @@ -1242,9 +1213,6 @@ public: } else if (Key == "case-sensitive") { if (!parseScalarBool(I->getValue(), FS->CaseSensitive)) return false; - } else if (Key == "overlay-relative") { - if (!parseScalarBool(I->getValue(), FS->IsRelativeOverlay)) - return false; } else if (Key == "use-external-names") { if (!parseScalarBool(I->getValue(), FS->UseExternalNames)) return false; @@ -1265,11 +1233,9 @@ public: Entry::~Entry() = default; -RedirectingFileSystem * -RedirectingFileSystem::create(std::unique_ptr Buffer, - SourceMgr::DiagHandlerTy DiagHandler, - StringRef YAMLFilePath, void *DiagContext, - IntrusiveRefCntPtr ExternalFS) { +RedirectingFileSystem *RedirectingFileSystem::create( + std::unique_ptr Buffer, SourceMgr::DiagHandlerTy DiagHandler, + void *DiagContext, IntrusiveRefCntPtr ExternalFS) { SourceMgr SM; yaml::Stream Stream(Buffer->getMemBufferRef(), SM); @@ -1286,23 +1252,6 @@ RedirectingFileSystem::create(std::unique_ptr Buffer, std::unique_ptr FS( new RedirectingFileSystem(ExternalFS)); - - if (!YAMLFilePath.empty()) { - // Use the YAML path from -ivfsoverlay to compute the dir to be prefixed - // to each 'external-contents' path. - // - // Example: - // -ivfsoverlay dummy.cache/vfs/vfs.yaml - // yields: - // FS->ExternalContentsPrefixDir => //dummy.cache/vfs - // - SmallString<256> OverlayAbsDir = sys::path::parent_path(YAMLFilePath); - std::error_code EC = llvm::sys::fs::make_absolute(OverlayAbsDir); - assert(!EC && "Overlay dir final path must be absolute"); - (void)EC; - FS->setExternalContentsPrefixDir(OverlayAbsDir); - } - if (!P.parse(Root, FS.get())) return nullptr; @@ -1447,12 +1396,10 @@ RedirectingFileSystem::openFileForRead(const Twine &Path) { IntrusiveRefCntPtr vfs::getVFSFromYAML(std::unique_ptr Buffer, - SourceMgr::DiagHandlerTy DiagHandler, - StringRef YAMLFilePath, - void *DiagContext, + SourceMgr::DiagHandlerTy DiagHandler, void *DiagContext, IntrusiveRefCntPtr ExternalFS) { return RedirectingFileSystem::create(std::move(Buffer), DiagHandler, - YAMLFilePath, DiagContext, ExternalFS); + DiagContext, ExternalFS); } UniqueID vfs::getNextVirtualUniqueID() { @@ -1484,8 +1431,7 @@ class JSONWriter { public: JSONWriter(llvm::raw_ostream &OS) : OS(OS) {} - void write(ArrayRef Entries, Optional IsCaseSensitive, - Optional IsOverlayRelative, StringRef OverlayDir); + void write(ArrayRef Entries, Optional IsCaseSensitive); }; } @@ -1538,9 +1484,7 @@ void JSONWriter::writeEntry(StringRef VPath, StringRef RPath) { } void JSONWriter::write(ArrayRef Entries, - Optional IsCaseSensitive, - Optional IsOverlayRelative, - StringRef OverlayDir) { + Optional IsCaseSensitive) { using namespace llvm::sys; OS << "{\n" @@ -1548,27 +1492,12 @@ void JSONWriter::write(ArrayRef Entries, if (IsCaseSensitive.hasValue()) OS << " 'case-sensitive': '" << (IsCaseSensitive.getValue() ? "true" : "false") << "',\n"; - bool UseOverlayRelative = false; - if (IsOverlayRelative.hasValue()) { - UseOverlayRelative = IsOverlayRelative.getValue(); - OS << " 'overlay-relative': '" - << (UseOverlayRelative ? "true" : "false") << "',\n"; - } OS << " 'roots': [\n"; if (!Entries.empty()) { const YAMLVFSEntry &Entry = Entries.front(); startDirectory(path::parent_path(Entry.VPath)); - - StringRef RPath = Entry.RPath; - if (UseOverlayRelative) { - unsigned OverlayDirLen = OverlayDir.size(); - assert(RPath.substr(0, OverlayDirLen) == OverlayDir && - "Overlay dir must be contained in RPath"); - RPath = RPath.slice(OverlayDirLen, RPath.size()); - } - - writeEntry(path::filename(Entry.VPath), RPath); + writeEntry(path::filename(Entry.VPath), Entry.RPath); for (const auto &Entry : Entries.slice(1)) { StringRef Dir = path::parent_path(Entry.VPath); @@ -1582,14 +1511,7 @@ void JSONWriter::write(ArrayRef Entries, OS << ",\n"; startDirectory(Dir); } - StringRef RPath = Entry.RPath; - if (UseOverlayRelative) { - unsigned OverlayDirLen = OverlayDir.size(); - assert(RPath.substr(0, OverlayDirLen) == OverlayDir && - "Overlay dir must be contained in RPath"); - RPath = RPath.slice(OverlayDirLen, RPath.size()); - } - writeEntry(path::filename(Entry.VPath), RPath); + writeEntry(path::filename(Entry.VPath), Entry.RPath); } while (!DirStack.empty()) { @@ -1609,8 +1531,7 @@ void YAMLVFSWriter::write(llvm::raw_ostream &OS) { return LHS.VPath < RHS.VPath; }); - JSONWriter(OS).write(Mappings, IsCaseSensitive, IsOverlayRelative, - OverlayDir); + JSONWriter(OS).write(Mappings, IsCaseSensitive); } VFSFromYamlDirIterImpl::VFSFromYamlDirIterImpl( diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index feace7e..cf4b5cf 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -2344,8 +2344,8 @@ createVFSFromCompilerInvocation(const CompilerInvocation &CI, return IntrusiveRefCntPtr(); } - IntrusiveRefCntPtr FS = vfs::getVFSFromYAML( - std::move(Buffer.get()), /*DiagHandler*/ nullptr, File); + IntrusiveRefCntPtr FS = + vfs::getVFSFromYAML(std::move(Buffer.get()), /*DiagHandler*/ nullptr); if (!FS.get()) { Diags.Report(diag::err_invalid_vfs_overlay) << File; return IntrusiveRefCntPtr(); diff --git a/clang/lib/Frontend/ModuleDependencyCollector.cpp b/clang/lib/Frontend/ModuleDependencyCollector.cpp index 7ba0464..df5e19d 100644 --- a/clang/lib/Frontend/ModuleDependencyCollector.cpp +++ b/clang/lib/Frontend/ModuleDependencyCollector.cpp @@ -51,10 +51,6 @@ void ModuleDependencyCollector::writeFileMap() { SmallString<256> Dest = getDest(); llvm::sys::path::append(Dest, "vfs.yaml"); - // Default to use relative overlay directories in the VFS yaml file. This - // allows crash reproducer scripts to work across machines. - VFSWriter.setOverlayDir(getDest()); - std::error_code EC; llvm::raw_fd_ostream OS(Dest, EC, llvm::sys::fs::F_Text); if (EC) { diff --git a/clang/test/Modules/crash-vfs-path-symlink-component.m b/clang/test/Modules/crash-vfs-path-symlink-component.m index 9256ffd..759bad0 100644 --- a/clang/test/Modules/crash-vfs-path-symlink-component.m +++ b/clang/test/Modules/crash-vfs-path-symlink-component.m @@ -40,21 +40,21 @@ // CHECKSH: "-ivfsoverlay" "crash-vfs-{{[^ ]*}}.cache/vfs/vfs.yaml" // CHECKYAML: 'type': 'directory' -// CHECKYAML: 'name': "/[[PATH:.*]]/i/usr/include", +// CHECKYAML: 'name': "{{[^ ]*}}/i/usr/include", // CHECKYAML-NEXT: 'contents': [ // CHECKYAML-NEXT: { // CHECKYAML-NEXT: 'type': 'file', // CHECKYAML-NEXT: 'name': "module.map", -// CHECKYAML-NEXT: 'external-contents': "/[[PATH]]/i/usr/include/module.map" +// CHECKYAML-NEXT: 'external-contents': "{{[^ ]*}}.cache/vfs/{{[^ ]*}}/i/usr/include/module.map" // CHECKYAML-NEXT: }, // CHECKYAML: 'type': 'directory' -// CHECKYAML: 'name': "/[[PATH]]/i/usr", +// CHECKYAML: 'name': "{{[^ ]*}}/i/usr", // CHECKYAML-NEXT: 'contents': [ // CHECKYAML-NEXT: { // CHECKYAML-NEXT: 'type': 'file', // CHECKYAML-NEXT: 'name': "module.map", -// CHECKYAML-NEXT: 'external-contents': "/[[PATH]]/i/usr/include/module.map" +// CHECKYAML-NEXT: 'external-contents': "{{[^ ]*}}.cache/vfs/{{[^ ]*}}/i/usr/include/module.map" // CHECKYAML-NEXT: }, // Test that by using the previous generated YAML file clang is able to find the diff --git a/clang/test/Modules/crash-vfs-path-traversal.m b/clang/test/Modules/crash-vfs-path-traversal.m index 75e484e..8acd217 100644 --- a/clang/test/Modules/crash-vfs-path-traversal.m +++ b/clang/test/Modules/crash-vfs-path-traversal.m @@ -35,12 +35,12 @@ // CHECKSH: "-ivfsoverlay" "crash-vfs-{{[^ ]*}}.cache/vfs/vfs.yaml" // CHECKYAML: 'type': 'directory' -// CHECKYAML: 'name': "/[[PATH:.*]]/Inputs/System/usr/include", +// CHECKYAML: 'name': "{{[^ ]*}}/Inputs/System/usr/include", // CHECKYAML-NEXT: 'contents': [ // CHECKYAML-NEXT: { // CHECKYAML-NEXT: 'type': 'file', // CHECKYAML-NEXT: 'name': "module.map", -// CHECKYAML-NEXT: 'external-contents': "/[[PATH]]/Inputs/System/usr/include/module.map" +// CHECKYAML-NEXT: 'external-contents': "{{[^ ]*}}/Inputs/System/usr/include/module.map" // CHECKYAML-NEXT: }, // Replace the paths in the YAML files with relative ".." traversals @@ -49,10 +49,9 @@ // RUN: sed -e "s@usr/include@usr/include/../include@g" \ // RUN: %t/crash-vfs-*.cache/vfs/vfs.yaml > %t/vfs.yaml -// RUN: cp %t/vfs.yaml %t/crash-vfs-*.cache/vfs/vfs.yaml // RUN: unset FORCE_CLANG_DIAGNOSTICS_CRASH // RUN: %clang -E %s -I %S/Inputs/System -isysroot %/t/i/ \ -// RUN: -ivfsoverlay %t/crash-vfs-*.cache/vfs/vfs.yaml -fmodules \ +// RUN: -ivfsoverlay %t/vfs.yaml -fmodules \ // RUN: -fmodules-cache-path=%t/m/ 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECKOVERLAY diff --git a/clang/test/Modules/crash-vfs-relative-overlay.m b/clang/test/Modules/crash-vfs-relative-overlay.m deleted file mode 100644 index ea72454..0000000 --- a/clang/test/Modules/crash-vfs-relative-overlay.m +++ /dev/null @@ -1,56 +0,0 @@ -// REQUIRES: crash-recovery, shell - -// FIXME: This XFAIL is cargo-culted from crash-report.c. Do we need it? -// XFAIL: mingw32 - -// RUN: rm -rf %t -// RUN: mkdir -p %t/i %t/m %t - -// RUN: not env FORCE_CLANG_DIAGNOSTICS_CRASH= TMPDIR=%t TEMP=%t TMP=%t \ -// RUN: %clang -fsyntax-only %s -I %S/Inputs/System -isysroot %/t/i/ \ -// RUN: -fmodules -fmodules-cache-path=%t/m/ 2>&1 | FileCheck %s - -// RUN: FileCheck --check-prefix=CHECKSRC %s -input-file %t/crash-vfs-*.m -// RUN: FileCheck --check-prefix=CHECKSH %s -input-file %t/crash-vfs-*.sh -// RUN: FileCheck --check-prefix=CHECKYAML %s -input-file \ -// RUN: %t/crash-vfs-*.cache/vfs/vfs.yaml -// RUN: find %t/crash-vfs-*.cache/vfs | \ -// RUN: grep "Inputs/System/usr/include/stdio.h" | count 1 - -#include "usr/include/stdio.h" - -// CHECK: Preprocessed source(s) and associated run script(s) are located at: -// CHECK-NEXT: note: diagnostic msg: {{.*}}.m -// CHECK-NEXT: note: diagnostic msg: {{.*}}.cache - -// CHECKSRC: @import cstd.stdio; - -// CHECKSH: # Crash reproducer -// CHECKSH-NEXT: # Driver args: "-fsyntax-only" -// CHECKSH-NEXT: # Original command: {{.*$}} -// CHECKSH-NEXT: "-cc1" -// CHECKSH: "-isysroot" "{{[^"]*}}/i/" -// CHECKSH-NOT: "-fmodules-cache-path=" -// CHECKSH: "crash-vfs-{{[^ ]*}}.m" -// CHECKSH: "-ivfsoverlay" "crash-vfs-{{[^ ]*}}.cache/vfs/vfs.yaml" - -// CHECKYAML: 'type': 'directory' -// CHECKYAML: 'name': "/[[PATH:.*]]/Inputs/System/usr/include", -// CHECKYAML-NEXT: 'contents': [ -// CHECKYAML-NEXT: { -// CHECKYAML-NEXT: 'type': 'file', -// CHECKYAML-NEXT: 'name': "module.map", -// CHECKYAML-NOT: 'external-contents': "{{[^ ]*}}.cache -// CHECKYAML-NEXT: 'external-contents': "/[[PATH]]/Inputs/System/usr/include/module.map" -// CHECKYAML-NEXT: }, - -// Test that reading the YAML file will yield the correct path after -// the overlay dir is prefixed to access headers in .cache/vfs directory. - -// RUN: unset FORCE_CLANG_DIAGNOSTICS_CRASH -// RUN: %clang -E %s -I %S/Inputs/System -isysroot %/t/i/ \ -// RUN: -ivfsoverlay %t/crash-vfs-*.cache/vfs/vfs.yaml -fmodules \ -// RUN: -fmodules-cache-path=%t/m/ 2>&1 \ -// RUN: | FileCheck %s --check-prefix=CHECKOVERLAY - -// CHECKOVERLAY: @import cstd.stdio; /* clang -E: implicit import for "{{[^ ]*}}.cache/vfs/{{[^ ]*}}/usr/include/stdio.h" diff --git a/clang/unittests/Basic/VirtualFileSystemTest.cpp b/clang/unittests/Basic/VirtualFileSystemTest.cpp index d2f4a7d..9448ad4 100644 --- a/clang/unittests/Basic/VirtualFileSystemTest.cpp +++ b/clang/unittests/Basic/VirtualFileSystemTest.cpp @@ -662,7 +662,7 @@ public: getFromYAMLRawString(StringRef Content, IntrusiveRefCntPtr ExternalFS) { std::unique_ptr Buffer = MemoryBuffer::getMemBuffer(Content); - return getVFSFromYAML(std::move(Buffer), CountingDiagHandler, "", this, + return getVFSFromYAML(std::move(Buffer), CountingDiagHandler, this, ExternalFS); }