From b59cf679e81483cbb3a9252056b7528f4c49586c Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Thu, 27 Feb 2014 00:25:12 +0000 Subject: Add a 'use-external-names' option to VFS overlay files When true, sets the name of the file to be the name from 'external-contents'. Otherwise, you get the virtual path that the file was looked up by. This will not affect any non-virtual paths, or fully virtual paths (for which there is no reasonable 'external' name anyway). The setting is available globally, but can be overriden on a per-file basis. The goal is that this setting will control which path you see in debug info, diagnostics, etc. which are sensitive to which path is used. That will come in future patches that pass the name through to FileManager. llvm-svn: 202329 --- clang/unittests/Basic/VirtualFileSystemTest.cpp | 54 ++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'clang/unittests/Basic/VirtualFileSystemTest.cpp') diff --git a/clang/unittests/Basic/VirtualFileSystemTest.cpp b/clang/unittests/Basic/VirtualFileSystemTest.cpp index 334b1a45ddf..367e79492a8 100644 --- a/clang/unittests/Basic/VirtualFileSystemTest.cpp +++ b/clang/unittests/Basic/VirtualFileSystemTest.cpp @@ -290,8 +290,7 @@ TEST_F(VFSFromYAMLTest, MappedFiles) { // file ErrorOr S = O->status("/file1"); ASSERT_EQ(errc::success, S.getError()); - EXPECT_EQ("/file1", S->getName()); - EXPECT_EQ("/foo/bar/a", S->getExternalName()); + EXPECT_EQ("/foo/bar/a", S->getName()); ErrorOr SLower = O->status("/foo/bar/a"); EXPECT_EQ("/foo/bar/a", SLower->getName()); @@ -467,6 +466,57 @@ TEST_F(VFSFromYAMLTest, IllegalVFSFile) { EXPECT_EQ(24, NumDiagnostics); } +TEST_F(VFSFromYAMLTest, UseExternalName) { + IntrusiveRefCntPtr Lower(new DummyFileSystem()); + Lower->addRegularFile("/external/file"); + + IntrusiveRefCntPtr FS = getFromYAMLString( + "{ 'roots': [\n" + " { 'type': 'file', 'name': '/A',\n" + " 'external-contents': '/external/file'\n" + " },\n" + " { 'type': 'file', 'name': '/B',\n" + " 'use-external-name': true,\n" + " 'external-contents': '/external/file'\n" + " },\n" + " { 'type': 'file', 'name': '/C',\n" + " 'use-external-name': false,\n" + " 'external-contents': '/external/file'\n" + " }\n" + "] }", Lower); + ASSERT_TRUE(NULL != FS.getPtr()); + + // default true + EXPECT_EQ("/external/file", FS->status("/A")->getName()); + // explicit + EXPECT_EQ("/external/file", FS->status("/B")->getName()); + EXPECT_EQ("/C", FS->status("/C")->getName()); + + // global configuration + FS = getFromYAMLString( + "{ 'use-external-names': false,\n" + " 'roots': [\n" + " { 'type': 'file', 'name': '/A',\n" + " 'external-contents': '/external/file'\n" + " },\n" + " { 'type': 'file', 'name': '/B',\n" + " 'use-external-name': true,\n" + " 'external-contents': '/external/file'\n" + " },\n" + " { 'type': 'file', 'name': '/C',\n" + " 'use-external-name': false,\n" + " 'external-contents': '/external/file'\n" + " }\n" + "] }", Lower); + ASSERT_TRUE(NULL != FS.getPtr()); + + // default + EXPECT_EQ("/A", FS->status("/A")->getName()); + // explicit + EXPECT_EQ("/external/file", FS->status("/B")->getName()); + EXPECT_EQ("/C", FS->status("/C")->getName()); +} + TEST_F(VFSFromYAMLTest, MultiComponentPath) { IntrusiveRefCntPtr Lower(new DummyFileSystem()); Lower->addRegularFile("/other"); -- cgit v1.2.3