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 /lldb/source/Host/common/FileSystem.cpp | |
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
Diffstat (limited to 'lldb/source/Host/common/FileSystem.cpp')
-rw-r--r-- | lldb/source/Host/common/FileSystem.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
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; +} |