[lldb] Refactor GetDeviceSupportDirectoryNames and GetPlatformName (NFC)

Both functions are effectively returning a single string literal. Change
the interface to return a llvm::StringRef instead of populating a vector
of std::strings or returning a std::string respectively.
This commit is contained in:
Jonas Devlieghere 2020-11-30 15:18:24 -08:00
parent 011bf4f556
commit 173bb3c2eb
10 changed files with 58 additions and 98 deletions

View File

@ -172,15 +172,10 @@ bool PlatformRemoteAppleBridge::GetSupportedArchitectureAtIndex(uint32_t idx,
return false; return false;
} }
llvm::StringRef PlatformRemoteAppleBridge::GetDeviceSupportDirectoryName() {
void PlatformRemoteAppleBridge::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) return "BridgeOS DeviceSupport";
{
dirnames.clear();
dirnames.push_back("BridgeOS DeviceSupport");
} }
std::string PlatformRemoteAppleBridge::GetPlatformName () llvm::StringRef PlatformRemoteAppleBridge::GetPlatformName() {
{ return "BridgeOS.platform";
return "BridgeOS.platform";
} }

View File

@ -48,12 +48,8 @@ public:
lldb_private::ArchSpec &arch) override; lldb_private::ArchSpec &arch) override;
protected: protected:
llvm::StringRef GetDeviceSupportDirectoryName() override;
// lldb_private::PlatformRemoteDarwinDevice functions llvm::StringRef GetPlatformName() override;
void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) override;
std::string GetPlatformName () override;
}; };
#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEAPPLEBRIDGE_H #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEAPPLEBRIDGE_H

View File

@ -223,15 +223,10 @@ bool PlatformRemoteAppleTV::GetSupportedArchitectureAtIndex(uint32_t idx,
return false; return false;
} }
llvm::StringRef PlatformRemoteAppleTV::GetDeviceSupportDirectoryName() {
void PlatformRemoteAppleTV::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) return "tvOS DeviceSupport";
{
dirnames.clear();
dirnames.push_back("tvOS DeviceSupport");
} }
std::string PlatformRemoteAppleTV::GetPlatformName () llvm::StringRef PlatformRemoteAppleTV::GetPlatformName() {
{ return "AppleTVOS.platform";
return "AppleTVOS.platform";
} }

View File

@ -48,12 +48,8 @@ public:
lldb_private::ArchSpec &arch) override; lldb_private::ArchSpec &arch) override;
protected: protected:
llvm::StringRef GetDeviceSupportDirectoryName() override;
// lldb_private::PlatformRemoteDarwinDevice functions llvm::StringRef GetPlatformName() override;
void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) override;
std::string GetPlatformName () override;
}; };
#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEAPPLETV_H #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEAPPLETV_H

View File

@ -298,13 +298,10 @@ bool PlatformRemoteAppleWatch::GetSupportedArchitectureAtIndex(uint32_t idx,
return false; return false;
} }
void PlatformRemoteAppleWatch::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) llvm::StringRef PlatformRemoteAppleWatch::GetDeviceSupportDirectoryName() {
{ return "watchOS DeviceSupport";
dirnames.clear();
dirnames.push_back("watchOS DeviceSupport");
} }
std::string PlatformRemoteAppleWatch::GetPlatformName () llvm::StringRef PlatformRemoteAppleWatch::GetPlatformName() {
{ return "WatchOS.platform";
return "WatchOS.platform";
} }

View File

@ -51,12 +51,8 @@ public:
lldb_private::ArchSpec &arch) override; lldb_private::ArchSpec &arch) override;
protected: protected:
llvm::StringRef GetDeviceSupportDirectoryName() override;
// lldb_private::PlatformRemoteDarwinDevice functions llvm::StringRef GetPlatformName() override;
void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) override;
std::string GetPlatformName () override;
}; };
#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEAPPLEWATCH_H #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEAPPLEWATCH_H

View File

