diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2018-11-08 00:14:50 +0000 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2018-11-08 00:14:50 +0000 |
commit | 3a58d89819389488df9fb5155f6d73ddd60e4816 (patch) | |
tree | 481f9e7a79eaf70ff06d7400a3ecf19c9f142aae /lldb/source | |
parent | 09dff53840787c0dbc031f1e5723834f62073f74 (diff) | |
download | bcm5719-llvm-3a58d89819389488df9fb5155f6d73ddd60e4816.tar.gz bcm5719-llvm-3a58d89819389488df9fb5155f6d73ddd60e4816.zip |
[FileSystem] Add convenience method to check for directories.
Replace calls to LLVM's is_directory with calls to LLDB's FileSytem
class. For this I introduced a new convenience method that, like the
other methods, takes either a path or filespec. This still uses the LLVM
functions under the hood.
Differential revision: https://reviews.llvm.org/D54135
llvm-svn: 346375
Diffstat (limited to 'lldb/source')
-rw-r--r-- | lldb/source/API/SBPlatform.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Core/Module.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Core/ModuleList.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Host/common/FileSystem.cpp | 11 | ||||
-rw-r--r-- | lldb/source/Host/common/Symbols.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Host/macosx/Symbols.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Host/macosx/objcxx/Host.mm | 4 | ||||
-rw-r--r-- | lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm | 2 | ||||
-rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp | 8 | ||||
-rw-r--r-- | lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp | 18 | ||||
-rw-r--r-- | lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Target/TargetList.cpp | 2 |
16 files changed, 38 insertions, 28 deletions
diff --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp index 2c254b2d946..aedad871cd2 100644 --- a/lldb/source/API/SBPlatform.cpp +++ b/lldb/source/API/SBPlatform.cpp @@ -366,7 +366,7 @@ SBError SBPlatform::Put(SBFileSpec &src, SBFileSpec &dst) { if (src.Exists()) { uint32_t permissions = FileSystem::Instance().GetPermissions(src.ref()); if (permissions == 0) { - if (llvm::sys::fs::is_directory(src.ref().GetPath())) + if (FileSystem::Instance().IsDirectory(src.ref())) permissions = eFilePermissionsDirectoryDefault; else permissions = eFilePermissionsFileDefault; diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 7fdca8a8626..714349d25d4 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -1448,7 +1448,7 @@ void Module::SetSymbolFileFileSpec(const FileSpec &file) { // ("/tmp/a.out.dSYM/Contents/Resources/DWARF/a.out"). So we need to // check this - if (llvm::sys::fs::is_directory(file.GetPath())) { + if (FileSystem::Instance().IsDirectory(file)) { std::string new_path(file.GetPath()); std::string old_path(obj_file->GetFileSpec().GetPath()); if (old_path.find(new_path) == 0) { diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp index baa5ff58501..9cff6c8218d 100644 --- a/lldb/source/Core/ModuleList.cpp +++ b/lldb/source/Core/ModuleList.cpp @@ -859,7 +859,7 @@ Status ModuleList::GetSharedModule(const ModuleSpec &module_spec, auto search_path_spec = module_search_paths_ptr->GetFileSpecAtIndex(idx); FileSystem::Instance().Resolve(search_path_spec); namespace fs = llvm::sys::fs; - if (!fs::is_directory(search_path_spec.GetPath())) + if (!FileSystem::Instance().IsDirectory(search_path_spec)) continue; search_path_spec.AppendPathComponent( module_spec.GetFileSpec().GetFilename().AsCString()); diff --git a/lldb/source/Host/common/FileSystem.cpp b/lldb/source/Host/common/FileSystem.cpp index 8b8b896f797..a9ed5bd1847 100644 --- a/lldb/source/Host/common/FileSystem.cpp +++ b/lldb/source/Host/common/FileSystem.cpp @@ -124,6 +124,17 @@ bool FileSystem::Readable(const FileSpec &file_spec) const { return Readable(file_spec.GetPath()); } +bool FileSystem::IsDirectory(const Twine &path) const { + ErrorOr<vfs::Status> status = m_fs->status(path); + if (!status) + return false; + return status->isDirectory(); +} + +bool FileSystem::IsDirectory(const FileSpec &file_spec) const { + return IsDirectory(file_spec.GetPath()); +} + void FileSystem::EnumerateDirectory(Twine path, bool find_directories, bool find_files, bool find_other, EnumerateDirectoryCallbackType callback, diff --git a/lldb/source/Host/common/Symbols.cpp b/lldb/source/Host/common/Symbols.cpp index 0a1eb8fd18f..5297ff040b0 100644 --- a/lldb/source/Host/common/Symbols.cpp +++ b/lldb/source/Host/common/Symbols.cpp @@ -311,7 +311,7 @@ FileSpec Symbols::LocateExecutableSymbolFile(const ModuleSpec &module_spec) { for (size_t idx = 0; idx < num_directories; ++idx) { FileSpec dirspec = debug_file_search_paths.GetFileSpecAtIndex(idx); FileSystem::Instance().Resolve(dirspec); - if (!llvm::sys::fs::is_directory(dirspec.GetPath())) + if (!FileSystem::Instance().IsDirectory(dirspec)) continue; std::vector<std::string> files; diff --git a/lldb/source/Host/macosx/Symbols.cpp b/lldb/source/Host/macosx/Symbols.cpp index 6c09014c801..2872be2b904 100644 --- a/lldb/source/Host/macosx/Symbols.cpp +++ b/lldb/source/Host/macosx/Symbols.cpp @@ -109,7 +109,7 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec, if (path[0] == '~') FileSystem::Instance().Resolve(dsym_filespec); - if (llvm::sys::fs::is_directory(dsym_filespec.GetPath())) { + if (FileSystem::Instance().IsDirectory(dsym_filespec)) { dsym_filespec = Symbols::FindSymbolFileInBundle(dsym_filespec, uuid, arch); ++items_found; diff --git a/lldb/source/Host/macosx/objcxx/Host.mm b/lldb/source/Host/macosx/objcxx/Host.mm index 6d6cf6a3199..297a052ac8e 100644 --- a/lldb/source/Host/macosx/objcxx/Host.mm +++ b/lldb/source/Host/macosx/objcxx/Host.mm @@ -101,7 +101,7 @@ using namespace lldb_private; bool Host::GetBundleDirectory(const FileSpec &file, FileSpec &bundle_directory) { #if defined(__APPLE__) - if (llvm::sys::fs::is_directory(file.GetPath())) { + if (FileSystem::Instance().IsDirectory(file)) { char path[PATH_MAX]; if (file.GetPath(path, sizeof(path))) { CFCBundle bundle(path); @@ -118,7 +118,7 @@ bool Host::GetBundleDirectory(const FileSpec &file, bool Host::ResolveExecutableInBundle(FileSpec &file) { #if defined(__APPLE__) - if (llvm::sys::fs::is_directory(file.GetPath())) { + if (FileSystem::Instance().IsDirectory(file)) { char path[PATH_MAX]; if (file.GetPath(path, sizeof(path))) { CFCBundle bundle(path); diff --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm index e9f84778b82..165e87e8bed 100644 --- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm +++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm @@ -141,7 +141,7 @@ bool HostInfoMacOSX::ComputeSupportExeDirectory(FileSpec &file_spec) { raw_path.append("/../bin"); FileSpec support_dir_spec(raw_path); FileSystem::Instance().Resolve(support_dir_spec); - if (!llvm::sys::fs::is_directory(support_dir_spec.GetPath())) { + if (!FileSystem::Instance().IsDirectory(support_dir_spec)) { Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); if (log) log->Printf("HostInfoMacOSX::%s(): failed to find support directory", diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp index 5f827817ef1..21aed4cb1e2 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp @@ -43,7 +43,7 @@ static bool DefaultComputeClangDirectory(FileSpec &file_spec) { #if defined(__APPLE__) static bool VerifyClangPath(const llvm::Twine &clang_path) { - if (llvm::sys::fs::is_directory(clang_path)) + if (FileSystem::Instance().IsDirectory(clang_path)) return true; Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); if (log) diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp index 665195f0177..5ca11d9d83f 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp @@ -601,7 +601,7 @@ ClangModulesDeclVendor::Create(Target &target) { { FileSpec clang_resource_dir = GetClangResourceDir(); - if (llvm::sys::fs::is_directory(clang_resource_dir.GetPath())) { + if (FileSystem::Instance().IsDirectory(clang_resource_dir.GetPath())) { compiler_invocation_arguments.push_back("-resource-dir"); compiler_invocation_arguments.push_back(clang_resource_dir.GetPath()); } diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 9e33896f0b2..37ee0843182 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1208,7 +1208,7 @@ const char *PlatformDarwin::GetDeveloperDirectory() { developer_dir_path[i] = '\0'; FileSpec devel_dir(developer_dir_path); - if (llvm::sys::fs::is_directory(devel_dir.GetPath())) { + if (FileSystem::Instance().IsDirectory(devel_dir)) { developer_dir_path_valid = true; } } @@ -1435,7 +1435,7 @@ FileSpec PlatformDarwin::FindSDKInXcodeForModules(SDKType sdk_type, const FileSpec &sdks_spec) { // Look inside Xcode for the required installed iOS SDK version - if (!llvm::sys::fs::is_directory(sdks_spec.GetPath())) { + if (!FileSystem::Instance().IsDirectory(sdks_spec)) { return FileSpec(); } @@ -1451,7 +1451,7 @@ FileSpec PlatformDarwin::FindSDKInXcodeForModules(SDKType sdk_type, sdks_spec.GetPath(), find_directories, find_files, find_other, DirectoryEnumerator, &enumerator_info); - if (llvm::sys::fs::is_directory(enumerator_info.found_path.GetPath())) + if (FileSystem::Instance().IsDirectory(enumerator_info.found_path)) return enumerator_info.found_path; else return FileSpec(); @@ -1596,7 +1596,7 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType( sysroot_spec = GetSDKDirectoryForModules(sdk_type); } - if (llvm::sys::fs::is_directory(sysroot_spec.GetPath())) { + if (FileSystem::Instance().IsDirectory(sysroot_spec.GetPath())) { options.push_back("-isysroot"); options.push_back(sysroot_spec.GetPath()); } diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp index c567db2e75a..7381f29a784 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp @@ -379,7 +379,7 @@ void PlatformDarwinKernel::CollectKextAndKernelDirectories() { // Add simple directory /Applications/Xcode.app/Contents/Developer/../Symbols FileSpec possible_dir(developer_dir + "/../Symbols"); FileSystem::Instance().Resolve(possible_dir); - if (llvm::sys::fs::is_directory(possible_dir.GetPath())) + if (FileSystem::Instance().IsDirectory(possible_dir)) m_search_directories.push_back(possible_dir); // Add simple directory of the current working directory @@ -396,7 +396,7 @@ void PlatformDarwinKernel::GetUserSpecifiedDirectoriesToSearch() { for (uint32_t i = 0; i < user_dirs_count; i++) { FileSpec dir = user_dirs.GetFileSpecAtIndex(i); FileSystem::Instance().Resolve(dir); - if (llvm::sys::fs::is_directory(dir.GetPath())) { + if (FileSystem::Instance().IsDirectory(dir)) { m_search_directories.push_back(dir); } } @@ -413,7 +413,7 @@ void PlatformDarwinKernel::AddRootSubdirsToSearchPaths( for (int i = 0; subdirs[i] != nullptr; i++) { FileSpec testdir(dir + subdirs[i]); FileSystem::Instance().Resolve(testdir); - if (llvm::sys::fs::is_directory(testdir.GetPath())) + if (FileSystem::Instance().IsDirectory(testdir)) thisp->m_search_directories.push_back(testdir); } @@ -542,11 +542,11 @@ PlatformDarwinKernel::GetKernelsAndKextsInDirectoryHelper( // Look to see if there is a PlugIns subdir with more kexts FileSpec contents_plugins(file_spec.GetPath() + "/Contents/PlugIns"); std::string search_here_too; - if (llvm::sys::fs::is_directory(contents_plugins.GetPath())) { + if (FileSystem::Instance().IsDirectory(contents_plugins)) { search_here_too = contents_plugins.GetPath(); } else { FileSpec plugins(file_spec.GetPath() + "/PlugIns"); - if (llvm::sys::fs::is_directory(plugins.GetPath())) { + if (FileSystem::Instance().IsDirectory(plugins)) { search_here_too = plugins.GetPath(); } } @@ -618,7 +618,7 @@ bool PlatformDarwinKernel::KextHasdSYMSibling( std::string filename = dsym_fspec.GetFilename().AsCString(); filename += ".dSYM"; dsym_fspec.GetFilename() = ConstString(filename); - if (llvm::sys::fs::is_directory(dsym_fspec.GetPath())) { + if (FileSystem::Instance().IsDirectory(dsym_fspec)) { return true; } // Should probably get the CFBundleExecutable here or call @@ -633,7 +633,7 @@ bool PlatformDarwinKernel::KextHasdSYMSibling( deep_bundle_str += ".dSYM"; dsym_fspec.SetFile(deep_bundle_str, FileSpec::Style::native); FileSystem::Instance().Resolve(dsym_fspec); - if (llvm::sys::fs::is_directory(dsym_fspec.GetPath())) { + if (FileSystem::Instance().IsDirectory(dsym_fspec)) { return true; } @@ -644,7 +644,7 @@ bool PlatformDarwinKernel::KextHasdSYMSibling( shallow_bundle_str += ".dSYM"; dsym_fspec.SetFile(shallow_bundle_str, FileSpec::Style::native); FileSystem::Instance().Resolve(dsym_fspec); - if (llvm::sys::fs::is_directory(dsym_fspec.GetPath())) { + if (FileSystem::Instance().IsDirectory(dsym_fspec)) { return true; } return false; @@ -658,7 +658,7 @@ bool PlatformDarwinKernel::KernelHasdSYMSibling(const FileSpec &kernel_binary) { std::string filename = kernel_binary.GetFilename().AsCString(); filename += ".dSYM"; kernel_dsym.GetFilename() = ConstString(filename); - if (llvm::sys::fs::is_directory(kernel_dsym.GetPath())) { + if (FileSystem::Instance().IsDirectory(kernel_dsym)) { return true; } return false; diff --git a/lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp b/lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp index 977da2f0ecc..70d9a5248fd 100644 --- a/lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp +++ b/lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp @@ -65,7 +65,7 @@ Status NativeProcessProtocol::Launch( FileSpec working_dir(launch_info.GetWorkingDirectory()); if (working_dir) { FileInstance::Instance().Resolve(working_dir); - if (!llvm::sys::fs::is_directory(working_dir.GetPath())) { + if (!FileSystem::Instance().IsDirectory(working_dir)) { error.SetErrorStringWithFormat("No such file or directory: %s", working_dir.GetCString()); return error; diff --git a/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp b/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp index a23f54b7d72..bd60defe501 100644 --- a/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp +++ b/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp @@ -374,10 +374,9 @@ Status ProcessFreeBSD::DoLaunch(Module *module, assert(m_monitor == NULL); FileSpec working_dir = launch_info.GetWorkingDirectory(); - namespace fs = llvm::sys::fs; if (working_dir) { FileSystem::Instance().Resolve(working_dir); - if (!fs::is_directory(working_dir.GetPath())) { + if (!FileSystem::Instance().IsDirectory(working_dir.GetPath())) { error.SetErrorStringWithFormat("No such file or directory: %s", working_dir.GetCString()); return error; diff --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp index 945b2ebabc4..583948434b2 100644 --- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp +++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp @@ -254,7 +254,7 @@ Status ProcessWindows::DoLaunch(Module *exe_module, namespace fs = llvm::sys::fs; if (working_dir) { FileSystem::Instance().Resolve(working_dir); - if (!fs::is_directory(working_dir.GetPath())) { + if (!FileSystem::Instance().IsDirectory(working_dir)) { result.SetErrorStringWithFormat("No such file or directory: %s", working_dir.GetCString()); return result; diff --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp index 84930b05cf0..5720777af37 100644 --- a/lldb/source/Target/TargetList.cpp +++ b/lldb/source/Target/TargetList.cpp @@ -364,7 +364,7 @@ Status TargetList::CreateTargetInternal(Debugger &debugger, char resolved_bundle_exe_path[PATH_MAX]; resolved_bundle_exe_path[0] = '\0'; if (file) { - if (llvm::sys::fs::is_directory(file.GetPath())) + if (FileSystem::Instance().IsDirectory(file)) user_exe_path_is_bundle = true; if (file.IsRelative() && !user_exe_path.empty()) { |