[Lldb-commits] [lldb] 921c1b7 - [lldb] Provide GetHomeDirectory wrapper in Host::FileSystem (NFC)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Thu Aug 20 14:07:12 PDT 2020
Author: Jonas Devlieghere
Date: 2020-08-20T14:07:05-07:00
New Revision: 921c1b7df37d6f5353ed5fdffa117dcda0c941ba
URL: https://github.com/llvm/llvm-project/commit/921c1b7df37d6f5353ed5fdffa117dcda0c941ba
DIFF: https://github.com/llvm/llvm-project/commit/921c1b7df37d6f5353ed5fdffa117dcda0c941ba.diff
LOG: [lldb] Provide GetHomeDirectory wrapper in Host::FileSystem (NFC)
Provider a wrapper around llvm::sys::path::home_directory in the
FileSystem class. This will make it possible for the reproducers to
intercept the call in a central place.
Added:
Modified:
lldb/include/lldb/Host/FileSystem.h
lldb/source/API/SBHostOS.cpp
lldb/source/Host/common/Editline.cpp
lldb/source/Host/common/FileSystem.cpp
lldb/source/Interpreter/CommandInterpreter.cpp
lldb/source/Target/Platform.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Host/FileSystem.h b/lldb/include/lldb/Host/FileSystem.h
index 697e799387b8..aff752699923 100644
--- a/lldb/include/lldb/Host/FileSystem.h
+++ b/lldb/include/lldb/Host/FileSystem.h
@@ -154,6 +154,10 @@ class FileSystem {
/// Call into the Host to see if it can help find the file.
bool ResolveExecutableLocation(FileSpec &file_spec);
+ /// Get the user home directory.
+ bool GetHomeDirectory(llvm::SmallVectorImpl<char> &path) const;
+ bool GetHomeDirectory(FileSpec &file_spec) const;
+
enum EnumerateDirectoryResult {
/// Enumerate next entry in the current directory.
eEnumerateDirectoryResultNext,
diff --git a/lldb/source/API/SBHostOS.cpp b/lldb/source/API/SBHostOS.cpp
index 9d3d119e4c2a..deca4ac81a1a 100644
--- a/lldb/source/API/SBHostOS.cpp
+++ b/lldb/source/API/SBHostOS.cpp
@@ -91,14 +91,13 @@ SBFileSpec SBHostOS::GetUserHomeDirectory() {
LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBFileSpec, SBHostOS,
GetUserHomeDirectory);
- SBFileSpec sb_fspec;
-
- llvm::SmallString<64> home_dir_path;
- llvm::sys::path::home_directory(home_dir_path);
- FileSpec homedir(home_dir_path.c_str());
+ FileSpec homedir;
+ FileSystem::Instance().GetHomeDirectory(homedir);
FileSystem::Instance().Resolve(homedir);
+ SBFileSpec sb_fspec;
sb_fspec.SetFileSpec(homedir);
+
return LLDB_RECORD_RESULT(sb_fspec);
}
diff --git a/lldb/source/Host/common/Editline.cpp b/lldb/source/Host/common/Editline.cpp
index fc535d79b978..026a05da45b2 100644
--- a/lldb/source/Host/common/Editline.cpp
+++ b/lldb/source/Host/common/Editline.cpp
@@ -210,7 +210,7 @@ class EditlineHistory {
// Compute the history path lazily.
if (m_path.empty() && m_history && !m_prefix.empty()) {
llvm::SmallString<128> lldb_history_file;
- llvm::sys::path::home_directory(lldb_history_file);
+ FileSystem::Instance().GetHomeDirectory(lldb_history_file);
llvm::sys::path::append(lldb_history_file, ".lldb");
// LLDB stores its history in ~/.lldb/. If for some reason this directory
diff --git a/lldb/source/Host/common/FileSystem.cpp b/lldb/source/Host/common/FileSystem.cpp
index 0fa27d131e1a..d295c01e6967 100644
--- a/lldb/source/Host/common/FileSystem.cpp
+++ b/lldb/source/Host/common/FileSystem.cpp
@@ -360,6 +360,18 @@ bool FileSystem::ResolveExecutableLocation(FileSpec &file_spec) {
return true;
}
+bool FileSystem::GetHomeDirectory(SmallVectorImpl<char> &path) const {
+ return llvm::sys::path::home_directory(path);
+}
+
+bool FileSystem::GetHomeDirectory(FileSpec &file_spec) const {
+ SmallString<128> home_dir;
+ if (!GetHomeDirectory(home_dir))
+ return false;
+ file_spec.SetPath(home_dir);
+ return true;
+}
+
static int OpenWithFS(const FileSystem &fs, const char *path, int flags,
int mode) {
return const_cast<FileSystem &>(fs).Open(path, flags, mode);
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 6a355cb12e8c..b3b0277ec667 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -2084,7 +2084,7 @@ static void GetHomeInitFile(llvm::SmallVectorImpl<char> &init_file,
init_file_name.append(suffix.str());
}
- llvm::sys::path::home_directory(init_file);
+ FileSystem::Instance().GetHomeDirectory(init_file);
llvm::sys::path::append(init_file, init_file_name);
FileSystem::Instance().Resolve(init_file);
@@ -2100,7 +2100,7 @@ static void GetHomeREPLInitFile(llvm::SmallVectorImpl<char> &init_file,
return;
}
- llvm::sys::path::home_directory(init_file);
+ FileSystem::Instance().GetHomeDirectory(init_file);
llvm::sys::path::append(init_file, init_file_name);
FileSystem::Instance().Resolve(init_file);
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index 16787141bee0..e867b8db4723 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -85,7 +85,7 @@ PlatformProperties::PlatformProperties() {
return;
llvm::SmallString<64> user_home_dir;
- if (!llvm::sys::path::home_directory(user_home_dir))
+ if (!FileSystem::Instance().GetHomeDirectory(user_home_dir))
return;
module_cache_dir = FileSpec(user_home_dir.c_str());
More information about the lldb-commits
mailing list