Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lldb/include/lldb/Host/HostInfoBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ class HostInfoBase {

static FileSpec GetXcodeContentsDirectory() { return {}; }
static FileSpec GetXcodeDeveloperDirectory() { return {}; }
static FileSpec GetCurrentXcodeToolchainDirectory() { return {}; }
static FileSpec GetCurrentCommandLineToolsDirectory() { return {}; }

struct SDKOptions {
std::optional<XcodeSDK> XcodeSDKSelection;
Expand Down
5 changes: 5 additions & 0 deletions lldb/include/lldb/Host/macosx/HostInfoMacOSX.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class HostInfoMacOSX : public HostInfoPosix {
static FileSpec GetProgramFileSpec();
static FileSpec GetXcodeContentsDirectory();
static FileSpec GetXcodeDeveloperDirectory();
static FileSpec GetCurrentXcodeToolchainDirectory();
static FileSpec GetCurrentCommandLineToolsDirectory();

/// Query xcrun to find an Xcode SDK directory.
///
Expand All @@ -50,6 +52,9 @@ class HostInfoMacOSX : public HostInfoPosix {
static bool ComputeHeaderDirectory(FileSpec &file_spec);
static bool ComputeSystemPluginsDirectory(FileSpec &file_spec);
static bool ComputeUserPluginsDirectory(FileSpec &file_spec);

static std::string FindComponentInPath(llvm::StringRef path,
llvm::StringRef component);
};
}

Expand Down
27 changes: 27 additions & 0 deletions lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,33 @@ static bool ResolveAndVerifyCandidateSupportDir(FileSpec &path) {
return g_developer_directory;
}

std::string HostInfoMacOSX::FindComponentInPath(llvm::StringRef path,
llvm::StringRef component) {
auto begin = llvm::sys::path::begin(path);
auto end = llvm::sys::path::end(path);
for (auto it = begin; it != end; ++it) {
if (it->contains(component)) {
llvm::SmallString<128> buffer;
llvm::sys::path::append(buffer, begin, ++it,
llvm::sys::path::Style::posix);
return buffer.str().str();
}
}
return {};
}

FileSpec HostInfoMacOSX::GetCurrentXcodeToolchainDirectory() {
if (FileSpec fspec = HostInfo::GetShlibDir())
return FileSpec(FindComponentInPath(fspec.GetPath(), ".xctoolchain"));
return {};
}

FileSpec HostInfoMacOSX::GetCurrentCommandLineToolsDirectory() {
if (FileSpec fspec = HostInfo::GetShlibDir())
return FileSpec(FindComponentInPath(fspec.GetPath(), "CommandLineTools"));
return {};
}

static llvm::Expected<std::string>
xcrun(const std::string &sdk, llvm::ArrayRef<llvm::StringRef> arguments,
llvm::StringRef developer_dir = "") {
Expand Down
27 changes: 0 additions & 27 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1337,33 +1337,6 @@ lldb_private::Status PlatformDarwin::FindBundleBinaryInExecSearchPaths(
return Status();
}

std::string PlatformDarwin::FindComponentInPath(llvm::StringRef path,
llvm::StringRef component) {
auto begin = llvm::sys::path::begin(path);
auto end = llvm::sys::path::end(path);
for (auto it = begin; it != end; ++it) {
if (it->contains(component)) {
llvm::SmallString<128> buffer;
llvm::sys::path::append(buffer, begin, ++it,
llvm::sys::path::Style::posix);
return buffer.str().str();
}
}
return {};
}

FileSpec PlatformDarwin::GetCurrentToolchainDirectory() {
if (FileSpec fspec = HostInfo::GetShlibDir())
return FileSpec(FindComponentInPath(fspec.GetPath(), ".xctoolchain"));
return {};
}

FileSpec PlatformDarwin::GetCurrentCommandLineToolsDirectory() {
if (FileSpec fspec = HostInfo::GetShlibDir())
return FileSpec(FindComponentInPath(fspec.GetPath(), "CommandLineTools"));
return {};
}

llvm::Triple::OSType PlatformDarwin::GetHostOSType() {
#if !defined(__APPLE__)
return llvm::Triple::MacOSX;
Expand Down
10 changes: 0 additions & 10 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,6 @@ class PlatformDarwin : public PlatformPOSIX {
llvm::Expected<StructuredData::DictionarySP>
FetchExtendedCrashInformation(Process &process) override;

/// Return the toolchain directory the current LLDB instance is located in.
static FileSpec GetCurrentToolchainDirectory();

/// Return the command line tools directory the current LLDB instance is
/// located in.
static FileSpec GetCurrentCommandLineToolsDirectory();

llvm::Expected<std::pair<XcodeSDK, bool>>
GetSDKPathFromDebugInfo(Module &module) override;

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

static std::string FindComponentInPath(llvm::StringRef path,
llvm::StringRef component);

// The OSType where lldb is running.
static llvm::Triple::OSType GetHostOSType();

Expand Down
23 changes: 23 additions & 0 deletions lldb/unittests/Host/HostInfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,26 @@ TEST(HostInfoTestInitialization, InitTwice) {
EXPECT_EQ(Version, HostInfo::GetOSVersion());
}
}

#ifdef __APPLE__
struct HostInfoTester : public HostInfoMacOSX {
public:
using HostInfoMacOSX::FindComponentInPath;
};

TEST_F(HostInfoTest, FindComponentInPath) {
EXPECT_EQ("/path/to/foo",
HostInfoTester::FindComponentInPath("/path/to/foo/", "foo"));

EXPECT_EQ("/path/to/foo",
HostInfoTester::FindComponentInPath("/path/to/foo", "foo"));

EXPECT_EQ("/path/to/foobar",
HostInfoTester::FindComponentInPath("/path/to/foobar", "foo"));

EXPECT_EQ("/path/to/foobar",
HostInfoTester::FindComponentInPath("/path/to/foobar", "bar"));

EXPECT_EQ("", HostInfoTester::FindComponentInPath("/path/to/foo", "bar"));
}
#endif
22 changes: 0 additions & 22 deletions lldb/unittests/Platform/PlatformDarwinTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
using namespace lldb;
using namespace lldb_private;

struct PlatformDarwinTester : public PlatformDarwin {
public:
using PlatformDarwin::FindComponentInPath;
};

TEST(PlatformDarwinTest, TestParseVersionBuildDir) {
llvm::VersionTuple V;
llvm::StringRef D;
Expand Down Expand Up @@ -49,20 +44,3 @@ TEST(PlatformDarwinTest, TestParseVersionBuildDir) {
std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("3.4.5");
EXPECT_EQ(llvm::VersionTuple(3, 4, 5), V);
}

TEST(PlatformDarwinTest, FindComponentInPath) {
EXPECT_EQ("/path/to/foo",
PlatformDarwinTester::FindComponentInPath("/path/to/foo/", "foo"));

EXPECT_EQ("/path/to/foo",
PlatformDarwinTester::FindComponentInPath("/path/to/foo", "foo"));

EXPECT_EQ("/path/to/foobar", PlatformDarwinTester::FindComponentInPath(
"/path/to/foobar", "foo"));

EXPECT_EQ("/path/to/foobar", PlatformDarwinTester::FindComponentInPath(
"/path/to/foobar", "bar"));

EXPECT_EQ("",
PlatformDarwinTester::FindComponentInPath("/path/to/foo", "bar"));
}