Modernize Platform::GetOSKernelDescription

This commit is contained in:
Pavel Labath 2021-10-26 10:52:39 +02:00
parent b9e3af124b
commit f5158ca48c
9 changed files with 28 additions and 37 deletions

View File

@ -214,7 +214,7 @@ public:
llvm::Optional<std::string> GetOSBuildString();
bool GetOSKernelDescription(std::string &s);
llvm::Optional<std::string> GetOSKernelDescription();
// Returns the name of the platform
ConstString GetName();
@ -244,9 +244,8 @@ public:
return llvm::None;
}
virtual bool GetRemoteOSKernelDescription(std::string &s) {
s.clear();
return false;
virtual llvm::Optional<std::string> GetRemoteOSKernelDescription() {
return llvm::None;
}
// Remote Platform subclasses need to override this function

View File

@ -65,7 +65,7 @@ public:
bool GetRemoteOSVersion() override;
llvm::Optional<std::string> GetRemoteOSBuildString() override;
bool GetRemoteOSKernelDescription(std::string &s) override;
llvm::Optional<std::string> GetRemoteOSKernelDescription() override;
ArchSpec GetRemoteSystemArchitecture() override;
Status RunShellCommand(llvm::StringRef command, const FileSpec &working_dir,

View File

@ -473,13 +473,11 @@ const char *SBPlatform::GetOSDescription() {
PlatformSP platform_sp(GetSP());
if (platform_sp) {
std::string s;
if (platform_sp->GetOSKernelDescription(s)) {
if (!s.empty()) {
// Const-ify the string so we don't need to worry about the lifetime of
// the string
return ConstString(s.c_str()).GetCString();
}
std::string s = platform_sp->GetOSKernelDescription().getValueOr("");
if (!s.empty()) {
// Const-ify the string so we don't need to worry about the lifetime of
// the string
return ConstString(s.c_str()).GetCString();
}
}
return nullptr;

View File

@ -240,8 +240,9 @@ llvm::Optional<std::string> PlatformRemoteGDBServer::GetRemoteOSBuildString() {
return m_gdb_client.GetOSBuildString();
}
bool PlatformRemoteGDBServer::GetRemoteOSKernelDescription(std::string &s) {
return m_gdb_client.GetOSKernelDescription(s);
llvm::Optional<std::string>
PlatformRemoteGDBServer::GetRemoteOSKernelDescription() {
return m_gdb_client.GetOSKernelDescription();
}
// Remote Platform subclasses need to override this function

View File

@ -79,7 +79,7 @@ public:
llvm::Optional<std::string> GetRemoteOSBuildString() override;
bool GetRemoteOSKernelDescription(std::string &s) override;
llvm::Optional<std::string> GetRemoteOSKernelDescription() override;
// Remote Platform subclasses need to override this function
ArchSpec GetRemoteSystemArchitecture() override;

View File

@ -978,15 +978,13 @@ llvm::Optional<std::string> GDBRemoteCommunicationClient::GetOSBuildString() {
return llvm::None;
}
bool GDBRemoteCommunicationClient::GetOSKernelDescription(std::string &s) {
llvm::Optional<std::string>
GDBRemoteCommunicationClient::GetOSKernelDescription() {
if (GetHostInfo()) {
if (!m_os_kernel.empty()) {
s = m_os_kernel;
return true;
}
if (!m_os_kernel.empty())
return m_os_kernel;
}
s.clear();
return false;
return llvm::None;
}
bool GDBRemoteCommunicationClient::GetHostname(std::string &s) {

View File

@ -241,7 +241,7 @@ public:
llvm::Optional<std::string> GetOSBuildString();
bool GetOSKernelDescription(std::string &s);
llvm::Optional<std::string> GetOSKernelDescription();
ArchSpec GetSystemArchitecture();

View File

@ -439,9 +439,8 @@ void Platform::GetStatus(Stream &strm) {
if (!specific_info.empty())
strm.Printf("Platform-specific connection: %s\n", specific_info.c_str());
std::string s;
if (GetOSKernelDescription(s))
strm.Printf(" Kernel: %s\n", s.c_str());
if (llvm::Optional<std::string> s = GetOSKernelDescription())
strm.Format(" Kernel: {0}\n", *s);
}
llvm::VersionTuple Platform::GetOSVersion(Process *process) {
@ -492,13 +491,10 @@ llvm::Optional<std::string> Platform::GetOSBuildString() {
return GetRemoteOSBuildString();
}
bool Platform::GetOSKernelDescription(std::string &s) {
if (IsHost()) {
llvm::Optional<std::string> desc = HostInfo::GetOSKernelDescription();
s = desc.getValueOr("");
return desc.hasValue();
}
return GetRemoteOSKernelDescription(s);
llvm::Optional<std::string> Platform::GetOSKernelDescription() {
if (IsHost())
return HostInfo::GetOSKernelDescription();
return GetRemoteOSKernelDescription();
}
void Platform::AddClangModuleCompilationOptions(

View File

@ -338,11 +338,10 @@ llvm::Optional<std::string> RemoteAwarePlatform::GetRemoteOSBuildString() {
return llvm::None;
}
bool RemoteAwarePlatform::GetRemoteOSKernelDescription(std::string &s) {
llvm::Optional<std::string> RemoteAwarePlatform::GetRemoteOSKernelDescription() {
if (m_remote_platform_sp)
return m_remote_platform_sp->GetRemoteOSKernelDescription(s);
s.clear();
return false;
return m_remote_platform_sp->GetRemoteOSKernelDescription();
return llvm::None;
}
ArchSpec RemoteAwarePlatform::GetRemoteSystemArchitecture() {