Skip to content

Commit a5b02a8

Browse files
committed
[lldb] Move two methods from Platfrom -> Host (NFC)
This moves two functions from Platform to Host: 1. GetCurrentXcodeToolchainDirectory 2. GetCurrentCommandLineToolsDirectory. These two functions caused a layering violation in the Swift fork, which added a dependency from lldbHost to lldbPlatform. As show by this PR, there's no need for these two functions to live in Platform, and we already have similar functions in Host. We have various layering violations but this one is particularly bad, because lldb-dap started depending on lldbHost. On the Swift fork, this library was depending on lldbPlatform which pulled in various Swift files, which libLLDB needs, but lldb-dap itself does not. We were missing RPATHs to resume them, so in the current nightly, lldb-dap crashes because the dynamic loader can't find the missing Swift libs. rdar://146537366
1 parent 029cb8a commit a5b02a8

File tree

7 files changed

+57
-59
lines changed

7 files changed

+57
-59
lines changed

lldb/include/lldb/Host/HostInfoBase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ class HostInfoBase {
126126

127127
static FileSpec GetXcodeContentsDirectory() { return {}; }
128128
static FileSpec GetXcodeDeveloperDirectory() { return {}; }
129+
static FileSpec GetCurrentXcodeToolchainDirectory() { return {}; }
130+
static FileSpec GetCurrentCommandLineToolsDirectory() { return {}; }
129131

130132
struct SDKOptions {
131133
std::optional<XcodeSDK> XcodeSDKSelection;

lldb/include/lldb/Host/macosx/HostInfoMacOSX.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class HostInfoMacOSX : public HostInfoPosix {
3030
static FileSpec GetProgramFileSpec();
3131
static FileSpec GetXcodeContentsDirectory();
3232
static FileSpec GetXcodeDeveloperDirectory();
33+
static FileSpec GetCurrentXcodeToolchainDirectory();
34+
static FileSpec GetCurrentCommandLineToolsDirectory();
3335

3436
/// Query xcrun to find an Xcode SDK directory.
3537
///
@@ -50,6 +52,9 @@ class HostInfoMacOSX : public HostInfoPosix {
5052
static bool ComputeHeaderDirectory(FileSpec &file_spec);
5153
static bool ComputeSystemPluginsDirectory(FileSpec &file_spec);
5254
static bool ComputeUserPluginsDirectory(FileSpec &file_spec);
55+
56+
static std::string FindComponentInPath(llvm::StringRef path,
57+
llvm::StringRef component);
5358
};
5459
}
5560

lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,33 @@ static bool ResolveAndVerifyCandidateSupportDir(FileSpec &path) {
393393
return g_developer_directory;
394394
}
395395

396+
std::string HostInfoMacOSX::FindComponentInPath(llvm::StringRef path,
397+
llvm::StringRef component) {
398+
auto begin = llvm::sys::path::begin(path);
399+
auto end = llvm::sys::path::end(path);
400+
for (auto it = begin; it != end; ++it) {
401+
if (it->contains(component)) {
402+
llvm::SmallString<128> buffer;
403+
llvm::sys::path::append(buffer, begin, ++it,
404+
llvm::sys::path::Style::posix);
405+
return buffer.str().str();
406+
}
407+
}
408+
return {};
409+
}
410+
411+
FileSpec HostInfoMacOSX::GetCurrentXcodeToolchainDirectory() {
412+
if (FileSpec fspec = HostInfo::GetShlibDir())
413+
return FileSpec(FindComponentInPath(fspec.GetPath(), ".xctoolchain"));
414+
return {};
415+
}
416+
417+
FileSpec HostInfoMacOSX::GetCurrentCommandLineToolsDirectory() {
418+
if (FileSpec fspec = HostInfo::GetShlibDir())
419+
return FileSpec(FindComponentInPath(fspec.GetPath(), "CommandLineTools"));
420+
return {};
421+
}
422+
396423
static llvm::Expected<std::string>
397424
xcrun(const std::string &sdk, llvm::ArrayRef<llvm::StringRef> arguments,
398425
llvm::StringRef developer_dir = "") {

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,33 +1337,6 @@ lldb_private::Status PlatformDarwin::FindBundleBinaryInExecSearchPaths(
13371337
return Status();
13381338
}
13391339

1340-
std::string PlatformDarwin::FindComponentInPath(llvm::StringRef path,
1341-
llvm::StringRef component) {
1342-
auto begin = llvm::sys::path::begin(path);
1343-
auto end = llvm::sys::path::end(path);
1344-
for (auto it = begin; it != end; ++it) {
1345-
if (it->contains(component)) {
1346-
llvm::SmallString<128> buffer;
1347-
llvm::sys::path::append(buffer, begin, ++it,
1348-
llvm::sys::path::Style::posix);
1349-
return buffer.str().str();
1350-
}
1351-
}
1352-
return {};
1353-
}
1354-
1355-
FileSpec PlatformDarwin::GetCurrentToolchainDirectory() {
1356-
if (FileSpec fspec = HostInfo::GetShlibDir())
1357-
return FileSpec(FindComponentInPath(fspec.GetPath(), ".xctoolchain"));
1358-
return {};
1359-
}
1360-
1361-
FileSpec PlatformDarwin::GetCurrentCommandLineToolsDirectory() {
1362-
if (FileSpec fspec = HostInfo::GetShlibDir())
1363-
return FileSpec(FindComponentInPath(fspec.GetPath(), "CommandLineTools"));
1364-
return {};
1365-
}
1366-
13671340
llvm::Triple::OSType PlatformDarwin::GetHostOSType() {
13681341
#if !defined(__APPLE__)
13691342
return llvm::Triple::MacOSX;

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,6 @@ class PlatformDarwin : public PlatformPOSIX {
117117
llvm::Expected<StructuredData::DictionarySP>
118118
FetchExtendedCrashInformation(Process &process) override;
119119

120-
/// Return the toolchain directory the current LLDB instance is located in.
121-
static FileSpec GetCurrentToolchainDirectory();
122-
123-
/// Return the command line tools directory the current LLDB instance is
124-
/// located in.
125-
static FileSpec GetCurrentCommandLineToolsDirectory();
126-
127120
llvm::Expected<std::pair<XcodeSDK, bool>>
128121
GetSDKPathFromDebugInfo(Module &module) override;
129122

@@ -199,9 +192,6 @@ class PlatformDarwin : public PlatformPOSIX {
199192
lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr,
200193
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr);
201194

202-
static std::string FindComponentInPath(llvm::StringRef path,
203-
llvm::StringRef component);
204-
205195
// The OSType where lldb is running.
206196
static llvm::Triple::OSType GetHostOSType();
207197

lldb/unittests/Host/HostInfoTest.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,26 @@ TEST(HostInfoTestInitialization, InitTwice) {
104104
EXPECT_EQ(Version, HostInfo::GetOSVersion());
105105
}
106106
}
107+
108+
#ifdef __APPLE__
109+
struct HostInfoTester : public HostInfoMacOSX {
110+
public:
111+
using HostInfoMacOSX::FindComponentInPath;
112+
};
113+
114+
TEST_F(HostInfoTest, FindComponentInPath) {
115+
EXPECT_EQ("/path/to/foo",
116+
HostInfoTester::FindComponentInPath("/path/to/foo/", "foo"));
117+
118+
EXPECT_EQ("/path/to/foo",
119+
HostInfoTester::FindComponentInPath("/path/to/foo", "foo"));
120+
121+
EXPECT_EQ("/path/to/foobar",
122+
HostInfoTester::FindComponentInPath("/path/to/foobar", "foo"));
123+
124+
EXPECT_EQ("/path/to/foobar",
125+
HostInfoTester::FindComponentInPath("/path/to/foobar", "bar"));
126+
127+
EXPECT_EQ("", HostInfoTester::FindComponentInPath("/path/to/foo", "bar"));
128+
}
129+
#endif

lldb/unittests/Platform/PlatformDarwinTest.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
using namespace lldb;
1818
using namespace lldb_private;
1919

20-
struct PlatformDarwinTester : public PlatformDarwin {
21-
public:
22-
using PlatformDarwin::FindComponentInPath;
23-
};
24-
2520
TEST(PlatformDarwinTest, TestParseVersionBuildDir) {
2621
llvm::VersionTuple V;
2722
llvm::StringRef D;
@@ -49,20 +44,3 @@ TEST(PlatformDarwinTest, TestParseVersionBuildDir) {
4944
std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("3.4.5");
5045
EXPECT_EQ(llvm::VersionTuple(3, 4, 5), V);
5146
}
52-
53-
TEST(PlatformDarwinTest, FindComponentInPath) {
54-
EXPECT_EQ("/path/to/foo",
55-
PlatformDarwinTester::FindComponentInPath("/path/to/foo/", "foo"));
56-
57-
EXPECT_EQ("/path/to/foo",
58-
PlatformDarwinTester::FindComponentInPath("/path/to/foo", "foo"));
59-
60-
EXPECT_EQ("/path/to/foobar", PlatformDarwinTester::FindComponentInPath(
61-
"/path/to/foobar", "foo"));
62-
63-
EXPECT_EQ("/path/to/foobar", PlatformDarwinTester::FindComponentInPath(
64-
"/path/to/foobar", "bar"));
65-
66-
EXPECT_EQ("",
67-
PlatformDarwinTester::FindComponentInPath("/path/to/foo", "bar"));
68-
}

0 commit comments

Comments
 (0)