Skip to content

Commit c172ffe

Browse files
committed
fixup! make sysroot member a FileSpec
1 parent 907b2f4 commit c172ffe

File tree

5 files changed

+26
-35
lines changed

5 files changed

+26
-35
lines changed

lldb/include/lldb/Utility/XcodeSDK.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLDB_UTILITY_SDK_H
1010
#define LLDB_UTILITY_SDK_H
1111

12+
#include "lldb/Utility/FileSpec.h"
1213
#include "lldb/lldb-forward.h"
1314
#include "llvm/ADT/StringRef.h"
1415
#include "llvm/Support/VersionTuple.h"
@@ -23,8 +24,7 @@ namespace lldb_private {
2324
/// An abstraction for Xcode-style SDKs that works like \ref ArchSpec.
2425
class XcodeSDK {
2526
std::string m_name;
26-
std::optional<std::string>
27-
m_sysroot_path; // TODO: should this be std::optional<FileSpec>?
27+
FileSpec m_sysroot;
2828

2929
public:
3030
/// Different types of Xcode SDKs.
@@ -64,8 +64,8 @@ class XcodeSDK {
6464
/// directory component of a path one would pass to clang's -isysroot
6565
/// parameter. For example, "MacOSX.10.14.sdk".
6666
XcodeSDK(std::string &&name) : m_name(std::move(name)) {}
67-
XcodeSDK(std::string name, std::string sysroot)
68-
: m_name(std::move(name)), m_sysroot_path(std::move(sysroot)) {}
67+
XcodeSDK(std::string name, FileSpec sysroot)
68+
: m_name(std::move(name)), m_sysroot(std::move(sysroot)) {}
6969
static XcodeSDK GetAnyMacOS() { return XcodeSDK("MacOSX.sdk"); }
7070

7171
/// The merge function follows a strict order to maintain monotonicity:
@@ -83,7 +83,7 @@ class XcodeSDK {
8383
llvm::VersionTuple GetVersion() const;
8484
Type GetType() const;
8585
llvm::StringRef GetString() const;
86-
std::optional<llvm::StringRef> GetSysroot() const;
86+
const FileSpec &GetSysroot() const;
8787
/// Whether this Xcode SDK supports Swift.
8888
bool SupportsSwift() const;
8989

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,6 @@ static Status ExceptionMaskValidator(const char *string, void *unused) {
7979
return {};
8080
}
8181

82-
static bool XcodeSysrootExists(XcodeSDK const &sdk) {
83-
auto maybe_sysroot = sdk.GetSysroot();
84-
if (!maybe_sysroot)
85-
return false;
86-
87-
return FileSystem::Instance().Exists(*maybe_sysroot);
88-
}
89-
9082
/// Destructor.
9183
///
9284
/// The destructor is virtual since this class is designed to be
@@ -1434,8 +1426,8 @@ PlatformDarwin::ResolveSDKPathFromDebugInfo(Module &module) {
14341426

14351427
auto [sdk, _] = std::move(*sdk_or_err);
14361428

1437-
if (XcodeSysrootExists(sdk))
1438-
return sdk.GetSysroot()->str();
1429+
if (FileSystem::Instance().Exists(sdk.GetSysroot()))
1430+
return sdk.GetSysroot().GetPath();
14391431

14401432
auto path_or_err = HostInfo::GetSDKRoot(HostInfo::SDKOptions{sdk});
14411433
if (!path_or_err)

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ XcodeSDK SymbolFileDWARF::ParseXcodeSDK(CompileUnit &comp_unit) {
10121012
local_module_sp->RegisterXcodeSDK(sdk, sysroot);
10131013
}
10141014

1015-
return {sdk, std::move(sysroot)};
1015+
return {sdk, FileSpec{std::move(sysroot)}};
10161016
}
10171017

10181018
size_t SymbolFileDWARF::ParseFunctions(CompileUnit &comp_unit) {

lldb/source/Utility/XcodeSDK.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ XcodeSDK::Type XcodeSDK::GetType() const {
142142

143143
llvm::StringRef XcodeSDK::GetString() const { return m_name; }
144144

145-
std::optional<llvm::StringRef> XcodeSDK::GetSysroot() const {
146-
return m_sysroot_path;
147-
}
145+
const FileSpec &XcodeSDK::GetSysroot() const { return m_sysroot; }
148146

149147
bool XcodeSDK::Info::operator<(const Info &other) const {
150148
return std::tie(type, version, internal) <
@@ -157,8 +155,8 @@ bool XcodeSDK::Info::operator==(const Info &other) const {
157155
}
158156

159157
void XcodeSDK::Merge(const XcodeSDK &other) {
160-
auto add_internal_sdk_suffix = [](std::string const &sdk) {
161-
return sdk.substr(0, sdk.size() - 3) + "Internal.sdk";
158+
auto add_internal_sdk_suffix = [](llvm::StringRef sdk) {
159+
return (sdk.substr(0, sdk.size() - 3) + "Internal.sdk").str();
162160
};
163161

164162
// The "bigger" SDK always wins.
@@ -172,8 +170,8 @@ void XcodeSDK::Merge(const XcodeSDK &other) {
172170
if (llvm::StringRef(m_name).ends_with(".sdk"))
173171
m_name = add_internal_sdk_suffix(m_name);
174172

175-
if (m_sysroot_path && llvm::StringRef(*m_sysroot_path).ends_with(".sdk"))
176-
m_sysroot_path.emplace(add_internal_sdk_suffix(*m_sysroot_path));
173+
if (m_sysroot.GetFileNameExtension() == ".sdk")
174+
m_sysroot.SetFilename(add_internal_sdk_suffix(m_sysroot.GetFilename()));
177175
}
178176
}
179177
}

lldb/unittests/Utility/XcodeSDKTest.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@ TEST(XcodeSDKTest, ParseTest) {
3434
EXPECT_EQ(XcodeSDK("MacOSX10.9.sdk").GetVersion(), llvm::VersionTuple(10, 9));
3535
EXPECT_EQ(XcodeSDK("MacOSX10.15.4.sdk").GetVersion(), llvm::VersionTuple(10, 15));
3636
EXPECT_EQ(XcodeSDK("MacOSX.sdk").IsAppleInternalSDK(), false);
37-
EXPECT_EQ(XcodeSDK("MacOSX.sdk", "/Path/To/MacOSX.sdk").GetSysroot(),
38-
"/Path/To/MacOSX.sdk");
37+
EXPECT_EQ(
38+
XcodeSDK("MacOSX.sdk", FileSpec{"/Path/To/MacOSX.sdk"}).GetSysroot(),
39+
FileSpec("/Path/To/MacOSX.sdk"));
3940
EXPECT_EQ(XcodeSDK("MacOSX10.15.Internal.sdk").GetType(), XcodeSDK::MacOSX);
4041
EXPECT_EQ(XcodeSDK("MacOSX10.15.Internal.sdk").GetVersion(),
4142
llvm::VersionTuple(10, 15));
4243
EXPECT_EQ(XcodeSDK("MacOSX10.15.Internal.sdk").IsAppleInternalSDK(), true);
43-
EXPECT_EQ(XcodeSDK("MacOSX10.15.Internal.sdk").GetSysroot(), std::nullopt);
44+
EXPECT_FALSE(XcodeSDK("MacOSX10.15.Internal.sdk").GetSysroot());
4445
EXPECT_EQ(XcodeSDK().GetType(), XcodeSDK::unknown);
4546
EXPECT_EQ(XcodeSDK().GetVersion(), llvm::VersionTuple());
46-
EXPECT_EQ(XcodeSDK().GetSysroot(), std::nullopt);
47+
EXPECT_FALSE(XcodeSDK().GetSysroot());
4748
}
4849

4950
TEST(XcodeSDKTest, MergeTest) {
@@ -64,14 +65,14 @@ TEST(XcodeSDKTest, MergeTest) {
6465
XcodeSDK empty;
6566
empty.Merge(XcodeSDK("MacOSX10.14.Internal.sdk"));
6667
EXPECT_EQ(empty.GetString(), llvm::StringRef("MacOSX10.14.Internal.sdk"));
67-
EXPECT_EQ(empty.GetSysroot(), std::nullopt);
68-
empty.Merge(XcodeSDK("MacOSX9.5.Internal.sdk", "/Path/To/9.5.sdk"));
69-
EXPECT_EQ(empty.GetSysroot(), std::nullopt);
70-
empty.Merge(XcodeSDK("MacOSX12.5.sdk", "/Path/To/12.5.sdk"));
71-
EXPECT_EQ(empty.GetSysroot(), "/Path/To/12.5.sdk");
72-
empty.Merge(
73-
XcodeSDK("MacOSX11.5.Internal.sdk", "/Path/To/12.5.Internal.sdk"));
74-
EXPECT_EQ(empty.GetSysroot(), "/Path/To/12.5.Internal.sdk");
68+
EXPECT_FALSE(empty.GetSysroot());
69+
empty.Merge(XcodeSDK("MacOSX9.5.Internal.sdk", FileSpec{"/Path/To/9.5.sdk"}));
70+
EXPECT_FALSE(empty.GetSysroot());
71+
empty.Merge(XcodeSDK("MacOSX12.5.sdk", FileSpec{"/Path/To/12.5.sdk"}));
72+
EXPECT_EQ(empty.GetSysroot(), FileSpec{"/Path/To/12.5.sdk"});
73+
empty.Merge(XcodeSDK("MacOSX11.5.Internal.sdk",
74+
FileSpec{"/Path/To/12.5.Internal.sdk"}));
75+
EXPECT_EQ(empty.GetSysroot(), FileSpec{"/Path/To/12.5.Internal.sdk"});
7576
}
7677

7778
#ifndef _WIN32

0 commit comments

Comments
 (0)