From: Rafael Espindola Date: Wed, 26 Jun 2013 15:01:50 +0000 (+0000) Subject: Remove last use of PathV1.h from clang. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=902a86385361d5d0a3ae731c89a5b62e470dd875;p=clang Remove last use of PathV1.h from clang. Instead of creating a temporary directory, remember the set of temporary files we create. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184951 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/unittests/Tooling/RefactoringTest.cpp b/unittests/Tooling/RefactoringTest.cpp index da759258ab..f4c086c4a3 100644 --- a/unittests/Tooling/RefactoringTest.cpp +++ b/unittests/Tooling/RefactoringTest.cpp @@ -26,7 +26,6 @@ #include "clang/Tooling/Tooling.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/Path.h" -#include "llvm/Support/PathV1.h" #include "gtest/gtest.h" namespace clang { @@ -177,36 +176,43 @@ TEST(ShiftedCodePositionTest, FindsNewCodePositionWithInserts) { } class FlushRewrittenFilesTest : public ::testing::Test { - public: - FlushRewrittenFilesTest() { - std::string ErrorInfo; - TemporaryDirectory = llvm::sys::Path::GetTemporaryDirectory(&ErrorInfo); - assert(ErrorInfo.empty()); - } +public: + FlushRewrittenFilesTest() {} ~FlushRewrittenFilesTest() { - std::string ErrorInfo; - TemporaryDirectory.eraseFromDisk(true, &ErrorInfo); - assert(ErrorInfo.empty()); + for (llvm::StringMap::iterator I = TemporaryFiles.begin(), + E = TemporaryFiles.end(); + I != E; ++I) { + llvm::StringRef Name = I->second; + llvm::error_code EC = llvm::sys::fs::remove(Name); + (void)EC; + assert(!EC); + } } FileID createFile(llvm::StringRef Name, llvm::StringRef Content) { - SmallString<1024> Path(TemporaryDirectory.str()); - llvm::sys::path::append(Path, Name); - std::string ErrorInfo; - llvm::raw_fd_ostream OutStream(Path.c_str(), - ErrorInfo, llvm::raw_fd_ostream::F_Binary); - assert(ErrorInfo.empty()); + SmallString<1024> Path; + int FD; + llvm::error_code EC = + llvm::sys::fs::unique_file(Twine(Name) + "%%%%%%", FD, Path); + assert(!EC); + (void)EC; + + llvm::raw_fd_ostream OutStream(FD, true); OutStream << Content; OutStream.close(); const FileEntry *File = Context.Files.getFile(Path); assert(File != NULL); + + StringRef Found = TemporaryFiles.GetOrCreateValue(Name, Path.str()).second; + assert(Found == Path); + (void)Found; return Context.Sources.createFileID(File, SourceLocation(), SrcMgr::C_User); } std::string getFileContentFromDisk(llvm::StringRef Name) { - SmallString<1024> Path(TemporaryDirectory.str()); - llvm::sys::path::append(Path, Name); + std::string Path = TemporaryFiles.lookup(Name); + assert(!Path.empty()); // We need to read directly from the FileManager without relaying through // a FileEntry, as otherwise we'd read through an already opened file // descriptor, which might not see the changes made. @@ -215,7 +221,7 @@ class FlushRewrittenFilesTest : public ::testing::Test { return Context.Files.getBufferForFile(Path, NULL)->getBuffer(); } - llvm::sys::Path TemporaryDirectory; + llvm::StringMap TemporaryFiles; RewriterTestContext Context; };