From 72787ac661626c6972bf028dfb9b3615a89346ea Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 9 Nov 2018 01:59:28 +0000 Subject: [PATCH] Revert "[FileSystem] Make use of FS in TildeExpressionResolver" The whole point of this change was making it possible to resolve paths without depending on the FileSystem, which is not what I did here. Not sure what I was thinking... llvm-svn: 346466 --- lldb/include/lldb/Host/FileSystem.h | 3 +-- .../lldb/Utility/TildeExpressionResolver.h | 10 +--------- lldb/source/Commands/CommandCompletions.cpp | 2 +- lldb/source/Host/common/FileSystem.cpp | 9 ++++----- lldb/source/Target/TargetList.cpp | 4 ++-- lldb/source/Utility/TildeExpressionResolver.cpp | 4 ++-- lldb/unittests/Host/FileSystemTest.cpp | 4 ++-- lldb/unittests/Interpreter/TestCompletion.cpp | 16 ++++------------ .../MockTildeExpressionResolver.cpp | 5 ++--- .../TestingSupport/MockTildeExpressionResolver.h | 3 +-- .../Utility/TildeExpressionResolverTest.cpp | 4 +--- 11 files changed, 21 insertions(+), 43 deletions(-) diff --git a/lldb/include/lldb/Host/FileSystem.h b/lldb/include/lldb/Host/FileSystem.h index c92454bd3ee3..730cbd2a4211 100644 --- a/lldb/include/lldb/Host/FileSystem.h +++ b/lldb/include/lldb/Host/FileSystem.h @@ -132,8 +132,7 @@ public: void *callback_baton); std::error_code GetRealPath(const llvm::Twine &path, - llvm::SmallVectorImpl &output, - bool expand_tilde) const; + llvm::SmallVectorImpl &output) const; private: static llvm::Optional &InstanceImpl(); diff --git a/lldb/include/lldb/Utility/TildeExpressionResolver.h b/lldb/include/lldb/Utility/TildeExpressionResolver.h index 6ac8da237492..ae6b4073f6aa 100644 --- a/lldb/include/lldb/Utility/TildeExpressionResolver.h +++ b/lldb/include/lldb/Utility/TildeExpressionResolver.h @@ -18,10 +18,8 @@ template class SmallVectorImpl; } namespace lldb_private { -class FileSystem; class TildeExpressionResolver { public: - TildeExpressionResolver(FileSystem &fs) : m_fs(fs) {} virtual ~TildeExpressionResolver(); /// Resolve a Tilde Expression contained according to bash rules. @@ -54,20 +52,14 @@ public: /// the username portion with the matched result. bool ResolveFullPath(llvm::StringRef Expr, llvm::SmallVectorImpl &Output); - -protected: - FileSystem &m_fs; }; class StandardTildeExpressionResolver : public TildeExpressionResolver { public: - StandardTildeExpressionResolver(FileSystem &fs) - : TildeExpressionResolver(fs) {} - bool ResolveExact(llvm::StringRef Expr, llvm::SmallVectorImpl &Output) override; bool ResolvePartial(llvm::StringRef Expr, llvm::StringSet<> &Output) override; }; -} // namespace lldb_private +} #endif // #ifndef LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H diff --git a/lldb/source/Commands/CommandCompletions.cpp b/lldb/source/Commands/CommandCompletions.cpp index 2f5697210255..af699a543d48 100644 --- a/lldb/source/Commands/CommandCompletions.cpp +++ b/lldb/source/Commands/CommandCompletions.cpp @@ -231,7 +231,7 @@ static int DiskFilesOrDirectories(const llvm::Twine &partial_name, static int DiskFilesOrDirectories(CompletionRequest &request, bool only_directories) { request.SetWordComplete(false); - StandardTildeExpressionResolver resolver(FileSystem::Instance()); + StandardTildeExpressionResolver resolver; StringList matches; DiskFilesOrDirectories(request.GetCursorArgumentPrefix(), only_directories, matches, resolver); diff --git a/lldb/source/Host/common/FileSystem.cpp b/lldb/source/Host/common/FileSystem.cpp index c1f98c1ad65d..a9ed5bd1847c 100644 --- a/lldb/source/Host/common/FileSystem.cpp +++ b/lldb/source/Host/common/FileSystem.cpp @@ -183,9 +183,8 @@ std::error_code FileSystem::MakeAbsolute(FileSpec &file_spec) const { } std::error_code FileSystem::GetRealPath(const Twine &path, - SmallVectorImpl &output, - bool expand_tilde) const { - return m_fs->getRealPath(path, output, expand_tilde); + SmallVectorImpl &output) const { + return m_fs->getRealPath(path, output); } void FileSystem::Resolve(SmallVectorImpl &path) { @@ -194,8 +193,8 @@ void FileSystem::Resolve(SmallVectorImpl &path) { // Resolve tilde. SmallString<128> original_path(path.begin(), path.end()); - StandardTildeExpressionResolver resolver(*this); - resolver.ResolveFullPath(original_path, path); + StandardTildeExpressionResolver Resolver; + Resolver.ResolveFullPath(original_path, path); // Try making the path absolute if it exists. SmallString<128> absolute_path(path.begin(), path.end()); diff --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp index b0653dd02e73..5720777af37e 100644 --- a/lldb/source/Target/TargetList.cpp +++ b/lldb/source/Target/TargetList.cpp @@ -351,8 +351,8 @@ Status TargetList::CreateTargetInternal(Debugger &debugger, // we want to expand the tilde but we don't want to resolve any symbolic // links so we can't use the FileSpec constructor's resolve flag llvm::SmallString<64> unglobbed_path; - StandardTildeExpressionResolver resolver(FileSystem::Instance()); - resolver.ResolveFullPath(user_exe_path, unglobbed_path); + StandardTildeExpressionResolver Resolver; + Resolver.ResolveFullPath(user_exe_path, unglobbed_path); if (unglobbed_path.empty()) file = FileSpec(user_exe_path); diff --git a/lldb/source/Utility/TildeExpressionResolver.cpp b/lldb/source/Utility/TildeExpressionResolver.cpp index 8f3d04f90f01..ae947059d8b9 100644 --- a/lldb/source/Utility/TildeExpressionResolver.cpp +++ b/lldb/source/Utility/TildeExpressionResolver.cpp @@ -8,13 +8,13 @@ //===----------------------------------------------------------------------===// #include "lldb/Utility/TildeExpressionResolver.h" -#include "lldb/Host/FileSystem.h" #include // for assert #include // for error_code #include "llvm/ADT/STLExtras.h" // for any_of #include "llvm/ADT/SmallVector.h" // for SmallVectorImpl +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" // for fs @@ -37,7 +37,7 @@ bool StandardTildeExpressionResolver::ResolveExact( assert(!llvm::any_of(Expr, [](char c) { return path::is_separator(c); })); assert(Expr.empty() || Expr[0] == '~'); - return !m_fs.GetRealPath(Expr, Output, true); + return !fs::real_path(Expr, Output, true); } bool StandardTildeExpressionResolver::ResolvePartial(StringRef Expr, diff --git a/lldb/unittests/Host/FileSystemTest.cpp b/lldb/unittests/Host/FileSystemTest.cpp index c8972786ad46..76ac83fe18b6 100644 --- a/lldb/unittests/Host/FileSystemTest.cpp +++ b/lldb/unittests/Host/FileSystemTest.cpp @@ -69,8 +69,8 @@ public: return std::error_code(); } // Map any symlink to "/symlink". - std::error_code getRealPath(const Twine &Path, SmallVectorImpl &Output, - bool ExpandTilde) const override { + std::error_code getRealPath(const Twine &Path, + SmallVectorImpl &Output) const override { auto I = FilesAndDirs.find(Path.str()); if (I == FilesAndDirs.end()) return make_error_code(llvm::errc::no_such_file_or_directory); diff --git a/lldb/unittests/Interpreter/TestCompletion.cpp b/lldb/unittests/Interpreter/TestCompletion.cpp index b170179287a0..e781de04e027 100644 --- a/lldb/unittests/Interpreter/TestCompletion.cpp +++ b/lldb/unittests/Interpreter/TestCompletion.cpp @@ -7,11 +7,9 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Host/FileSystem.h" #include "lldb/Interpreter/CommandCompletions.h" #include "lldb/Utility/StringList.h" #include "lldb/Utility/TildeExpressionResolver.h" - #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -67,8 +65,6 @@ protected: SmallString<128> FileBaz; void SetUp() override { - FileSystem::Initialize(); - // chdir back into the original working dir this test binary started with. // A previous test may have have changed the working dir. ASSERT_NO_ERROR(fs::set_current_path(OriginalWorkingDir)); @@ -109,10 +105,7 @@ protected: ASSERT_NO_ERROR(fs::current_path(OriginalWorkingDir)); } - void TearDown() override { - ASSERT_NO_ERROR(fs::remove_directories(BaseDir)); - FileSystem::Terminate(); - } + void TearDown() override { ASSERT_NO_ERROR(fs::remove_directories(BaseDir)); } static bool HasEquivalentFile(const Twine &Path, const StringList &Paths) { for (size_t I = 0; I < Paths.GetSize(); ++I) { @@ -165,7 +158,7 @@ TEST_F(CompletionTest, DirCompletionAbsolute) { std::string Prefixes[] = {(Twine(BaseDir) + "/").str(), ""}; - StandardTildeExpressionResolver Resolver(FileSystem::Instance()); + StandardTildeExpressionResolver Resolver; StringList Results; // When a directory is specified that doesn't end in a slash, it searches @@ -204,7 +197,7 @@ TEST_F(CompletionTest, FileCompletionAbsolute) { // all check this by asserting an exact result count, and verifying against // known folders. - StandardTildeExpressionResolver Resolver(FileSystem::Instance()); + StandardTildeExpressionResolver Resolver; StringList Results; // When an item is specified that doesn't end in a slash but exactly matches // one item, it returns that item. @@ -255,8 +248,7 @@ TEST_F(CompletionTest, FileCompletionAbsolute) { } TEST_F(CompletionTest, DirCompletionUsername) { - MockTildeExpressionResolver Resolver(FileSystem::Instance(), "James", - BaseDir); + MockTildeExpressionResolver Resolver("James", BaseDir); Resolver.AddKnownUser("Kirk", DirFooB); Resolver.AddKnownUser("Lars", DirFooC); Resolver.AddKnownUser("Jason", DirFoo); diff --git a/lldb/unittests/TestingSupport/MockTildeExpressionResolver.cpp b/lldb/unittests/TestingSupport/MockTildeExpressionResolver.cpp index 20790180624a..832836682b50 100644 --- a/lldb/unittests/TestingSupport/MockTildeExpressionResolver.cpp +++ b/lldb/unittests/TestingSupport/MockTildeExpressionResolver.cpp @@ -13,10 +13,9 @@ using namespace lldb_private; using namespace llvm; -MockTildeExpressionResolver::MockTildeExpressionResolver(FileSystem &fs, - StringRef CurrentUser, +MockTildeExpressionResolver::MockTildeExpressionResolver(StringRef CurrentUser, StringRef HomeDir) - : TildeExpressionResolver(fs), CurrentUser(CurrentUser) { + : CurrentUser(CurrentUser) { UserDirectories.insert(std::make_pair(CurrentUser, HomeDir)); } diff --git a/lldb/unittests/TestingSupport/MockTildeExpressionResolver.h b/lldb/unittests/TestingSupport/MockTildeExpressionResolver.h index 45a3796fdb8c..18be1102e1fd 100644 --- a/lldb/unittests/TestingSupport/MockTildeExpressionResolver.h +++ b/lldb/unittests/TestingSupport/MockTildeExpressionResolver.h @@ -16,13 +16,12 @@ #include "llvm/ADT/StringMap.h" namespace lldb_private { -class FileSystem; class MockTildeExpressionResolver : public TildeExpressionResolver { llvm::StringRef CurrentUser; llvm::StringMap UserDirectories; public: - MockTildeExpressionResolver(FileSystem &fs, llvm::StringRef CurrentUser, + MockTildeExpressionResolver(llvm::StringRef CurrentUser, llvm::StringRef HomeDir); void AddKnownUser(llvm::StringRef User, llvm::StringRef HomeDir); diff --git a/lldb/unittests/Utility/TildeExpressionResolverTest.cpp b/lldb/unittests/Utility/TildeExpressionResolverTest.cpp index eb4812619c38..bc1ca7a44811 100644 --- a/lldb/unittests/Utility/TildeExpressionResolverTest.cpp +++ b/lldb/unittests/Utility/TildeExpressionResolverTest.cpp @@ -1,7 +1,6 @@ #include "gtest/gtest.h" #include "TestingSupport/MockTildeExpressionResolver.h" -#include "lldb/Host/FileSystem.h" #include "lldb/Utility/TildeExpressionResolver.h" #include "llvm/ADT/SmallString.h" @@ -10,8 +9,7 @@ using namespace llvm; using namespace lldb_private; TEST(TildeExpressionResolver, ResolveFullPath) { - FileSystem fs; - MockTildeExpressionResolver Resolver(fs, "James", "/james"); + MockTildeExpressionResolver Resolver("James", "/james"); Resolver.AddKnownUser("Kirk", "/kirk"); Resolver.AddKnownUser("Lars", "/lars"); Resolver.AddKnownUser("Jason", "/jason"); -- 2.34.1