Remove last use of PathV1.h from clang.

Instead of creating a temporary directory, remember the set of temporary files
we create.

llvm-svn: 184951
This commit is contained in:
Rafael Espindola 2013-06-26 15:01:50 +00:00
parent 06d6c25141
commit 641c6a182b
1 changed files with 25 additions and 19 deletions

View File

@ -26,7 +26,6 @@
#include "clang/Tooling/Tooling.h" #include "clang/Tooling/Tooling.h"
#include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallString.h"
#include "llvm/Support/Path.h" #include "llvm/Support/Path.h"
#include "llvm/Support/PathV1.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace clang { namespace clang {
@ -177,36 +176,43 @@ TEST(ShiftedCodePositionTest, FindsNewCodePositionWithInserts) {
} }
class FlushRewrittenFilesTest : public ::testing::Test { class FlushRewrittenFilesTest : public ::testing::Test {
public: public:
FlushRewrittenFilesTest() { FlushRewrittenFilesTest() {}
std::string ErrorInfo;
TemporaryDirectory = llvm::sys::Path::GetTemporaryDirectory(&ErrorInfo);
assert(ErrorInfo.empty());
}
~FlushRewrittenFilesTest() { ~FlushRewrittenFilesTest() {
std::string ErrorInfo; for (llvm::StringMap<std::string>::iterator I = TemporaryFiles.begin(),
TemporaryDirectory.eraseFromDisk(true, &ErrorInfo); E = TemporaryFiles.end();
assert(ErrorInfo.empty()); 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) { FileID createFile(llvm::StringRef Name, llvm::StringRef Content) {
SmallString<1024> Path(TemporaryDirectory.str()); SmallString<1024> Path;
llvm::sys::path::append(Path, Name); int FD;
std::string ErrorInfo; llvm::error_code EC =
llvm::raw_fd_ostream OutStream(Path.c_str(), llvm::sys::fs::unique_file(Twine(Name) + "%%%%%%", FD, Path);
ErrorInfo, llvm::raw_fd_ostream::F_Binary); assert(!EC);
assert(ErrorInfo.empty()); (void)EC;
llvm::raw_fd_ostream OutStream(FD, true);
OutStream << Content; OutStream << Content;
OutStream.close(); OutStream.close();
const FileEntry *File = Context.Files.getFile(Path); const FileEntry *File = Context.Files.getFile(Path);
assert(File != NULL); 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); return Context.Sources.createFileID(File, SourceLocation(), SrcMgr::C_User);
} }
std::string getFileContentFromDisk(llvm::StringRef Name) { std::string getFileContentFromDisk(llvm::StringRef Name) {
SmallString<1024> Path(TemporaryDirectory.str()); std::string Path = TemporaryFiles.lookup(Name);
llvm::sys::path::append(Path, Name); assert(!Path.empty());
// We need to read directly from the FileManager without relaying through // We need to read directly from the FileManager without relaying through
// a FileEntry, as otherwise we'd read through an already opened file // a FileEntry, as otherwise we'd read through an already opened file
// descriptor, which might not see the changes made. // descriptor, which might not see the changes made.
@ -215,7 +221,7 @@ class FlushRewrittenFilesTest : public ::testing::Test {
return Context.Files.getBufferForFile(Path, NULL)->getBuffer(); return Context.Files.getBufferForFile(Path, NULL)->getBuffer();
} }
llvm::sys::Path TemporaryDirectory; llvm::StringMap<std::string> TemporaryFiles;
RewriterTestContext Context; RewriterTestContext Context;
}; };