Skip to content

Commit

Permalink
Use VFS operations in FileManager::makeAbsolutePath.
Browse files Browse the repository at this point in the history
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

llvm-svn: 309795
  • Loading branch information
ilya-biryukov committed Aug 2, 2017
1 parent 7b370e4 commit 47035c0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Basic/FileManager.cpp
Expand Up @@ -408,7 +408,7 @@ bool FileManager::makeAbsolutePath(SmallVectorImpl<char> &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;
}

Expand Down
27 changes: 27 additions & 0 deletions clang/unittests/Basic/FileManagerTest.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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<vfs::InMemoryFileSystem>(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

0 comments on commit 47035c0

Please sign in to comment.