[Lldb-commits] [lldb] r346457 - [FileSystem] Make use of FS in TildeExpressionResolver
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Thu Nov 8 16:50:51 PST 2018
Author: jdevlieghere
Date: Thu Nov 8 16:50:50 2018
New Revision: 346457
URL: http://llvm.org/viewvc/llvm-project?rev=346457&view=rev
Log:
[FileSystem] Make use of FS in TildeExpressionResolver
In order to call real_path from the TildeExpressionResolver we need
access to the FileSystem. Since the resolver lives under utility we have
to pass in the FS.
Modified:
lldb/trunk/include/lldb/Host/FileSystem.h
lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h
lldb/trunk/source/Commands/CommandCompletions.cpp
lldb/trunk/source/Host/common/FileSystem.cpp
lldb/trunk/source/Target/TargetList.cpp
lldb/trunk/source/Utility/TildeExpressionResolver.cpp
lldb/trunk/unittests/Host/FileSystemTest.cpp
lldb/trunk/unittests/Interpreter/TestCompletion.cpp
lldb/trunk/unittests/TestingSupport/MockTildeExpressionResolver.cpp
lldb/trunk/unittests/TestingSupport/MockTildeExpressionResolver.h
lldb/trunk/unittests/Utility/TildeExpressionResolverTest.cpp
Modified: lldb/trunk/include/lldb/Host/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSystem.h?rev=346457&r1=346456&r2=346457&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/FileSystem.h (original)
+++ lldb/trunk/include/lldb/Host/FileSystem.h Thu Nov 8 16:50:50 2018
@@ -132,7 +132,8 @@ public:
void *callback_baton);
std::error_code GetRealPath(const llvm::Twine &path,
- llvm::SmallVectorImpl<char> &output) const;
+ llvm::SmallVectorImpl<char> &output,
+ bool expand_tilde) const;
private:
static llvm::Optional<FileSystem> &InstanceImpl();
Modified: lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h?rev=346457&r1=346456&r2=346457&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h (original)
+++ lldb/trunk/include/lldb/Utility/TildeExpressionResolver.h Thu Nov 8 16:50:50 2018
@@ -18,8 +18,10 @@ template <typename T> class SmallVectorI
}
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.
@@ -52,14 +54,20 @@ public:
/// the username portion with the matched result.
bool ResolveFullPath(llvm::StringRef Expr,
llvm::SmallVectorImpl<char> &Output);
+
+protected:
+ FileSystem &m_fs;
};
class StandardTildeExpressionResolver : public TildeExpressionResolver {
public:
+ StandardTildeExpressionResolver(FileSystem &fs)
+ : TildeExpressionResolver(fs) {}
+
bool ResolveExact(llvm::StringRef Expr,
llvm::SmallVectorImpl<char> &Output) override;
bool ResolvePartial(llvm::StringRef Expr, llvm::StringSet<> &Output) override;
};
-}
+} // namespace lldb_private
#endif // #ifndef LLDB_UTILITY_TILDE_EXPRESSION_RESOLVER_H
Modified: lldb/trunk/source/Commands/CommandCompletions.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandCompletions.cpp?rev=346457&r1=346456&r2=346457&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandCompletions.cpp (original)
+++ lldb/trunk/source/Commands/CommandCompletions.cpp Thu Nov 8 16:50:50 2018
@@ -231,7 +231,7 @@ static int DiskFilesOrDirectories(const
static int DiskFilesOrDirectories(CompletionRequest &request,
bool only_directories) {
request.SetWordComplete(false);
- StandardTildeExpressionResolver resolver;
+ StandardTildeExpressionResolver resolver(FileSystem::Instance());
StringList matches;
DiskFilesOrDirectories(request.GetCursorArgumentPrefix(), only_directories,
matches, resolver);
Modified: lldb/trunk/source/Host/common/FileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSystem.cpp?rev=346457&r1=346456&r2=346457&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/FileSystem.cpp (original)
+++ lldb/trunk/source/Host/common/FileSystem.cpp Thu Nov 8 16:50:50 2018
@@ -183,8 +183,9 @@ std::error_code FileSystem::MakeAbsolute
}
std::error_code FileSystem::GetRealPath(const Twine &path,
- SmallVectorImpl<char> &output) const {
- return m_fs->getRealPath(path, output);
+ SmallVectorImpl<char> &output,
+ bool expand_tilde) const {
+ return m_fs->getRealPath(path, output, expand_tilde);
}
void FileSystem::Resolve(SmallVectorImpl<char> &path) {
@@ -193,8 +194,8 @@ void FileSystem::Resolve(SmallVectorImpl
// Resolve tilde.
SmallString<128> original_path(path.begin(), path.end());
- StandardTildeExpressionResolver Resolver;
- Resolver.ResolveFullPath(original_path, path);
+ StandardTildeExpressionResolver resolver(*this);
+ resolver.ResolveFullPath(original_path, path);
// Try making the path absolute if it exists.
SmallString<128> absolute_path(path.begin(), path.end());
Modified: lldb/trunk/source/Target/TargetList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/TargetList.cpp?rev=346457&r1=346456&r2=346457&view=diff
==============================================================================
--- lldb/trunk/source/Target/TargetList.cpp (original)
+++ lldb/trunk/source/Target/TargetList.cpp Thu Nov 8 16:50:50 2018
@@ -351,8 +351,8 @@ Status TargetList::CreateTargetInternal(
// 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;
- Resolver.ResolveFullPath(user_exe_path, unglobbed_path);
+ StandardTildeExpressionResolver resolver(FileSystem::Instance());
+ resolver.ResolveFullPath(user_exe_path, unglobbed_path);
if (unglobbed_path.empty())
file = FileSpec(user_exe_path);
Modified: lldb/trunk/source/Utility/TildeExpressionResolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/TildeExpressionResolver.cpp?rev=346457&r1=346456&r2=346457&view=diff
==============================================================================
--- lldb/trunk/source/Utility/TildeExpressionResolver.cpp (original)
+++ lldb/trunk/source/Utility/TildeExpressionResolver.cpp Thu Nov 8 16:50:50 2018
@@ -8,13 +8,13 @@
//===----------------------------------------------------------------------===//
#include "lldb/Utility/TildeExpressionResolver.h"
+#include "lldb/Host/FileSystem.h"
#include <assert.h> // for assert
#include <system_error> // 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::Re
assert(!llvm::any_of(Expr, [](char c) { return path::is_separator(c); }));
assert(Expr.empty() || Expr[0] == '~');
- return !fs::real_path(Expr, Output, true);
+ return !m_fs.GetRealPath(Expr, Output, true);
}
bool StandardTildeExpressionResolver::ResolvePartial(StringRef Expr,
Modified: lldb/trunk/unittests/Host/FileSystemTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Host/FileSystemTest.cpp?rev=346457&r1=346456&r2=346457&view=diff
==============================================================================
--- lldb/trunk/unittests/Host/FileSystemTest.cpp (original)
+++ lldb/trunk/unittests/Host/FileSystemTest.cpp Thu Nov 8 16:50:50 2018
@@ -69,8 +69,8 @@ public:
return std::error_code();
}
// Map any symlink to "/symlink".
- std::error_code getRealPath(const Twine &Path,
- SmallVectorImpl<char> &Output) const override {
+ std::error_code getRealPath(const Twine &Path, SmallVectorImpl<char> &Output,
+ bool ExpandTilde) const override {
auto I = FilesAndDirs.find(Path.str());
if (I == FilesAndDirs.end())
return make_error_code(llvm::errc::no_such_file_or_directory);
Modified: lldb/trunk/unittests/Interpreter/TestCompletion.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Interpreter/TestCompletion.cpp?rev=346457&r1=346456&r2=346457&view=diff
==============================================================================
--- lldb/trunk/unittests/Interpreter/TestCompletion.cpp (original)
+++ lldb/trunk/unittests/Interpreter/TestCompletion.cpp Thu Nov 8 16:50:50 2018
@@ -7,9 +7,11 @@
//
//===----------------------------------------------------------------------===//
+#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"
@@ -65,6 +67,8 @@ 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));
@@ -105,7 +109,10 @@ protected:
ASSERT_NO_ERROR(fs::current_path(OriginalWorkingDir));
}
- void TearDown() override { ASSERT_NO_ERROR(fs::remove_directories(BaseDir)); }
+ void TearDown() override {
+ ASSERT_NO_ERROR(fs::remove_directories(BaseDir));
+ FileSystem::Terminate();
+ }
static bool HasEquivalentFile(const Twine &Path, const StringList &Paths) {
for (size_t I = 0; I < Paths.GetSize(); ++I) {
@@ -158,7 +165,7 @@ TEST_F(CompletionTest, DirCompletionAbso
std::string Prefixes[] = {(Twine(BaseDir) + "/").str(), ""};
- StandardTildeExpressionResolver Resolver;
+ StandardTildeExpressionResolver Resolver(FileSystem::Instance());
StringList Results;
// When a directory is specified that doesn't end in a slash, it searches
@@ -197,7 +204,7 @@ TEST_F(CompletionTest, FileCompletionAbs
// all check this by asserting an exact result count, and verifying against
// known folders.
- StandardTildeExpressionResolver Resolver;
+ StandardTildeExpressionResolver Resolver(FileSystem::Instance());
StringList Results;
// When an item is specified that doesn't end in a slash but exactly matches
// one item, it returns that item.
@@ -248,7 +255,8 @@ TEST_F(CompletionTest, FileCompletionAbs
}
TEST_F(CompletionTest, DirCompletionUsername) {
- MockTildeExpressionResolver Resolver("James", BaseDir);
+ MockTildeExpressionResolver Resolver(FileSystem::Instance(), "James",
+ BaseDir);
Resolver.AddKnownUser("Kirk", DirFooB);
Resolver.AddKnownUser("Lars", DirFooC);
Resolver.AddKnownUser("Jason", DirFoo);
Modified: lldb/trunk/unittests/TestingSupport/MockTildeExpressionResolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/TestingSupport/MockTildeExpressionResolver.cpp?rev=346457&r1=346456&r2=346457&view=diff
==============================================================================
--- lldb/trunk/unittests/TestingSupport/MockTildeExpressionResolver.cpp (original)
+++ lldb/trunk/unittests/TestingSupport/MockTildeExpressionResolver.cpp Thu Nov 8 16:50:50 2018
@@ -13,9 +13,10 @@
using namespace lldb_private;
using namespace llvm;
-MockTildeExpressionResolver::MockTildeExpressionResolver(StringRef CurrentUser,
+MockTildeExpressionResolver::MockTildeExpressionResolver(FileSystem &fs,
+ StringRef CurrentUser,
StringRef HomeDir)
- : CurrentUser(CurrentUser) {
+ : TildeExpressionResolver(fs), CurrentUser(CurrentUser) {
UserDirectories.insert(std::make_pair(CurrentUser, HomeDir));
}
Modified: lldb/trunk/unittests/TestingSupport/MockTildeExpressionResolver.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/TestingSupport/MockTildeExpressionResolver.h?rev=346457&r1=346456&r2=346457&view=diff
==============================================================================
--- lldb/trunk/unittests/TestingSupport/MockTildeExpressionResolver.h (original)
+++ lldb/trunk/unittests/TestingSupport/MockTildeExpressionResolver.h Thu Nov 8 16:50:50 2018
@@ -16,12 +16,13 @@
#include "llvm/ADT/StringMap.h"
namespace lldb_private {
+class FileSystem;
class MockTildeExpressionResolver : public TildeExpressionResolver {
llvm::StringRef CurrentUser;
llvm::StringMap<llvm::StringRef> UserDirectories;
public:
- MockTildeExpressionResolver(llvm::StringRef CurrentUser,
+ MockTildeExpressionResolver(FileSystem &fs, llvm::StringRef CurrentUser,
llvm::StringRef HomeDir);
void AddKnownUser(llvm::StringRef User, llvm::StringRef HomeDir);
Modified: lldb/trunk/unittests/Utility/TildeExpressionResolverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/TildeExpressionResolverTest.cpp?rev=346457&r1=346456&r2=346457&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/TildeExpressionResolverTest.cpp (original)
+++ lldb/trunk/unittests/Utility/TildeExpressionResolverTest.cpp Thu Nov 8 16:50:50 2018
@@ -1,6 +1,7 @@
#include "gtest/gtest.h"
#include "TestingSupport/MockTildeExpressionResolver.h"
+#include "lldb/Host/FileSystem.h"
#include "lldb/Utility/TildeExpressionResolver.h"
#include "llvm/ADT/SmallString.h"
@@ -9,7 +10,8 @@ using namespace llvm;
using namespace lldb_private;
TEST(TildeExpressionResolver, ResolveFullPath) {
- MockTildeExpressionResolver Resolver("James", "/james");
+ FileSystem fs;
+ MockTildeExpressionResolver Resolver(fs, "James", "/james");
Resolver.AddKnownUser("Kirk", "/kirk");
Resolver.AddKnownUser("Lars", "/lars");
Resolver.AddKnownUser("Jason", "/jason");
More information about the lldb-commits
mailing list