From: Ilya Biryukov Date: Wed, 2 Aug 2017 07:25:24 +0000 (+0000) Subject: Use VFS operations in FileManager::makeAbsolutePath. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d7be359ae9ef18903ff36837e5a9c6caab69a1b4;p=clang Use VFS operations in FileManager::makeAbsolutePath. Summary: It used to call into llvm::sys::fs::make_absolute. Reviewers: akyrtzi, erikjv, bkramer, krasimir, klimek Reviewed By: klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D36155 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309795 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Basic/FileManager.cpp b/lib/Basic/FileManager.cpp index 0c10b5f4d1..a3e226d6cc 100644 --- a/lib/Basic/FileManager.cpp +++ b/lib/Basic/FileManager.cpp @@ -408,7 +408,7 @@ bool FileManager::makeAbsolutePath(SmallVectorImpl &Path) const { bool Changed = FixupRelativePath(Path); if (!llvm::sys::path::is_absolute(StringRef(Path.data(), Path.size()))) { - llvm::sys::fs::make_absolute(Path); + FS->makeAbsolute(Path); Changed = true; } diff --git a/unittests/Basic/FileManagerTest.cpp b/unittests/Basic/FileManagerTest.cpp index a19535e104..a2a6c6aebe 100644 --- a/unittests/Basic/FileManagerTest.cpp +++ b/unittests/Basic/FileManagerTest.cpp @@ -10,6 +10,7 @@ #include "clang/Basic/FileManager.h" #include "clang/Basic/FileSystemOptions.h" #include "clang/Basic/FileSystemStatCache.h" +#include "clang/Basic/VirtualFileSystem.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Config/llvm-config.h" #include "llvm/Support/Path.h" @@ -296,4 +297,30 @@ TEST_F(FileManagerTest, getVirtualFileWithDifferentName) { #endif // !LLVM_ON_WIN32 +TEST_F(FileManagerTest, makeAbsoluteUsesVFS) { + SmallString<64> CustomWorkingDir; +#ifdef LLVM_ON_WIN32 + CustomWorkingDir = "C:"; +#else + CustomWorkingDir = "/"; +#endif + llvm::sys::path::append(CustomWorkingDir, "some", "weird", "path"); + + auto FS = + IntrusiveRefCntPtr(new vfs::InMemoryFileSystem); + // setCurrentworkingdirectory must finish without error. + ASSERT_TRUE(!FS->setCurrentWorkingDirectory(CustomWorkingDir)); + + FileSystemOptions Opts; + FileManager Manager(Opts, FS); + + SmallString<64> Path("a/foo.cpp"); + + SmallString<64> ExpectedResult(CustomWorkingDir); + llvm::sys::path::append(ExpectedResult, Path); + + ASSERT_TRUE(Manager.makeAbsolutePath(Path)); + EXPECT_EQ(Path, ExpectedResult); +} + } // anonymous namespace