[Lldb-commits] [lldb] r345800 - [FileSystem] Move EnumerateDirectory from FileSpec to FileSystem.
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Wed Oct 31 17:33:28 PDT 2018
Author: jdevlieghere
Date: Wed Oct 31 17:33:27 2018
New Revision: 345800
URL: http://llvm.org/viewvc/llvm-project?rev=345800&view=rev
Log:
[FileSystem] Move EnumerateDirectory from FileSpec to FileSystem.
This patch moves the EnumerateDirectory functionality and related enum
and typedef from FileSpec to FileSystem.
This is part of a set of patches that extracts file system related
convenience methods from FileSpec. The long term goal is to remove this
method altogether and use the iterators directly, but for introducing
the VFS into LLDB this change is sufficient.
Differential revision: https://reviews.llvm.org/D53785
Modified:
lldb/trunk/include/lldb/Utility/FileSpec.h
lldb/trunk/source/Core/Debugger.cpp
lldb/trunk/source/Core/PluginManager.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp
lldb/trunk/source/Target/Platform.cpp
lldb/trunk/source/Utility/FileSpec.cpp
Modified: lldb/trunk/include/lldb/Utility/FileSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/FileSpec.h?rev=345800&r1=345799&r2=345800&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/FileSpec.h (original)
+++ lldb/trunk/include/lldb/Utility/FileSpec.h Wed Oct 31 17:33:27 2018
@@ -545,27 +545,6 @@ public:
ConstString GetLastPathComponent() const;
- enum EnumerateDirectoryResult {
- eEnumerateDirectoryResultNext, // Enumerate next entry in the current
- // directory
- eEnumerateDirectoryResultEnter, // Recurse into the current entry if it is a
- // directory or symlink, or next if not
- eEnumerateDirectoryResultQuit // Stop directory enumerations at any level
- };
-
- typedef EnumerateDirectoryResult (*EnumerateDirectoryCallbackType)(
- void *baton, llvm::sys::fs::file_type file_type, const FileSpec &spec);
-
- static void EnumerateDirectory(llvm::StringRef dir_path,
- bool find_directories, bool find_files,
- bool find_other,
- EnumerateDirectoryCallbackType callback,
- void *callback_baton);
-
- typedef std::function<EnumerateDirectoryResult(
- llvm::sys::fs::file_type file_type, const FileSpec &spec)>
- DirectoryCallback;
-
protected:
//------------------------------------------------------------------
// Convenience method for setting the file without changing the style.
Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=345800&r1=345799&r2=345800&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Wed Oct 31 17:33:27 2018
@@ -21,6 +21,7 @@
#include "lldb/DataFormatters/DataVisualization.h"
#include "lldb/Expression/REPL.h"
#include "lldb/Host/File.h" // for File, File::kInv...
+#include "lldb/Host/FileSystem.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Host/Terminal.h"
#include "lldb/Host/ThreadLauncher.h"
@@ -604,16 +605,16 @@ bool Debugger::LoadPlugin(const FileSpec
return false;
}
-static FileSpec::EnumerateDirectoryResult
+static FileSystem::EnumerateDirectoryResult
LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft,
- const FileSpec &file_spec) {
+ llvm::StringRef path) {
Status error;
static ConstString g_dylibext(".dylib");
static ConstString g_solibext(".so");
if (!baton)
- return FileSpec::eEnumerateDirectoryResultQuit;
+ return FileSystem::eEnumerateDirectoryResultQuit;
Debugger *debugger = (Debugger *)baton;
@@ -624,18 +625,18 @@ LoadPluginCallback(void *baton, llvm::sy
// file type information.
if (ft == fs::file_type::regular_file || ft == fs::file_type::symlink_file ||
ft == fs::file_type::type_unknown) {
- FileSpec plugin_file_spec(file_spec);
+ FileSpec plugin_file_spec(path, false);
plugin_file_spec.ResolvePath();
if (plugin_file_spec.GetFileNameExtension() != g_dylibext &&
plugin_file_spec.GetFileNameExtension() != g_solibext) {
- return FileSpec::eEnumerateDirectoryResultNext;
+ return FileSystem::eEnumerateDirectoryResultNext;
}
Status plugin_load_error;
debugger->LoadPlugin(plugin_file_spec, plugin_load_error);
- return FileSpec::eEnumerateDirectoryResultNext;
+ return FileSystem::eEnumerateDirectoryResultNext;
} else if (ft == fs::file_type::directory_file ||
ft == fs::file_type::symlink_file ||
ft == fs::file_type::type_unknown) {
@@ -643,10 +644,10 @@ LoadPluginCallback(void *baton, llvm::sy
// also do this for unknown as sometimes the directory enumeration might be
// enumerating a file system that doesn't have correct file type
// information.
- return FileSpec::eEnumerateDirectoryResultEnter;
+ return FileSystem::eEnumerateDirectoryResultEnter;
}
- return FileSpec::eEnumerateDirectoryResultNext;
+ return FileSystem::eEnumerateDirectoryResultNext;
}
void Debugger::InstanceInitialize() {
@@ -656,15 +657,17 @@ void Debugger::InstanceInitialize() {
char dir_path[PATH_MAX];
if (FileSpec dir_spec = HostInfo::GetSystemPluginDir()) {
if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) {
- FileSpec::EnumerateDirectory(dir_path, find_directories, find_files,
- find_other, LoadPluginCallback, this);
+ FileSystem::Instance().EnumerateDirectory(dir_path, find_directories,
+ find_files, find_other,
+ LoadPluginCallback, this);
}
}
if (FileSpec dir_spec = HostInfo::GetUserPluginDir()) {
if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) {
- FileSpec::EnumerateDirectory(dir_path, find_directories, find_files,
- find_other, LoadPluginCallback, this);
+ FileSystem::Instance().EnumerateDirectory(dir_path, find_directories,
+ find_files, find_other,
+ LoadPluginCallback, this);
}
}
Modified: lldb/trunk/source/Core/PluginManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/PluginManager.cpp?rev=345800&r1=345799&r2=345800&view=diff
==============================================================================
--- lldb/trunk/source/Core/PluginManager.cpp (original)
+++ lldb/trunk/source/Core/PluginManager.cpp Wed Oct 31 17:33:27 2018
@@ -10,6 +10,7 @@
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/Debugger.h"
+#include "lldb/Host/FileSystem.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Interpreter/OptionValueProperties.h"
#include "lldb/Utility/ConstString.h" // for ConstString
@@ -89,9 +90,9 @@ template <typename FPtrTy> static FPtrTy
return reinterpret_cast<FPtrTy>(reinterpret_cast<intptr_t>(VPtr));
}
-static FileSpec::EnumerateDirectoryResult
+static FileSystem::EnumerateDirectoryResult
LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft,
- const FileSpec &file_spec) {
+ llvm::StringRef path) {
// PluginManager *plugin_manager = (PluginManager *)baton;
Status error;
@@ -102,11 +103,11 @@ LoadPluginCallback(void *baton, llvm::sy
// file type information.
if (ft == fs::file_type::regular_file || ft == fs::file_type::symlink_file ||
ft == fs::file_type::type_unknown) {
- FileSpec plugin_file_spec(file_spec);
+ FileSpec plugin_file_spec(path, false);
plugin_file_spec.ResolvePath();
if (PluginIsLoaded(plugin_file_spec))
- return FileSpec::eEnumerateDirectoryResultNext;
+ return FileSystem::eEnumerateDirectoryResultNext;
else {
PluginInfo plugin_info;
@@ -138,7 +139,7 @@ LoadPluginCallback(void *baton, llvm::sy
// plug-in info so we don't try to load it again and again.
SetPluginInfo(plugin_file_spec, plugin_info);
- return FileSpec::eEnumerateDirectoryResultNext;
+ return FileSystem::eEnumerateDirectoryResultNext;
}
}
}
@@ -149,10 +150,10 @@ LoadPluginCallback(void *baton, llvm::sy
// also do this for unknown as sometimes the directory enumeration might be
// enumerating a file system that doesn't have correct file type
// information.
- return FileSpec::eEnumerateDirectoryResultEnter;
+ return FileSystem::eEnumerateDirectoryResultEnter;
}
- return FileSpec::eEnumerateDirectoryResultNext;
+ return FileSystem::eEnumerateDirectoryResultNext;
}
void PluginManager::Initialize() {
@@ -163,15 +164,17 @@ void PluginManager::Initialize() {
char dir_path[PATH_MAX];
if (FileSpec dir_spec = HostInfo::GetSystemPluginDir()) {
if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) {
- FileSpec::EnumerateDirectory(dir_path, find_directories, find_files,
- find_other, LoadPluginCallback, nullptr);
+ FileSystem::Instance().EnumerateDirectory(dir_path, find_directories,
+ find_files, find_other,
+ LoadPluginCallback, nullptr);
}
}
if (FileSpec dir_spec = HostInfo::GetUserPluginDir()) {
if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) {
- FileSpec::EnumerateDirectory(dir_path, find_directories, find_files,
- find_other, LoadPluginCallback, nullptr);
+ FileSystem::Instance().EnumerateDirectory(dir_path, find_directories,
+ find_files, find_other,
+ LoadPluginCallback, nullptr);
}
}
#endif
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp?rev=345800&r1=345799&r2=345800&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp Wed Oct 31 17:33:27 2018
@@ -247,19 +247,20 @@ Status PlatformAppleTVSimulator::Resolve
return error;
}
-static FileSpec::EnumerateDirectoryResult
+static FileSystem::EnumerateDirectoryResult
EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft,
- const FileSpec &file_spec) {
+ llvm::StringRef path) {
if (ft == llvm::sys::fs::file_type::directory_file) {
+ FileSpec file_spec(path, false);
const char *filename = file_spec.GetFilename().GetCString();
if (filename &&
strncmp(filename, "AppleTVSimulator", strlen("AppleTVSimulator")) ==
0) {
::snprintf((char *)baton, PATH_MAX, "%s", filename);
- return FileSpec::eEnumerateDirectoryResultQuit;
+ return FileSystem::eEnumerateDirectoryResultQuit;
}
}
- return FileSpec::eEnumerateDirectoryResultNext;
+ return FileSystem::eEnumerateDirectoryResultNext;
}
const char *PlatformAppleTVSimulator::GetSDKDirectoryAsCString() {
@@ -277,9 +278,9 @@ const char *PlatformAppleTVSimulator::Ge
bool find_directories = true;
bool find_files = false;
bool find_other = false;
- FileSpec::EnumerateDirectory(sdks_directory, find_directories, find_files,
- find_other, EnumerateDirectoryCallback,
- sdk_dirname);
+ FileSystem::Instance().EnumerateDirectory(
+ sdks_directory, find_directories, find_files, find_other,
+ EnumerateDirectoryCallback, sdk_dirname);
if (sdk_dirname[0]) {
m_sdk_directory = sdks_directory;
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp?rev=345800&r1=345799&r2=345800&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp Wed Oct 31 17:33:27 2018
@@ -247,19 +247,20 @@ Status PlatformAppleWatchSimulator::Reso
return error;
}
-static FileSpec::EnumerateDirectoryResult
+static FileSystem::EnumerateDirectoryResult
EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft,
- const FileSpec &file_spec) {
+ llvm::StringRef path) {
if (ft == llvm::sys::fs::file_type::directory_file) {
+ FileSpec file_spec(path, false);
const char *filename = file_spec.GetFilename().GetCString();
if (filename &&
strncmp(filename, "AppleWatchSimulator",
strlen("AppleWatchSimulator")) == 0) {
::snprintf((char *)baton, PATH_MAX, "%s", filename);
- return FileSpec::eEnumerateDirectoryResultQuit;
+ return FileSystem::eEnumerateDirectoryResultQuit;
}
}
- return FileSpec::eEnumerateDirectoryResultNext;
+ return FileSystem::eEnumerateDirectoryResultNext;
}
const char *PlatformAppleWatchSimulator::GetSDKDirectoryAsCString() {
@@ -277,9 +278,9 @@ const char *PlatformAppleWatchSimulator:
bool find_directories = true;
bool find_files = false;
bool find_other = false;
- FileSpec::EnumerateDirectory(sdks_directory, find_directories, find_files,
- find_other, EnumerateDirectoryCallback,
- sdk_dirname);
+ FileSystem::Instance().EnumerateDirectory(
+ sdks_directory, find_directories, find_files, find_other,
+ EnumerateDirectoryCallback, sdk_dirname);
if (sdk_dirname[0]) {
m_sdk_directory = sdks_directory;
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp?rev=345800&r1=345799&r2=345800&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Wed Oct 31 17:33:27 2018
@@ -1417,16 +1417,17 @@ bool PlatformDarwin::SDKSupportsModules(
return false;
}
-FileSpec::EnumerateDirectoryResult PlatformDarwin::DirectoryEnumerator(
- void *baton, llvm::sys::fs::file_type file_type, const FileSpec &spec) {
+FileSystem::EnumerateDirectoryResult PlatformDarwin::DirectoryEnumerator(
+ void *baton, llvm::sys::fs::file_type file_type, llvm::StringRef path) {
SDKEnumeratorInfo *enumerator_info = static_cast<SDKEnumeratorInfo *>(baton);
+ FileSpec spec(path, false);
if (SDKSupportsModules(enumerator_info->sdk_type, spec)) {
enumerator_info->found_path = spec;
- return FileSpec::EnumerateDirectoryResult::eEnumerateDirectoryResultNext;
+ return FileSystem::EnumerateDirectoryResult::eEnumerateDirectoryResultNext;
}
- return FileSpec::EnumerateDirectoryResult::eEnumerateDirectoryResultNext;
+ return FileSystem::EnumerateDirectoryResult::eEnumerateDirectoryResultNext;
}
FileSpec PlatformDarwin::FindSDKInXcodeForModules(SDKType sdk_type,
@@ -1445,9 +1446,9 @@ FileSpec PlatformDarwin::FindSDKInXcodeF
enumerator_info.sdk_type = sdk_type;
- FileSpec::EnumerateDirectory(sdks_spec.GetPath(), find_directories,
- find_files, find_other, DirectoryEnumerator,
- &enumerator_info);
+ FileSystem::Instance().EnumerateDirectory(
+ sdks_spec.GetPath(), find_directories, find_files, find_other,
+ DirectoryEnumerator, &enumerator_info);
if (llvm::sys::fs::is_directory(enumerator_info.found_path.GetPath()))
return enumerator_info.found_path;
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h?rev=345800&r1=345799&r2=345800&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h Wed Oct 31 17:33:27 2018
@@ -16,6 +16,7 @@
// Other libraries and framework includes
// Project includes
#include "Plugins/Platform/POSIX/PlatformPOSIX.h"
+#include "lldb/Host/FileSystem.h"
#include "lldb/Utility/FileSpec.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FileSystem.h"
@@ -111,9 +112,9 @@ protected:
SDKType sdk_type;
};
- static lldb_private::FileSpec::EnumerateDirectoryResult
+ static lldb_private::FileSystem::EnumerateDirectoryResult
DirectoryEnumerator(void *baton, llvm::sys::fs::file_type file_type,
- const lldb_private::FileSpec &spec);
+ llvm::StringRef path);
static lldb_private::FileSpec
FindSDKInXcodeForModules(SDKType sdk_type,
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp?rev=345800&r1=345799&r2=345800&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp Wed Oct 31 17:33:27 2018
@@ -424,25 +424,26 @@ void PlatformDarwinKernel::AddSDKSubdirs
const bool find_directories = true;
const bool find_files = false;
const bool find_other = false;
- FileSpec::EnumerateDirectory(dir.c_str(), find_directories, find_files,
- find_other, FindKDKandSDKDirectoriesInDirectory,
- this);
+ FileSystem::Instance().EnumerateDirectory(
+ dir.c_str(), find_directories, find_files, find_other,
+ FindKDKandSDKDirectoriesInDirectory, this);
}
// Helper function to find *.sdk and *.kdk directories in a given directory.
-FileSpec::EnumerateDirectoryResult
+FileSystem::EnumerateDirectoryResult
PlatformDarwinKernel::FindKDKandSDKDirectoriesInDirectory(
- void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) {
+ void *baton, llvm::sys::fs::file_type ft, llvm::StringRef path) {
static ConstString g_sdk_suffix = ConstString(".sdk");
static ConstString g_kdk_suffix = ConstString(".kdk");
PlatformDarwinKernel *thisp = (PlatformDarwinKernel *)baton;
+ FileSpec file_spec(path, false);
if (ft == llvm::sys::fs::file_type::directory_file &&
(file_spec.GetFileNameExtension() == g_sdk_suffix ||
file_spec.GetFileNameExtension() == g_kdk_suffix)) {
AddRootSubdirsToSearchPaths(thisp, file_spec.GetPath());
}
- return FileSpec::eEnumerateDirectoryResultNext;
+ return FileSystem::eEnumerateDirectoryResultNext;
}
// Recursively search trough m_search_directories looking for kext and kernel
@@ -454,7 +455,7 @@ void PlatformDarwinKernel::SearchForKext
const bool find_directories = true;
const bool find_files = true;
const bool find_other = true; // I think eFileTypeSymbolicLink are "other"s.
- FileSpec::EnumerateDirectory(
+ FileSystem::Instance().EnumerateDirectory(
dir.GetPath().c_str(), find_directories, find_files, find_other,
GetKernelsAndKextsInDirectoryWithRecursion, this);
}
@@ -464,7 +465,7 @@ void PlatformDarwinKernel::SearchForKext
const bool find_directories = true;
const bool find_files = true;
const bool find_other = true; // I think eFileTypeSymbolicLink are "other"s.
- FileSpec::EnumerateDirectory(
+ FileSystem::Instance().EnumerateDirectory(
dir.GetPath().c_str(), find_directories, find_files, find_other,
GetKernelsAndKextsInDirectoryNoRecursion, this);
}
@@ -478,25 +479,27 @@ void PlatformDarwinKernel::SearchForKext
//
// Recurse into any subdirectories found.
-FileSpec::EnumerateDirectoryResult
+FileSystem::EnumerateDirectoryResult
PlatformDarwinKernel::GetKernelsAndKextsInDirectoryWithRecursion(
- void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) {
- return GetKernelsAndKextsInDirectoryHelper(baton, ft, file_spec, true);
+ void *baton, llvm::sys::fs::file_type ft, llvm::StringRef path) {
+ return GetKernelsAndKextsInDirectoryHelper(baton, ft, path, true);
}
-FileSpec::EnumerateDirectoryResult
+FileSystem::EnumerateDirectoryResult
PlatformDarwinKernel::GetKernelsAndKextsInDirectoryNoRecursion(
- void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) {
- return GetKernelsAndKextsInDirectoryHelper(baton, ft, file_spec, false);
+ void *baton, llvm::sys::fs::file_type ft, llvm::StringRef path) {
+ return GetKernelsAndKextsInDirectoryHelper(baton, ft, path, false);
}
-FileSpec::EnumerateDirectoryResult
+FileSystem::EnumerateDirectoryResult
PlatformDarwinKernel::GetKernelsAndKextsInDirectoryHelper(
- void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec,
+ void *baton, llvm::sys::fs::file_type ft, llvm::StringRef path,
bool recurse) {
static ConstString g_kext_suffix = ConstString(".kext");
static ConstString g_dsym_suffix = ConstString(".dSYM");
static ConstString g_bundle_suffix = ConstString("Bundle");
+
+ FileSpec file_spec(path, false);
ConstString file_spec_extension = file_spec.GetFileNameExtension();
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
@@ -528,7 +531,7 @@ PlatformDarwinKernel::GetKernelsAndKexts
}
thisp->m_kernel_binaries_without_dsyms.push_back(file_spec);
}
- return FileSpec::eEnumerateDirectoryResultNext;
+ return FileSystem::eEnumerateDirectoryResultNext;
}
} else if (ft == llvm::sys::fs::file_type::directory_file &&
file_spec_extension == g_kext_suffix) {
@@ -549,13 +552,13 @@ PlatformDarwinKernel::GetKernelsAndKexts
const bool find_directories = true;
const bool find_files = false;
const bool find_other = false;
- FileSpec::EnumerateDirectory(
+ FileSystem::Instance().EnumerateDirectory(
search_here_too.c_str(), find_directories, find_files, find_other,
recurse ? GetKernelsAndKextsInDirectoryWithRecursion
: GetKernelsAndKextsInDirectoryNoRecursion,
baton);
}
- return FileSpec::eEnumerateDirectoryResultNext;
+ return FileSystem::eEnumerateDirectoryResultNext;
}
// Don't recurse into dSYM/kext/bundle directories
if (recurse && file_spec_extension != g_dsym_suffix &&
@@ -563,9 +566,9 @@ PlatformDarwinKernel::GetKernelsAndKexts
file_spec_extension != g_bundle_suffix) {
if (log_verbose)
log_verbose->Printf ("PlatformDarwinKernel descending into directory '%s'", file_spec.GetPath().c_str());
- return FileSpec::eEnumerateDirectoryResultEnter;
+ return FileSystem::eEnumerateDirectoryResultEnter;
} else {
- return FileSpec::eEnumerateDirectoryResultNext;
+ return FileSystem::eEnumerateDirectoryResultNext;
}
}
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h?rev=345800&r1=345799&r2=345800&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h Wed Oct 31 17:33:27 2018
@@ -106,26 +106,25 @@ protected:
void AddSDKSubdirsToSearchPaths(const std::string &dir);
- static lldb_private::FileSpec::EnumerateDirectoryResult
+ static lldb_private::FileSystem::EnumerateDirectoryResult
FindKDKandSDKDirectoriesInDirectory(void *baton, llvm::sys::fs::file_type ft,
- const lldb_private::FileSpec &file_spec);
+ llvm::StringRef path);
void SearchForKextsAndKernelsRecursively();
- static lldb_private::FileSpec::EnumerateDirectoryResult
- GetKernelsAndKextsInDirectoryWithRecursion(
- void *baton, llvm::sys::fs::file_type ft,
- const lldb_private::FileSpec &file_spec);
-
- static lldb_private::FileSpec::EnumerateDirectoryResult
- GetKernelsAndKextsInDirectoryNoRecursion(
- void *baton, llvm::sys::fs::file_type ft,
- const lldb_private::FileSpec &file_spec);
+ static lldb_private::FileSystem::EnumerateDirectoryResult
+ GetKernelsAndKextsInDirectoryWithRecursion(void *baton,
+ llvm::sys::fs::file_type ft,
+ llvm::StringRef path);
+
+ static lldb_private::FileSystem::EnumerateDirectoryResult
+ GetKernelsAndKextsInDirectoryNoRecursion(void *baton,
+ llvm::sys::fs::file_type ft,
+ llvm::StringRef path);
- static lldb_private::FileSpec::EnumerateDirectoryResult
+ static lldb_private::FileSystem::EnumerateDirectoryResult
GetKernelsAndKextsInDirectoryHelper(void *baton, llvm::sys::fs::file_type ft,
- const lldb_private::FileSpec &file_spec,
- bool recurse);
+ llvm::StringRef path, bool recurse);
static std::vector<lldb_private::FileSpec>
SearchForExecutablesRecursively(const std::string &dir);
@@ -148,7 +147,7 @@ protected:
const lldb_private::ArchSpec &arch,
lldb::ModuleSP &exe_module_sp);
- // Most of the ivars are assembled under FileSpec::EnumerateDirectory calls
+ // Most of the ivars are assembled under FileSystem::EnumerateDirectory calls
// where the
// function being called for each file/directory must be static. We'll pass a
// this pointer
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp?rev=345800&r1=345799&r2=345800&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp Wed Oct 31 17:33:27 2018
@@ -139,12 +139,13 @@ Status PlatformRemoteDarwinDevice::Resol
return error;
}
-FileSpec::EnumerateDirectoryResult
+FileSystem::EnumerateDirectoryResult
PlatformRemoteDarwinDevice::GetContainedFilesIntoVectorOfStringsCallback(
- void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) {
+ void *baton, llvm::sys::fs::file_type ft, llvm::StringRef path) {
((PlatformRemoteDarwinDevice::SDKDirectoryInfoCollection *)baton)
- ->push_back(PlatformRemoteDarwinDevice::SDKDirectoryInfo(file_spec));
- return FileSpec::eEnumerateDirectoryResultNext;
+ ->push_back(
+ PlatformRemoteDarwinDevice::SDKDirectoryInfo(FileSpec(path, false)));
+ return FileSystem::eEnumerateDirectoryResultNext;
}
bool PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded() {
@@ -175,10 +176,10 @@ bool PlatformRemoteDarwinDevice::UpdateS
const bool find_other = false;
SDKDirectoryInfoCollection builtin_sdk_directory_infos;
- FileSpec::EnumerateDirectory(m_device_support_directory, find_directories,
- find_files, find_other,
- GetContainedFilesIntoVectorOfStringsCallback,
- &builtin_sdk_directory_infos);
+ FileSystem::Instance().EnumerateDirectory(
+ m_device_support_directory, find_directories, find_files, find_other,
+ GetContainedFilesIntoVectorOfStringsCallback,
+ &builtin_sdk_directory_infos);
// Only add SDK directories that have symbols in them, some SDKs only
// contain developer disk images and no symbols, so they aren't useful to
@@ -214,13 +215,13 @@ bool PlatformRemoteDarwinDevice::UpdateS
}
char path[PATH_MAX];
if (local_sdk_cache.GetPath(path, sizeof(path))) {
- FileSpec::EnumerateDirectory(
- path, find_directories, find_files, find_other,
- GetContainedFilesIntoVectorOfStringsCallback,
- &m_sdk_directory_infos);
- const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
- // First try for an exact match of major, minor and update
- for (uint32_t i = num_installed; i < num_sdk_infos; ++i) {
+ FileSystem::Instance().EnumerateDirectory(
+ path, find_directories, find_files, find_other,
+ GetContainedFilesIntoVectorOfStringsCallback,
+ &m_sdk_directory_infos);
+ const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
+ // First try for an exact match of major, minor and update
+ for (uint32_t i = num_installed; i < num_sdk_infos; ++i) {
m_sdk_directory_infos[i].user_cached = true;
if (log) {
log->Printf("PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded "
@@ -235,10 +236,10 @@ bool PlatformRemoteDarwinDevice::UpdateS
const char *addtional_platform_dirs = getenv("PLATFORM_SDK_DIRECTORY");
if (addtional_platform_dirs) {
SDKDirectoryInfoCollection env_var_sdk_directory_infos;
- FileSpec::EnumerateDirectory(addtional_platform_dirs, find_directories,
- find_files, find_other,
- GetContainedFilesIntoVectorOfStringsCallback,
- &env_var_sdk_directory_infos);
+ FileSystem::Instance().EnumerateDirectory(
+ addtional_platform_dirs, find_directories, find_files, find_other,
+ GetContainedFilesIntoVectorOfStringsCallback,
+ &env_var_sdk_directory_infos);
FileSpec sdk_symbols_symlink_fspec;
for (const auto &sdk_directory_info : env_var_sdk_directory_infos) {
sdk_symbols_symlink_fspec = sdk_directory_info.directory;
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h?rev=345800&r1=345799&r2=345800&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h Wed Oct 31 17:33:27 2018
@@ -84,10 +84,10 @@ protected:
const SDKDirectoryInfo *GetSDKDirectoryForCurrentOSVersion();
- static lldb_private::FileSpec::EnumerateDirectoryResult
- GetContainedFilesIntoVectorOfStringsCallback(
- void *baton, llvm::sys::fs::file_type ft,
- const lldb_private::FileSpec &file_spec);
+ static lldb_private::FileSystem::EnumerateDirectoryResult
+ GetContainedFilesIntoVectorOfStringsCallback(void *baton,
+ llvm::sys::fs::file_type ft,
+ llvm::StringRef path);
uint32_t FindFileInAllSDKs(const char *platform_file_path,
lldb_private::FileSpecList &file_list);
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp?rev=345800&r1=345799&r2=345800&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp Wed Oct 31 17:33:27 2018
@@ -253,18 +253,19 @@ Status PlatformiOSSimulator::ResolveExec
return error;
}
-static FileSpec::EnumerateDirectoryResult
+static FileSystem::EnumerateDirectoryResult
EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft,
- const FileSpec &file_spec) {
+ llvm::StringRef path) {
if (ft == llvm::sys::fs::file_type::directory_file) {
+ FileSpec file_spec(path, false);
const char *filename = file_spec.GetFilename().GetCString();
if (filename &&
strncmp(filename, "iPhoneSimulator", strlen("iPhoneSimulator")) == 0) {
::snprintf((char *)baton, PATH_MAX, "%s", filename);
- return FileSpec::eEnumerateDirectoryResultQuit;
+ return FileSystem::eEnumerateDirectoryResultQuit;
}
}
- return FileSpec::eEnumerateDirectoryResultNext;
+ return FileSystem::eEnumerateDirectoryResultNext;
}
const char *PlatformiOSSimulator::GetSDKDirectoryAsCString() {
@@ -282,9 +283,9 @@ const char *PlatformiOSSimulator::GetSDK
bool find_directories = true;
bool find_files = false;
bool find_other = false;
- FileSpec::EnumerateDirectory(sdks_directory, find_directories, find_files,
- find_other, EnumerateDirectoryCallback,
- sdk_dirname);
+ FileSystem::Instance().EnumerateDirectory(
+ sdks_directory, find_directories, find_files, find_other,
+ EnumerateDirectoryCallback, sdk_dirname);
if (sdk_dirname[0]) {
m_sdk_directory = sdks_directory;
Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=345800&r1=345799&r2=345800&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Wed Oct 31 17:33:27 2018
@@ -552,16 +552,17 @@ struct RecurseCopyBaton {
Status error;
};
-static FileSpec::EnumerateDirectoryResult
+static FileSystem::EnumerateDirectoryResult
RecurseCopy_Callback(void *baton, llvm::sys::fs::file_type ft,
- const FileSpec &src) {
+ llvm::StringRef path) {
RecurseCopyBaton *rc_baton = (RecurseCopyBaton *)baton;
+ FileSpec src(path, false);
namespace fs = llvm::sys::fs;
switch (ft) {
case fs::file_type::fifo_file:
case fs::file_type::socket_file:
// we have no way to copy pipes and sockets - ignore them and continue
- return FileSpec::eEnumerateDirectoryResultNext;
+ return FileSystem::eEnumerateDirectoryResultNext;
break;
case fs::file_type::directory_file: {
@@ -574,7 +575,7 @@ RecurseCopy_Callback(void *baton, llvm::
if (error.Fail()) {
rc_baton->error.SetErrorStringWithFormat(
"unable to setup directory %s on remote end", dst_dir.GetCString());
- return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
+ return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out
}
// now recurse
@@ -586,13 +587,13 @@ RecurseCopy_Callback(void *baton, llvm::
recurse_dst.GetDirectory().SetCString(dst_dir.GetPath().c_str());
RecurseCopyBaton rc_baton2 = {recurse_dst, rc_baton->platform_ptr,
Status()};
- FileSpec::EnumerateDirectory(src_dir_path, true, true, true,
- RecurseCopy_Callback, &rc_baton2);
+ FileSystem::Instance().EnumerateDirectory(src_dir_path, true, true, true,
+ RecurseCopy_Callback, &rc_baton2);
if (rc_baton2.error.Fail()) {
rc_baton->error.SetErrorString(rc_baton2.error.AsCString());
- return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
+ return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out
}
- return FileSpec::eEnumerateDirectoryResultNext;
+ return FileSystem::eEnumerateDirectoryResultNext;
} break;
case fs::file_type::symlink_file: {
@@ -606,15 +607,15 @@ RecurseCopy_Callback(void *baton, llvm::
rc_baton->error = FileSystem::Instance().Readlink(src, src_resolved);
if (rc_baton->error.Fail())
- return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
+ return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out
rc_baton->error =
rc_baton->platform_ptr->CreateSymlink(dst_file, src_resolved);
if (rc_baton->error.Fail())
- return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
+ return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out
- return FileSpec::eEnumerateDirectoryResultNext;
+ return FileSystem::eEnumerateDirectoryResultNext;
} break;
case fs::file_type::regular_file: {
@@ -625,15 +626,15 @@ RecurseCopy_Callback(void *baton, llvm::
Status err = rc_baton->platform_ptr->PutFile(src, dst_file);
if (err.Fail()) {
rc_baton->error.SetErrorString(err.AsCString());
- return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
+ return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out
}
- return FileSpec::eEnumerateDirectoryResultNext;
+ return FileSystem::eEnumerateDirectoryResultNext;
} break;
default:
rc_baton->error.SetErrorStringWithFormat(
"invalid file detected during copy: %s", src.GetPath().c_str());
- return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
+ return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out
break;
}
llvm_unreachable("Unhandled file_type!");
@@ -719,8 +720,8 @@ Status Platform::Install(const FileSpec
recurse_dst.GetDirectory().SetCString(fixed_dst.GetCString());
std::string src_dir_path(src.GetPath());
RecurseCopyBaton baton = {recurse_dst, this, Status()};
- FileSpec::EnumerateDirectory(src_dir_path, true, true, true,
- RecurseCopy_Callback, &baton);
+ FileSystem::Instance().EnumerateDirectory(
+ src_dir_path, true, true, true, RecurseCopy_Callback, &baton);
return baton.error;
}
} break;
Modified: lldb/trunk/source/Utility/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/FileSpec.cpp?rev=345800&r1=345799&r2=345800&view=diff
==============================================================================
--- lldb/trunk/source/Utility/FileSpec.cpp (original)
+++ lldb/trunk/source/Utility/FileSpec.cpp Wed Oct 31 17:33:27 2018
@@ -602,39 +602,6 @@ size_t FileSpec::MemorySize() const {
return m_filename.MemorySize() + m_directory.MemorySize();
}
-void FileSpec::EnumerateDirectory(llvm::StringRef dir_path,
- bool find_directories, bool find_files,
- bool find_other,
- EnumerateDirectoryCallbackType callback,
- void *callback_baton) {
- namespace fs = llvm::sys::fs;
- std::error_code EC;
- fs::recursive_directory_iterator Iter(dir_path, EC);
- fs::recursive_directory_iterator End;
- for (; Iter != End && !EC; Iter.increment(EC)) {
- const auto &Item = *Iter;
- llvm::ErrorOr<fs::basic_file_status> Status = Item.status();
- if (!Status)
- break;
- if (!find_files && fs::is_regular_file(*Status))
- continue;
- if (!find_directories && fs::is_directory(*Status))
- continue;
- if (!find_other && fs::is_other(*Status))
- continue;
-
- FileSpec Spec(Item.path(), false);
- auto Result = callback(callback_baton, Status->type(), Spec);
- if (Result == eEnumerateDirectoryResultQuit)
- return;
- if (Result == eEnumerateDirectoryResultNext) {
- // Default behavior is to recurse. Opt out if the callback doesn't want
- // this behavior.
- Iter.no_push();
- }
- }
-}
-
FileSpec
FileSpec::CopyByAppendingPathComponent(llvm::StringRef component) const {
FileSpec ret = *this;
More information about the lldb-commits
mailing list