forked from OSchip/llvm-project
[FileSystem] Remove ResolveExecutableLocation() from FileSpec
This patch removes the ResolveExecutableLocation method from FileSpec and updates its uses with calls to the FileSystem. Differential revision: https://reviews.llvm.org/D53834 llvm-svn: 345853
This commit is contained in:
parent
73bb119940
commit
2c22c800a0
|
@ -92,6 +92,9 @@ public:
|
|||
void Resolve(FileSpec &file_spec);
|
||||
/// @}
|
||||
|
||||
/// Call into the Host to see if it can help find the file.
|
||||
bool ResolveExecutableLocation(FileSpec &file_spec);
|
||||
|
||||
enum EnumerateDirectoryResult {
|
||||
/// Enumerate next entry in the current directory.
|
||||
eEnumerateDirectoryResultNext,
|
||||
|
|
|
@ -280,21 +280,6 @@ public:
|
|||
//------------------------------------------------------------------
|
||||
bool Exists() const;
|
||||
|
||||
//------------------------------------------------------------------
|
||||
/// Expanded existence test.
|
||||
///
|
||||
/// Call into the Host to see if it can help find the file (e.g. by
|
||||
/// searching paths set in the environment, etc.).
|
||||
///
|
||||
/// If found, sets the value of m_directory to the directory where the file
|
||||
/// was found.
|
||||
///
|
||||
/// @return
|
||||
/// \b true if was able to find the file using expanded search
|
||||
/// methods, \b false otherwise.
|
||||
//------------------------------------------------------------------
|
||||
bool ResolveExecutableLocation();
|
||||
|
||||
//------------------------------------------------------------------
|
||||
/// Canonicalize this file path (basically running the static
|
||||
/// FileSpec::Resolve method on it). Useful if you asked us not to resolve
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include "lldb/API/SBFileSpec.h"
|
||||
#include "lldb/API/SBStream.h"
|
||||
#include "lldb/Host/FileSystem.h"
|
||||
#include "lldb/Host/PosixApi.h"
|
||||
#include "lldb/Utility/FileSpec.h"
|
||||
#include "lldb/Utility/Log.h"
|
||||
|
@ -61,7 +62,7 @@ bool SBFileSpec::Exists() const {
|
|||
}
|
||||
|
||||
bool SBFileSpec::ResolveExecutableLocation() {
|
||||
return m_opaque_ap->ResolveExecutableLocation();
|
||||
return FileSystem::Instance().ResolveExecutableLocation(*m_opaque_ap);
|
||||
}
|
||||
|
||||
int SBFileSpec::ResolvePath(const char *src_path, char *dst_path,
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#include "lldb/Utility/TildeExpressionResolver.h"
|
||||
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/Program.h"
|
||||
#include "llvm/Support/Threading.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -178,3 +180,36 @@ void FileSystem::Resolve(FileSpec &file_spec) {
|
|||
// Update the FileSpec with the resolved path.
|
||||
file_spec.SetPath(path);
|
||||
}
|
||||
|
||||
bool FileSystem::ResolveExecutableLocation(FileSpec &file_spec) {
|
||||
// If the directory is set there's nothing to do.
|
||||
const ConstString &directory = file_spec.GetDirectory();
|
||||
if (directory)
|
||||
return false;
|
||||
|
||||
// We cannot look for a file if there's no file name.
|
||||
const ConstString &filename = file_spec.GetFilename();
|
||||
if (!filename)
|
||||
return false;
|
||||
|
||||
// Search for the file on the host.
|
||||
const std::string filename_str(filename.GetCString());
|
||||
llvm::ErrorOr<std::string> error_or_path =
|
||||
llvm::sys::findProgramByName(filename_str);
|
||||
if (!error_or_path)
|
||||
return false;
|
||||
|
||||
// findProgramByName returns "." if it can't find the file.
|
||||
llvm::StringRef path = *error_or_path;
|
||||
llvm::StringRef parent = llvm::sys::path::parent_path(path);
|
||||
if (parent.empty() || parent == ".")
|
||||
return false;
|
||||
|
||||
// Make sure that the result exists.
|
||||
FileSpec result(*error_or_path, false);
|
||||
if (!Exists(result))
|
||||
return false;
|
||||
|
||||
file_spec = result;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "lldb/Host/MonitoringProcessLauncher.h"
|
||||
#include "lldb/Host/FileSystem.h"
|
||||
#include "lldb/Host/HostProcess.h"
|
||||
#include "lldb/Target/ProcessLaunchInfo.h"
|
||||
#include "lldb/Utility/Log.h"
|
||||
|
@ -38,7 +39,7 @@ MonitoringProcessLauncher::LaunchProcess(const ProcessLaunchInfo &launch_info,
|
|||
status(exe_spec.GetPath(), stats);
|
||||
}
|
||||
if (!exists(stats)) {
|
||||
exe_spec.ResolveExecutableLocation();
|
||||
FileSystem::Instance().ResolveExecutableLocation(exe_spec);
|
||||
status(exe_spec.GetPath(), stats);
|
||||
}
|
||||
|
||||
|
|
|
@ -55,10 +55,11 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "lldb/Host/ConnectionFileDescriptor.h"
|
||||
#include "lldb/Host/FileSystem.h"
|
||||
#include "lldb/Host/HostInfo.h"
|
||||
#include "lldb/Host/ThreadLauncher.h"
|
||||
#include "lldb/Target/ProcessLaunchInfo.h"
|
||||
#include "lldb/Target/Process.h"
|
||||
#include "lldb/Target/ProcessLaunchInfo.h"
|
||||
#include "lldb/Utility/ArchSpec.h"
|
||||
#include "lldb/Utility/CleanUp.h"
|
||||
#include "lldb/Utility/DataBufferHeap.h"
|
||||
|
@ -1282,7 +1283,7 @@ Status Host::LaunchProcess(ProcessLaunchInfo &launch_info) {
|
|||
status(exe_spec.GetPath(), stats);
|
||||
}
|
||||
if (!exists(stats)) {
|
||||
exe_spec.ResolveExecutableLocation();
|
||||
FileSystem::Instance().ResolveExecutableLocation(exe_spec);
|
||||
status(exe_spec.GetPath(), stats);
|
||||
}
|
||||
if (!exists(stats)) {
|
||||
|
|
|
@ -135,7 +135,8 @@ PlatformPOSIX::ResolveExecutable(const ModuleSpec &module_spec,
|
|||
}
|
||||
|
||||
if (!resolved_module_spec.GetFileSpec().Exists())
|
||||
resolved_module_spec.GetFileSpec().ResolveExecutableLocation();
|
||||
FileSystem::Instance().ResolveExecutableLocation(
|
||||
resolved_module_spec.GetFileSpec());
|
||||
|
||||
// Resolve any executable within a bundle on MacOSX
|
||||
Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
|
||||
|
|
|
@ -199,7 +199,8 @@ Status PlatformWindows::ResolveExecutable(
|
|||
}
|
||||
|
||||
if (!resolved_module_spec.GetFileSpec().Exists())
|
||||
resolved_module_spec.GetFileSpec().ResolveExecutableLocation();
|
||||
FileSystem::Instance().ResolveExecutableLocation(
|
||||
resolved_module_spec.GetFileSpec());
|
||||
|
||||
if (resolved_module_spec.GetFileSpec().Exists())
|
||||
error.Clear();
|
||||
|
|
|
@ -151,7 +151,7 @@ const FileSpec &ProcessLaunchInfo::GetShell() const { return m_shell; }
|
|||
void ProcessLaunchInfo::SetShell(const FileSpec &shell) {
|
||||
m_shell = shell;
|
||||
if (m_shell) {
|
||||
m_shell.ResolveExecutableLocation();
|
||||
FileSystem::Instance().ResolveExecutableLocation(m_shell);
|
||||
m_flags.Set(lldb::eLaunchFlagLaunchInShell);
|
||||
} else
|
||||
m_flags.Clear(lldb::eLaunchFlagLaunchInShell);
|
||||
|
|
|
@ -458,42 +458,6 @@ void FileSpec::Dump(Stream *s) const {
|
|||
//------------------------------------------------------------------
|
||||
bool FileSpec::Exists() const { return llvm::sys::fs::exists(GetPath()); }
|
||||
|
||||
bool FileSpec::ResolveExecutableLocation() {
|
||||
// CLEANUP: Use StringRef for string handling.
|
||||
if (!m_directory) {
|
||||
const char *file_cstr = m_filename.GetCString();
|
||||
if (file_cstr) {
|
||||
const std::string file_str(file_cstr);
|
||||
llvm::ErrorOr<std::string> error_or_path =
|
||||
llvm::sys::findProgramByName(file_str);
|
||||
if (!error_or_path)
|
||||
return false;
|
||||
std::string path = error_or_path.get();
|
||||
llvm::StringRef dir_ref = llvm::sys::path::parent_path(path);
|
||||
if (!dir_ref.empty()) {
|
||||
// FindProgramByName returns "." if it can't find the file.
|
||||
if (strcmp(".", dir_ref.data()) == 0)
|
||||
return false;
|
||||
|
||||
m_directory.SetCString(dir_ref.data());
|
||||
if (Exists())
|
||||
return true;
|
||||
else {
|
||||
// If FindProgramByName found the file, it returns the directory +
|
||||
// filename in its return results. We need to separate them.
|
||||
FileSpec tmp_file(dir_ref.data(), false);
|
||||
if (tmp_file.Exists()) {
|
||||
m_directory = tmp_file.m_directory;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FileSpec::ResolvePath() {
|
||||
if (m_is_resolved)
|
||||
return true; // We have already resolved this path
|
||||
|
|
Loading…
Reference in New Issue