Skip to content

Commit 1667d2e

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 (cherry picked from commit a5b02a8)
1 parent 015571a commit 1667d2e

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
#ifdef LLDB_ENABLE_SWIFT
130132
static FileSpec GetSwiftResourceDir() { return {}; }
131133
static FileSpec GetSwiftResourceDir(llvm::Triple triple) { return {}; }

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
#ifdef LLDB_ENABLE_SWIFT
3537
static FileSpec GetSwiftResourceDir();
@@ -72,6 +74,9 @@ class HostInfoMacOSX : public HostInfoPosix {
7274
static bool ComputeHeaderDirectory(FileSpec &file_spec);
7375
static bool ComputeSystemPluginsDirectory(FileSpec &file_spec);
7476
static bool ComputeUserPluginsDirectory(FileSpec &file_spec);
77+
78+
static std::string FindComponentInPath(llvm::StringRef path,
79+
llvm::StringRef component);
7580
};
7681
}
7782

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,33 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
379379
return g_developer_directory;
380380
}
381381

382+
std::string HostInfoMacOSX::FindComponentInPath(llvm::StringRef path,
383+
llvm::StringRef component) {
384+
auto begin = llvm::sys::path::begin(path);
385+
auto end = llvm::sys::path::end(path);
386+
for (auto it = begin; it != end; ++it) {
387+
if (it->contains(component)) {
388+
llvm::SmallString<128> buffer;
389+
llvm::sys::path::append(buffer, begin, ++it,
390+
llvm::sys::path::Style::posix);
391+
return buffer.str().str();
392+
}
393+
}
394+
return {};
395+
}
396+
397+
FileSpec HostInfoMacOSX::GetCurrentXcodeToolchainDirectory() {
398+
if (FileSpec fspec = HostInfo::GetShlibDir())
399+
return FileSpec(FindComponentInPath(fspec.GetPath(), ".xctoolchain"));
400+
return {};
401+
}
402+
403+
FileSpec HostInfoMacOSX::GetCurrentCommandLineToolsDirectory() {
404+
if (FileSpec fspec = HostInfo::GetShlibDir())
405+
return FileSpec(FindComponentInPath(fspec.GetPath(), "CommandLineTools"));
406+
return {};
407+
}
408+
382409
static llvm::Expected<std::string>
383410
xcrun(const std::string &sdk, llvm::ArrayRef<llvm::StringRef> arguments,
384411
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
@@ -1332,33 +1332,6 @@ lldb_private::Status PlatformDarwin::FindBundleBinaryInExecSearchPaths(
13321332
return Status();
13331333
}
13341334

1335-
std::string PlatformDarwin::FindComponentInPath(llvm::StringRef path,
1336-
llvm::StringRef component) {
1337-
auto begin = llvm::sys::path::begin(path);
1338-
auto end = llvm::sys::path::end(path);
1339-
for (auto it = begin; it != end; ++it) {
1340-
if (it->contains(component)) {
1341-
llvm::SmallString<128> buffer;
1342-
llvm::sys::path::append(buffer, begin, ++it,
1343-
llvm::sys::path::Style::posix);
1344-
return buffer.str().str();
1345-
}
1346-
}
1347-
return {};
1348-
}
1349-
1350-
FileSpec PlatformDarwin::GetCurrentToolchainDirectory() {
1351-
if (FileSpec fspec = HostInfo::GetShlibDir())
1352-
return FileSpec(FindComponentInPath(fspec.GetPath(), ".xctoolchain"));
1353-
return {};
1354-
}
1355-
1356-
FileSpec PlatformDarwin::GetCurrentCommandLineToolsDirectory() {
1357-
if (FileSpec fspec = HostInfo::GetShlibDir())
1358-
return FileSpec(FindComponentInPath(fspec.GetPath(), "CommandLineTools"));
1359-
return {};
1360-
}
1361-
13621335
llvm::Triple::OSType PlatformDarwin::GetHostOSType() {
13631336
#if !defined(__APPLE__)
13641337
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)