forked from OSchip/llvm-project
[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:
parent
011bf4f556
commit
173bb3c2eb
|
@ -172,15 +172,10 @@ bool PlatformRemoteAppleBridge::GetSupportedArchitectureAtIndex(uint32_t idx,
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
void PlatformRemoteAppleBridge::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames)
|
||||
{
|
||||
dirnames.clear();
|
||||
dirnames.push_back("BridgeOS DeviceSupport");
|
||||
llvm::StringRef PlatformRemoteAppleBridge::GetDeviceSupportDirectoryName() {
|
||||
return "BridgeOS DeviceSupport";
|
||||
}
|
||||
|
||||
std::string PlatformRemoteAppleBridge::GetPlatformName ()
|
||||
{
|
||||
return "BridgeOS.platform";
|
||||
llvm::StringRef PlatformRemoteAppleBridge::GetPlatformName() {
|
||||
return "BridgeOS.platform";
|
||||
}
|
||||
|
||||
|
|
|
@ -48,12 +48,8 @@ public:
|
|||
lldb_private::ArchSpec &arch) override;
|
||||
|
||||
protected:
|
||||
|
||||
// lldb_private::PlatformRemoteDarwinDevice functions
|
||||
|
||||
void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) override;
|
||||
|
||||
std::string GetPlatformName () override;
|
||||
llvm::StringRef GetDeviceSupportDirectoryName() override;
|
||||
llvm::StringRef GetPlatformName() override;
|
||||
};
|
||||
|
||||
#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEAPPLEBRIDGE_H
|
||||
|
|
|
@ -223,15 +223,10 @@ bool PlatformRemoteAppleTV::GetSupportedArchitectureAtIndex(uint32_t idx,
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
void PlatformRemoteAppleTV::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames)
|
||||
{
|
||||
dirnames.clear();
|
||||
dirnames.push_back("tvOS DeviceSupport");
|
||||
llvm::StringRef PlatformRemoteAppleTV::GetDeviceSupportDirectoryName() {
|
||||
return "tvOS DeviceSupport";
|
||||
}
|
||||
|
||||
std::string PlatformRemoteAppleTV::GetPlatformName ()
|
||||
{
|
||||
return "AppleTVOS.platform";
|
||||
llvm::StringRef PlatformRemoteAppleTV::GetPlatformName() {
|
||||
return "AppleTVOS.platform";
|
||||
}
|
||||
|
||||
|
|
|
@ -48,12 +48,8 @@ public:
|
|||
lldb_private::ArchSpec &arch) override;
|
||||
|
||||
protected:
|
||||
|
||||
// lldb_private::PlatformRemoteDarwinDevice functions
|
||||
|
||||
void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) override;
|
||||
|
||||
std::string GetPlatformName () override;
|
||||
llvm::StringRef GetDeviceSupportDirectoryName() override;
|
||||
llvm::StringRef GetPlatformName() override;
|
||||
};
|
||||
|
||||
#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEAPPLETV_H
|
||||
|
|
|
@ -298,13 +298,10 @@ bool PlatformRemoteAppleWatch::GetSupportedArchitectureAtIndex(uint32_t idx,
|
|||
return false;
|
||||
}
|
||||
|
||||
void PlatformRemoteAppleWatch::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames)
|
||||
{
|
||||
dirnames.clear();
|
||||
dirnames.push_back("watchOS DeviceSupport");
|
||||
llvm::StringRef PlatformRemoteAppleWatch::GetDeviceSupportDirectoryName() {
|
||||
return "watchOS DeviceSupport";
|
||||
}
|
||||
|
||||
std::string PlatformRemoteAppleWatch::GetPlatformName ()
|
||||
{
|
||||
return "WatchOS.platform";
|
||||
llvm::StringRef PlatformRemoteAppleWatch::GetPlatformName() {
|
||||
return "WatchOS.platform";
|
||||
}
|
||||
|
|
|
@ -51,12 +51,8 @@ public:
|
|||
lldb_private::ArchSpec &arch) override;
|
||||
|
||||
protected:
|
||||
|
||||
// lldb_private::PlatformRemoteDarwinDevice functions
|
||||
|
||||
void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) override;
|
||||
|
||||
std::string GetPlatformName () override;
|
||||
llvm::StringRef GetDeviceSupportDirectoryName() override;
|
||||
llvm::StringRef GetPlatformName() override;
|
||||
};
|
||||
|
||||
#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEAPPLEWATCH_H
|
||||
|
|
|
@ -197,42 +197,36 @@ bool PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded() {
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> device_support_dirnames;
|
||||
GetDeviceSupportDirectoryNames (device_support_dirnames);
|
||||
|
||||
for (std::string &dirname : device_support_dirnames)
|
||||
{
|
||||
const uint32_t num_installed = m_sdk_directory_infos.size();
|
||||
std::string local_sdk_cache_str = "~/Library/Developer/Xcode/";
|
||||
local_sdk_cache_str += dirname;
|
||||
FileSpec local_sdk_cache(local_sdk_cache_str.c_str());
|
||||
FileSystem::Instance().Resolve(local_sdk_cache);
|
||||
if (FileSystem::Instance().Exists(local_sdk_cache)) {
|
||||
if (log) {
|
||||
LLDB_LOGF(
|
||||
log,
|
||||
"PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded "
|
||||
"searching %s for additional SDKs",
|
||||
local_sdk_cache.GetPath().c_str());
|
||||
}
|
||||
char path[PATH_MAX];
|
||||
if (local_sdk_cache.GetPath(path, sizeof(path))) {
|
||||
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) {
|
||||
LLDB_LOGF(
|
||||
log,
|
||||
"PlatformRemoteDarwinDevice::"
|
||||
"UpdateSDKDirectoryInfosIfNeeded "
|
||||
"user SDK directory %s",
|
||||
m_sdk_directory_infos[i].directory.GetPath().c_str());
|
||||
}
|
||||
const uint32_t num_installed = m_sdk_directory_infos.size();
|
||||
llvm::StringRef dirname = GetDeviceSupportDirectoryName();
|
||||
std::string local_sdk_cache_str = "~/Library/Developer/Xcode/";
|
||||
local_sdk_cache_str += std::string(dirname);
|
||||
FileSpec local_sdk_cache(local_sdk_cache_str.c_str());
|
||||
FileSystem::Instance().Resolve(local_sdk_cache);
|
||||
if (FileSystem::Instance().Exists(local_sdk_cache)) {
|
||||
if (log) {
|
||||
LLDB_LOGF(
|
||||
log,
|
||||
"PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded "
|
||||
"searching %s for additional SDKs",
|
||||
local_sdk_cache.GetPath().c_str());
|
||||
}
|
||||
char path[PATH_MAX];
|
||||
if (local_sdk_cache.GetPath(path, sizeof(path))) {
|
||||
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) {
|
||||
LLDB_LOGF(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() {
|
||||
std::string platform_dir = "/Platforms/" + GetPlatformName() + "/DeviceSupport";
|
||||
std::string platform_dir =
|
||||
("/Platforms/" + GetPlatformName() + "/DeviceSupport").str();
|
||||
if (m_device_support_directory.empty()) {
|
||||
if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) {
|
||||
m_device_support_directory = fspec.GetPath();
|
||||
|
|
|
@ -97,10 +97,8 @@ protected:
|
|||
// UINT32_MAX if that SDK not found.
|
||||
uint32_t GetSDKIndexBySDKDirectoryInfo(const SDKDirectoryInfo *sdk_info);
|
||||
|
||||
|
||||
virtual void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) = 0;
|
||||
|
||||
virtual std::string GetPlatformName () = 0;
|
||||
virtual llvm::StringRef GetDeviceSupportDirectoryName() = 0;
|
||||
virtual llvm::StringRef GetPlatformName() = 0;
|
||||
|
||||
private:
|
||||
PlatformRemoteDarwinDevice(const PlatformRemoteDarwinDevice &) = delete;
|
||||
|
|
|
@ -143,14 +143,10 @@ bool PlatformRemoteiOS::GetSupportedArchitectureAtIndex(uint32_t idx,
|
|||
return ARMGetSupportedArchitectureAtIndex(idx, arch);
|
||||
}
|
||||
|
||||
|
||||
void PlatformRemoteiOS::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames)
|
||||
{
|
||||
dirnames.clear();
|
||||
dirnames.push_back("iOS DeviceSupport");
|
||||
llvm::StringRef PlatformRemoteiOS::GetDeviceSupportDirectoryName() {
|
||||
return "iOS DeviceSupport";
|
||||
}
|
||||
|
||||
std::string PlatformRemoteiOS::GetPlatformName ()
|
||||
{
|
||||
return "iPhoneOS.platform";
|
||||
llvm::StringRef PlatformRemoteiOS::GetPlatformName() {
|
||||
return "iPhoneOS.platform";
|
||||
}
|
||||
|
|
|
@ -47,12 +47,8 @@ public:
|
|||
lldb_private::ArchSpec &arch) override;
|
||||
|
||||
protected:
|
||||
|
||||
// lldb_private::PlatformRemoteDarwinDevice functions
|
||||
|
||||
void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) override;
|
||||
|
||||
std::string GetPlatformName () override;
|
||||
llvm::StringRef GetDeviceSupportDirectoryName() override;
|
||||
llvm::StringRef GetPlatformName() override;
|
||||
};
|
||||
|
||||
#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEIOS_H
|
||||
|
|
Loading…
Reference in New Issue