forked from OSchip/llvm-project
[lldb/PlatformDarwin] Expose current toolchain and CL tools directory
Expose two methods to find the current toolchain and the current command line tools directory. These are used by Swift to find the resource directory.
This commit is contained in:
parent
14970669dd
commit
5ffb30fd6c
|
@ -1829,6 +1829,21 @@ 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 {};
|
||||
}
|
||||
|
||||
std::string
|
||||
PlatformDarwin::FindXcodeContentsDirectoryInPath(llvm::StringRef path) {
|
||||
auto begin = llvm::sys::path::begin(path);
|
||||
|
@ -1959,3 +1974,15 @@ FileSpec PlatformDarwin::GetXcodeContentsDirectory() {
|
|||
});
|
||||
return g_xcode_contents_path;
|
||||
}
|
||||
|
||||
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 {};
|
||||
}
|
||||
|
|
|
@ -100,6 +100,13 @@ public:
|
|||
static lldb_private::FileSpec GetXcodeSDK(SDKType type);
|
||||
static lldb_private::FileSpec GetXcodeContentsDirectory();
|
||||
|
||||
/// Return the toolchain directroy the current LLDB instance is located in.
|
||||
static lldb_private::FileSpec GetCurrentToolchainDirectory();
|
||||
|
||||
/// Return the command line tools directory the current LLDB instance is
|
||||
/// located in.
|
||||
static lldb_private::FileSpec GetCurrentCommandLineToolsDirectory();
|
||||
|
||||
protected:
|
||||
struct CrashInfoAnnotations {
|
||||
uint64_t version; // unsigned long
|
||||
|
@ -172,6 +179,8 @@ protected:
|
|||
const lldb_private::FileSpecList *module_search_paths_ptr,
|
||||
lldb::ModuleSP *old_module_sp_ptr, bool *did_create_ptr);
|
||||
|
||||
static std::string FindComponentInPath(llvm::StringRef path,
|
||||
llvm::StringRef component);
|
||||
static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path);
|
||||
|
||||
std::string m_developer_directory;
|
||||
|
|
|
@ -19,6 +19,7 @@ using namespace lldb_private;
|
|||
|
||||
struct PlatformDarwinTester : public PlatformDarwin {
|
||||
public:
|
||||
using PlatformDarwin::FindComponentInPath;
|
||||
using PlatformDarwin::FindXcodeContentsDirectoryInPath;
|
||||
static bool SDKSupportsModules(SDKType desired_type,
|
||||
const lldb_private::FileSpec &sdk_path) {
|
||||
|
@ -132,3 +133,20 @@ TEST(PlatformDarwinTest, GetSDKNameForType) {
|
|||
EXPECT_EQ(
|
||||
"", PlatformDarwin::GetSDKNameForType(PlatformDarwin::SDKType::unknown));
|
||||
}
|
||||
|
||||
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"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue