Skip to content

Commit 29af015

Browse files
authored
Merge pull request #1740 from Teemperor/cherry/921c1b7df37d6f5353ed5fdffa117dcda0c941ba
[lldb] Provide GetHomeDirectory wrapper in Host::FileSystem (NFC)
2 parents 9a320ba + b96f908 commit 29af015

File tree

6 files changed

+23
-8
lines changed

6 files changed

+23
-8
lines changed

lldb/include/lldb/Host/FileSystem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ class FileSystem {
154154
/// Call into the Host to see if it can help find the file.
155155
bool ResolveExecutableLocation(FileSpec &file_spec);
156156

157+
/// Get the user home directory.
158+
bool GetHomeDirectory(llvm::SmallVectorImpl<char> &path) const;
159+
bool GetHomeDirectory(FileSpec &file_spec) const;
160+
157161
enum EnumerateDirectoryResult {
158162
/// Enumerate next entry in the current directory.
159163
eEnumerateDirectoryResultNext,

lldb/source/API/SBHostOS.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,13 @@ SBFileSpec SBHostOS::GetUserHomeDirectory() {
9191
LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBFileSpec, SBHostOS,
9292
GetUserHomeDirectory);
9393

94-
SBFileSpec sb_fspec;
95-
96-
llvm::SmallString<64> home_dir_path;
97-
llvm::sys::path::home_directory(home_dir_path);
98-
FileSpec homedir(home_dir_path.c_str());
94+
FileSpec homedir;
95+
FileSystem::Instance().GetHomeDirectory(homedir);
9996
FileSystem::Instance().Resolve(homedir);
10097

98+
SBFileSpec sb_fspec;
10199
sb_fspec.SetFileSpec(homedir);
100+
102101
return LLDB_RECORD_RESULT(sb_fspec);
103102
}
104103

lldb/source/Host/common/Editline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class EditlineHistory {
207207
// Compute the history path lazily.
208208
if (m_path.empty() && m_history && !m_prefix.empty()) {
209209
llvm::SmallString<128> lldb_history_file;
210-
llvm::sys::path::home_directory(lldb_history_file);
210+
FileSystem::Instance().GetHomeDirectory(lldb_history_file);
211211
llvm::sys::path::append(lldb_history_file, ".lldb");
212212

213213
// LLDB stores its history in ~/.lldb/. If for some reason this directory

lldb/source/Host/common/FileSystem.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,18 @@ bool FileSystem::ResolveExecutableLocation(FileSpec &file_spec) {
360360
return true;
361361
}
362362

363+
bool FileSystem::GetHomeDirectory(SmallVectorImpl<char> &path) const {
364+
return llvm::sys::path::home_directory(path);
365+
}
366+
367+
bool FileSystem::GetHomeDirectory(FileSpec &file_spec) const {
368+
SmallString<128> home_dir;
369+
if (!GetHomeDirectory(home_dir))
370+
return false;
371+
file_spec.SetPath(home_dir);
372+
return true;
373+
}
374+
363375
static int OpenWithFS(const FileSystem &fs, const char *path, int flags,
364376
int mode) {
365377
return const_cast<FileSystem &>(fs).Open(path, flags, mode);

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2083,7 +2083,7 @@ static void GetHomeInitFile(llvm::SmallVectorImpl<char> &init_file,
20832083
init_file_name.append(suffix.str());
20842084
}
20852085

2086-
llvm::sys::path::home_directory(init_file);
2086+
FileSystem::Instance().GetHomeDirectory(init_file);
20872087
llvm::sys::path::append(init_file, init_file_name);
20882088

20892089
FileSystem::Instance().Resolve(init_file);

lldb/source/Target/Platform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ PlatformProperties::PlatformProperties() {
8585
return;
8686

8787
llvm::SmallString<64> user_home_dir;
88-
if (!llvm::sys::path::home_directory(user_home_dir))
88+
if (!FileSystem::Instance().GetHomeDirectory(user_home_dir))
8989
return;
9090

9191
module_cache_dir = FileSpec(user_home_dir.c_str());

0 commit comments

Comments
 (0)