Skip to content

Commit

Permalink
[lldb] Provide GetHomeDirectory wrapper in Host::FileSystem (NFC)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JDevlieghere committed Aug 20, 2020
1 parent 74ca527 commit 921c1b7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
4 changes: 4 additions & 0 deletions lldb/include/lldb/Host/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions lldb/source/API/SBHostOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Host/common/Editline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions lldb/source/Host/common/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Interpreter/CommandInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Target/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 921c1b7

Please sign in to comment.