Skip to content

Commit b5cb04b

Browse files
authored
Merge pull request #10302 from swiftlang/jdevlieghere/rdar/146537366
[lldb] Fix layering violation between Host & Platform on the Swift fork
2 parents 09f3cd8 + bd8908c commit b5cb04b

File tree

9 files changed

+60
-71
lines changed

9 files changed

+60
-71
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/CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
set(SWIFT_SOURCES HostInfoMacOSXSwift.cpp)
22
set(LLVM_OPTIONAL_SOURCES ${SWIFT_SOURCES})
3-
if (NOT LLDB_ENABLE_SWIFT_SUPPORT)
4-
unset(SWIFT_SOURCES)
5-
set(PLUGIN_DEPENDENCY_ARG NO_PLUGIN_DEPENDENCIES)
6-
set(LLDB_PLUGIN_DEPENDENCIES)
7-
else()
8-
set(PLUGIN_DEPENDENCY_ARG)
9-
set(LLDB_PLUGIN_DEPENDENCIES lldbPluginPlatformMacOSX)
10-
endif()
113

124
remove_module_flags()
135
include_directories(..)
146

15-
add_lldb_library(lldbHostMacOSXObjCXX ${PLUGIN_DEPENDENCY_ARG}
7+
add_lldb_library(lldbHostMacOSXObjCXX NO_PLUGIN_DEPENDENCIES
168
Host.mm
179
HostInfoMacOSX.mm
1810
HostThreadMacOSX.mm
@@ -21,7 +13,6 @@ add_lldb_library(lldbHostMacOSXObjCXX ${PLUGIN_DEPENDENCY_ARG}
2113

2214
LINK_LIBS
2315
lldbUtility
24-
${LLDB_PLUGIN_DEPENDENCIES}
2516
${EXTRA_LIBS}
2617

2718
LINK_COMPONENTS

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/Host/macosx/objcxx/HostInfoMacOSXSwift.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ HostInfoMacOSX::GetSwiftResourceDir(llvm::Triple triple,
285285
platform_sdk_path, swift_stdlib_os_dir,
286286
HostInfo::GetSwiftResourceDir().GetPath(),
287287
HostInfo::GetXcodeContentsDirectory().GetPath(),
288-
PlatformDarwin::GetCurrentToolchainDirectory().GetPath(),
289-
PlatformDarwin::GetCurrentCommandLineToolsDirectory().GetPath());
288+
HostInfoMacOSX::GetCurrentXcodeToolchainDirectory().GetPath(),
289+
HostInfoMacOSX::GetCurrentCommandLineToolsDirectory().GetPath());
290290
g_resource_dir_cache.insert({key, value});
291291
return g_resource_dir_cache[key];
292292
}

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)