@ -197,42 +197,36 @@ bool PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded() {
} }
} }
std::vector<std::string> device_support_dirnames; const uint32_t num_installed = m_sdk_directory_infos.size();
GetDeviceSupportDirectoryNames (device_support_dirnames); llvm::StringRef dirname = GetDeviceSupportDirectoryName();
std::string local_sdk_cache_str = "~/Library/Developer/Xcode/";
for (std::string &dirname : device_support_dirnames) local_sdk_cache_str += std::string(dirname);
{ FileSpec local_sdk_cache(local_sdk_cache_str.c_str());
const uint32_t num_installed = m_sdk_directory_infos.size(); FileSystem::Instance().Resolve(local_sdk_cache);
std::string local_sdk_cache_str = "~/Library/Developer/Xcode/"; if (FileSystem::Instance().Exists(local_sdk_cache)) {
local_sdk_cache_str += dirname; if (log) {
FileSpec local_sdk_cache(local_sdk_cache_str.c_str()); LLDB_LOGF(
FileSystem::Instance().Resolve(local_sdk_cache); log,
if (FileSystem::Instance().Exists(local_sdk_cache)) { "PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded "
if (log) { "searching %s for additional SDKs",
LLDB_LOGF( local_sdk_cache.GetPath().c_str());
log, }
"PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded " char path[PATH_MAX];
"searching %s for additional SDKs", if (local_sdk_cache.GetPath(path, sizeof(path))) {
local_sdk_cache.GetPath().c_str()); FileSystem::Instance().EnumerateDirectory(
} path, find_directories, find_files, find_other,
char path[PATH_MAX]; GetContainedFilesIntoVectorOfStringsCallback,
if (local_sdk_cache.GetPath(path, sizeof(path))) { &m_sdk_directory_infos);
FileSystem::Instance().EnumerateDirectory( const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
path, find_directories, find_files, find_other, // First try for an exact match of major, minor and update
GetContainedFilesIntoVectorOfStringsCallback, for (uint32_t i = num_installed; i < num_sdk_infos; ++i) {
&m_sdk_directory_infos); m_sdk_directory_infos[i].user_cached = true;
const uint32_t num_sdk_infos = m_sdk_directory_infos.size(); if (log) {
// First try for an exact match of major, minor and update LLDB_LOGF(log,
for (uint32_t i = num_installed; i < num_sdk_infos; ++i) { "PlatformRemoteDarwinDevice::"
m_sdk_directory_infos[i].user_cached = true; "UpdateSDKDirectoryInfosIfNeeded "
if (log) { "user SDK directory %s",
LLDB_LOGF( m_sdk_directory_infos[i].directory.GetPath().c_str());
log,
"PlatformRemoteDarwinDevice::"
"UpdateSDKDirectoryInfosIfNeeded "
"user SDK directory %s",
m_sdk_directory_infos[i].directory.GetPath().c_str());
}
} }
} }
} }
@ -341,7 +335,8 @@ PlatformRemoteDarwinDevice::GetSDKDirectoryForLatestOSVersion() {
} }
const char *PlatformRemoteDarwinDevice::GetDeviceSupportDirectory() { const char *PlatformRemoteDarwinDevice::GetDeviceSupportDirectory() {
std::string platform_dir = "/Platforms/" + GetPlatformName() + "/DeviceSupport"; std::string platform_dir =
("/Platforms/" + GetPlatformName() + "/DeviceSupport").str();
if (m_device_support_directory.empty()) { if (m_device_support_directory.empty()) {
if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) { if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) {
m_device_support_directory = fspec.GetPath(); m_device_support_directory = fspec.GetPath();

View File

@ -97,10 +97,8 @@ protected:
// UINT32_MAX if that SDK not found. // UINT32_MAX if that SDK not found.
uint32_t GetSDKIndexBySDKDirectoryInfo(const SDKDirectoryInfo *sdk_info); uint32_t GetSDKIndexBySDKDirectoryInfo(const SDKDirectoryInfo *sdk_info);
virtual llvm::StringRef GetDeviceSupportDirectoryName() = 0;
virtual void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) = 0; virtual llvm::StringRef GetPlatformName() = 0;
virtual std::string GetPlatformName () = 0;
private: private:
PlatformRemoteDarwinDevice(const PlatformRemoteDarwinDevice &) = delete; PlatformRemoteDarwinDevice(const PlatformRemoteDarwinDevice &) = delete;

View File

@ -143,14 +143,10 @@ bool PlatformRemoteiOS::GetSupportedArchitectureAtIndex(uint32_t idx,
return ARMGetSupportedArchitectureAtIndex(idx, arch); return ARMGetSupportedArchitectureAtIndex(idx, arch);
} }
llvm::StringRef PlatformRemoteiOS::GetDeviceSupportDirectoryName() {
void PlatformRemoteiOS::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) return "iOS DeviceSupport";
{
dirnames.clear();
dirnames.push_back("iOS DeviceSupport");
} }
std::string PlatformRemoteiOS::GetPlatformName () llvm::StringRef PlatformRemoteiOS::GetPlatformName() {
{ return "iPhoneOS.platform";
return "iPhoneOS.platform";
} }

View File

@ -47,12 +47,8 @@ public:
lldb_private::ArchSpec &arch) override; lldb_private::ArchSpec &arch) override;
protected: protected:
llvm::StringRef GetDeviceSupportDirectoryName() override;
// lldb_private::PlatformRemoteDarwinDevice functions llvm::StringRef GetPlatformName() override;
void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) override;
std::string GetPlatformName () override;
}; };
#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEIOS_H #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEIOS_H