diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2018-11-01 17:09:22 +0000 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2018-11-01 17:09:22 +0000 |
commit | 2c22c800a0d049f6300dbf59b400aa1329c21971 (patch) | |
tree | ef96df15a0bd1b4469b4991df87ddd5e715a9179 | |
parent | 73bb11994064f5172bf454c3dae523b9661642a8 (diff) | |
download | bcm5719-llvm-2c22c800a0d049f6300dbf59b400aa1329c21971.tar.gz bcm5719-llvm-2c22c800a0d049f6300dbf59b400aa1329c21971.zip |
[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
-rw-r--r-- | lldb/include/lldb/Host/FileSystem.h | 3 | ||||
-rw-r--r-- | lldb/include/lldb/Utility/FileSpec.h | 15 | ||||
-rw-r--r-- | lldb/source/API/SBFileSpec.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Host/common/FileSystem.cpp | 35 | ||||
-rw-r--r-- | lldb/source/Host/common/MonitoringProcessLauncher.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Host/macosx/objcxx/Host.mm | 5 | ||||
-rw-r--r-- | lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Target/ProcessLaunchInfo.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Utility/FileSpec.cpp | 36 |
10 files changed, 50 insertions, 58 deletions
diff --git a/lldb/include/lldb/Host/FileSystem.h b/lldb/include/lldb/Host/FileSystem.h index 115d6d4b9cc..ea1fe08bb31 100644 --- a/lldb/include/lldb/Host/FileSystem.h +++ b/lldb/include/lldb/Host/FileSystem.h @@ -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, diff --git a/lldb/include/lldb/Utility/FileSpec.h b/lldb/include/lldb/Utility/FileSpec.h index a51ebf89a4e..53c5b4ba35a 100644 --- a/lldb/include/lldb/Utility/FileSpec.h +++ b/lldb/include/lldb/Utility/FileSpec.h @@ -281,21 +281,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 /// the file path when you set the file. diff --git a/lldb/source/API/SBFileSpec.cpp b/lldb/source/API/SBFileSpec.cpp index 011b88225ef..027528c46ca 100644 --- a/lldb/source/API/SBFileSpec.cpp +++ b/lldb/source/API/SBFileSpec.cpp @@ -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, diff --git a/lldb/source/Host/common/FileSystem.cpp b/lldb/source/Host/common/FileSystem.cpp index 5f8d8fb4282..c5f4db6128c 100644 --- a/lldb/source/Host/common/FileSystem.cpp +++ b/lldb/source/Host/common/FileSystem.cpp @@ -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; +} diff --git a/lldb/source/Host/common/MonitoringProcessLauncher.cpp b/lldb/source/Host/common/MonitoringProcessLauncher.cpp index 76c11454f57..bdded150e7b 100644 --- a/lldb/source/Host/common/MonitoringProcessLauncher.cpp +++ b/lldb/source/Host/common/MonitoringProcessLauncher.cpp @@ -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); } diff --git a/lldb/source/Host/macosx/objcxx/Host.mm b/lldb/source/Host/macosx/objcxx/Host.mm index a70bf0421ec..c113a17f20f 100644 --- a/lldb/source/Host/macosx/objcxx/Host.mm +++ b/lldb/source/Host/macosx/objcxx/Host.mm @@ -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)) { diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp index 0016a5cd558..996bd2671da 100644 --- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp +++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp @@ -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()); diff --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp index fd1a4022b65..a4e590e2053 100644 --- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp +++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp @@ -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(); diff --git a/lldb/source/Target/ProcessLaunchInfo.cpp b/lldb/source/Target/ProcessLaunchInfo.cpp index 9569750bc5f..b0153ece80d 100644 --- a/lldb/source/Target/ProcessLaunchInfo.cpp +++ b/lldb/source/Target/ProcessLaunchInfo.cpp @@ -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); diff --git a/lldb/source/Utility/FileSpec.cpp b/lldb/source/Utility/FileSpec.cpp index c41a0643742..c0dfea36ee3 100644 --- a/lldb/source/Utility/FileSpec.cpp +++ b/lldb/source/Utility/FileSpec.cpp @@ -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 |