diff --git a/lldb/include/lldb/Host/HostInfoBase.h b/lldb/include/lldb/Host/HostInfoBase.h index f1789a5bc5ca7..13a98380eb844 100644 --- a/lldb/include/lldb/Host/HostInfoBase.h +++ b/lldb/include/lldb/Host/HostInfoBase.h @@ -126,6 +126,8 @@ class HostInfoBase { static FileSpec GetXcodeContentsDirectory() { return {}; } static FileSpec GetXcodeDeveloperDirectory() { return {}; } + static FileSpec GetCurrentXcodeToolchainDirectory() { return {}; } + static FileSpec GetCurrentCommandLineToolsDirectory() { return {}; } #ifdef LLDB_ENABLE_SWIFT static FileSpec GetSwiftResourceDir() { return {}; } static FileSpec GetSwiftResourceDir(llvm::Triple triple) { return {}; } diff --git a/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h b/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h index 30445e011047c..c9fca9f7811fd 100644 --- a/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h +++ b/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h @@ -30,6 +30,8 @@ class HostInfoMacOSX : public HostInfoPosix { static FileSpec GetProgramFileSpec(); static FileSpec GetXcodeContentsDirectory(); static FileSpec GetXcodeDeveloperDirectory(); + static FileSpec GetCurrentXcodeToolchainDirectory(); + static FileSpec GetCurrentCommandLineToolsDirectory(); #ifdef LLDB_ENABLE_SWIFT static FileSpec GetSwiftResourceDir(); @@ -72,6 +74,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); }; } diff --git a/lldb/source/Host/macosx/objcxx/CMakeLists.txt b/lldb/source/Host/macosx/objcxx/CMakeLists.txt index e0a923fc97de4..8784ce61da464 100644 --- a/lldb/source/Host/macosx/objcxx/CMakeLists.txt +++ b/lldb/source/Host/macosx/objcxx/CMakeLists.txt @@ -1,18 +1,10 @@ set(SWIFT_SOURCES HostInfoMacOSXSwift.cpp) set(LLVM_OPTIONAL_SOURCES ${SWIFT_SOURCES}) -if (NOT LLDB_ENABLE_SWIFT_SUPPORT) - unset(SWIFT_SOURCES) - set(PLUGIN_DEPENDENCY_ARG NO_PLUGIN_DEPENDENCIES) - set(LLDB_PLUGIN_DEPENDENCIES) -else() - set(PLUGIN_DEPENDENCY_ARG) - set(LLDB_PLUGIN_DEPENDENCIES lldbPluginPlatformMacOSX) -endif() remove_module_flags() include_directories(..) -add_lldb_library(lldbHostMacOSXObjCXX ${PLUGIN_DEPENDENCY_ARG} +add_lldb_library(lldbHostMacOSXObjCXX NO_PLUGIN_DEPENDENCIES Host.mm HostInfoMacOSX.mm HostThreadMacOSX.mm @@ -21,7 +13,6 @@ add_lldb_library(lldbHostMacOSXObjCXX ${PLUGIN_DEPENDENCY_ARG} LINK_LIBS lldbUtility - ${LLDB_PLUGIN_DEPENDENCIES} ${EXTRA_LIBS} LINK_COMPONENTS diff --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm index c5442a9573560..08b16e393ffb9 100644 --- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm +++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm @@ -379,6 +379,33 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) { 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 xcrun(const std::string &sdk, llvm::ArrayRef arguments, llvm::StringRef developer_dir = "") { diff --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSXSwift.cpp b/lldb/source/Host/macosx/objcxx/HostInfoMacOSXSwift.cpp index ec0d50fb97b03..cf27f6d42f933 100644 --- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSXSwift.cpp +++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSXSwift.cpp @@ -285,8 +285,8 @@ HostInfoMacOSX::GetSwiftResourceDir(llvm::Triple triple, platform_sdk_path, swift_stdlib_os_dir, HostInfo::GetSwiftResourceDir().GetPath(), HostInfo::GetXcodeContentsDirectory().GetPath(), - PlatformDarwin::GetCurrentToolchainDirectory().GetPath(), - PlatformDarwin::GetCurrentCommandLineToolsDirectory().GetPath()); + HostInfoMacOSX::GetCurrentXcodeToolchainDirectory().GetPath(), + HostInfoMacOSX::GetCurrentCommandLineToolsDirectory().GetPath()); g_resource_dir_cache.insert({key, value}); return g_resource_dir_cache[key]; } diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index a3841f6f05f82..aae59090c5f55 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1332,33 +1332,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; diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h index e2d4cb6726d58..f8a62ceb958fe 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h @@ -117,13 +117,6 @@ class PlatformDarwin : public PlatformPOSIX { llvm::Expected 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> GetSDKPathFromDebugInfo(Module &module) override; @@ -199,9 +192,6 @@ class PlatformDarwin : public PlatformPOSIX { lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr, llvm::SmallVectorImpl *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(); diff --git a/lldb/unittests/Host/HostInfoTest.cpp b/lldb/unittests/Host/HostInfoTest.cpp index 5c53b96b853c8..14941ee5a94b2 100644 --- a/lldb/unittests/Host/HostInfoTest.cpp +++ b/lldb/unittests/Host/HostInfoTest.cpp @@ -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 diff --git a/lldb/unittests/Platform/PlatformDarwinTest.cpp b/lldb/unittests/Platform/PlatformDarwinTest.cpp index 285dc2ee3db78..72494d0a2667b 100644 --- a/lldb/unittests/Platform/PlatformDarwinTest.cpp +++ b/lldb/unittests/Platform/PlatformDarwinTest.cpp @@ -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; @@ -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")); -}