Skip to content

[lldb] Provide GetHomeDirectory wrapper in Host::FileSystem (NFC) #1740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -207,7 +207,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
2 changes: 1 addition & 1 deletion lldb/source/Interpreter/CommandInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,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 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