From 3d7b926dd16ff9ff264337793b76080681636f15 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Thu, 4 Jun 2020 17:57:11 -0700 Subject: [PATCH] Move GetXcode*Directory into HostInfo (NFC) These functions really don't belong into PlatformDarwin, since they actualy query state of the Host and not of the remote platform. --- lldb/include/lldb/Host/HostInfoBase.h | 3 + lldb/include/lldb/Host/macosx/HostInfoMacOSX.h | 3 +- lldb/include/lldb/Utility/XcodeSDK.h | 2 + lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm | 57 +++++++++++++++ .../Platform/MacOSX/PlatformAppleSimulator.cpp | 9 +-- .../Platform/MacOSX/PlatformAppleTVSimulator.cpp | 2 +- .../MacOSX/PlatformAppleWatchSimulator.cpp | 2 +- .../Plugins/Platform/MacOSX/PlatformDarwin.cpp | 83 +--------------------- .../Plugins/Platform/MacOSX/PlatformDarwin.h | 4 -- .../Platform/MacOSX/PlatformDarwinKernel.cpp | 3 +- .../Plugins/Platform/MacOSX/PlatformMacOSX.cpp | 2 +- .../Platform/MacOSX/PlatformRemoteDarwinDevice.cpp | 3 +- .../Platform/MacOSX/PlatformiOSSimulator.cpp | 2 +- lldb/source/Utility/XcodeSDK.cpp | 22 ++++++ lldb/unittests/Platform/PlatformDarwinTest.cpp | 39 ---------- lldb/unittests/Utility/XcodeSDKTest.cpp | 35 +++++++++ 16 files changed, 136 insertions(+), 135 deletions(-) diff --git a/lldb/include/lldb/Host/HostInfoBase.h b/lldb/include/lldb/Host/HostInfoBase.h index dbd1150..70682c9 100644 --- a/lldb/include/lldb/Host/HostInfoBase.h +++ b/lldb/include/lldb/Host/HostInfoBase.h @@ -92,6 +92,9 @@ public: static bool ComputePathRelativeToLibrary(FileSpec &file_spec, llvm::StringRef dir); + static FileSpec GetXcodeContentsDirectory() { return {}; } + static FileSpec GetXcodeDeveloperDirectory() { return {}; } + /// Return the directory containing a specific Xcode SDK. static llvm::StringRef GetXcodeSDKPath(XcodeSDK sdk) { return {}; } diff --git a/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h b/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h index dacb8c4..3941414 100644 --- a/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h +++ b/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h @@ -32,7 +32,8 @@ public: static bool GetOSBuildString(std::string &s); static bool GetOSKernelDescription(std::string &s); static FileSpec GetProgramFileSpec(); - static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path); + static FileSpec GetXcodeContentsDirectory(); + static FileSpec GetXcodeDeveloperDirectory(); /// Query xcrun to find an Xcode SDK directory. static llvm::StringRef GetXcodeSDKPath(XcodeSDK sdk); diff --git a/lldb/include/lldb/Utility/XcodeSDK.h b/lldb/include/lldb/Utility/XcodeSDK.h index 2ed5fab..307fe7f 100644 --- a/lldb/include/lldb/Utility/XcodeSDK.h +++ b/lldb/include/lldb/Utility/XcodeSDK.h @@ -87,6 +87,8 @@ public: static std::string GetCanonicalName(Info info); /// Return the best-matching SDK type for a specific triple. static XcodeSDK::Type GetSDKTypeForTriple(const llvm::Triple &triple); + + static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path); }; } // namespace lldb_private diff --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm index 615f77b..5c459a0 100644 --- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm +++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm @@ -297,6 +297,63 @@ void HostInfoMacOSX::ComputeHostArchitectureSupport(ArchSpec &arch_32, } } +FileSpec HostInfoMacOSX::GetXcodeContentsDirectory() { + static FileSpec g_xcode_contents_path; + static std::once_flag g_once_flag; + std::call_once(g_once_flag, [&]() { + // Try the shlib dir first. + if (FileSpec fspec = HostInfo::GetShlibDir()) { + if (FileSystem::Instance().Exists(fspec)) { + std::string xcode_contents_dir = + XcodeSDK::FindXcodeContentsDirectoryInPath(fspec.GetPath()); + if (!xcode_contents_dir.empty()) { + g_xcode_contents_path = FileSpec(xcode_contents_dir); + return; + } + } + } + + if (const char *developer_dir_env_var = getenv("DEVELOPER_DIR")) { + FileSpec fspec(developer_dir_env_var); + if (FileSystem::Instance().Exists(fspec)) { + // FIXME: This looks like it couldn't possibly work! + std::string xcode_contents_dir = + XcodeSDK::FindXcodeContentsDirectoryInPath(fspec.GetPath()); + if (!xcode_contents_dir.empty()) { + g_xcode_contents_path = FileSpec(xcode_contents_dir); + return; + } + } + } + + FileSpec fspec(HostInfo::GetXcodeSDKPath(XcodeSDK::GetAnyMacOS())); + if (fspec) { + if (FileSystem::Instance().Exists(fspec)) { + std::string xcode_contents_dir = + XcodeSDK::FindXcodeContentsDirectoryInPath(fspec.GetPath()); + if (!xcode_contents_dir.empty()) { + g_xcode_contents_path = FileSpec(xcode_contents_dir); + return; + } + } + } + }); + return g_xcode_contents_path; +} + +lldb_private::FileSpec HostInfoMacOSX::GetXcodeDeveloperDirectory() { + static lldb_private::FileSpec g_developer_directory; + static llvm::once_flag g_once_flag; + llvm::call_once(g_once_flag, []() { + if (FileSpec fspec = GetXcodeContentsDirectory()) { + fspec.AppendPathComponent("Developer"); + if (FileSystem::Instance().Exists(fspec)) + g_developer_directory = fspec; + } + }); + return g_developer_directory; +} + static std::string GetXcodeSDK(XcodeSDK sdk) { XcodeSDK::Info info = sdk.Parse(); std::string sdk_name = XcodeSDK::GetCanonicalName(info); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp index cb6fbce..3f83a23 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp @@ -15,6 +15,7 @@ #include #include #include "lldb/Host/PseudoTerminal.h" +#include "lldb/Host/HostInfo.h" #include "lldb/Target/Process.h" #include "lldb/Utility/LLDBAssert.h" #include "lldb/Utility/Status.h" @@ -77,7 +78,7 @@ void PlatformAppleSimulator::GetStatus(Stream &strm) { // simulator PlatformAppleSimulator::LoadCoreSimulator(); - std::string developer_dir = GetXcodeDeveloperDirectory().GetPath(); + std::string developer_dir = HostInfo::GetXcodeDeveloperDirectory().GetPath(); CoreSimulatorSupport::DeviceSet devices = CoreSimulatorSupport::DeviceSet::GetAvailableDevices( developer_dir.c_str()); @@ -124,7 +125,7 @@ Status PlatformAppleSimulator::ConnectRemote(Args &args) { const char *arg_cstr = args.GetArgumentAtIndex(0); if (arg_cstr) { std::string arg_str(arg_cstr); - std::string developer_dir = GetXcodeDeveloperDirectory().GetPath(); + std::string developer_dir = HostInfo::GetXcodeDeveloperDirectory().GetPath(); CoreSimulatorSupport::DeviceSet devices = CoreSimulatorSupport::DeviceSet::GetAvailableDevices( developer_dir.c_str()); @@ -214,7 +215,7 @@ FileSpec PlatformAppleSimulator::GetCoreSimulatorPath() { #if defined(__APPLE__) std::lock_guard guard(m_core_sim_path_mutex); if (!m_core_simulator_framework_path.hasValue()) { - if (FileSpec fspec = GetXcodeDeveloperDirectory()) { + if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) { std::string developer_dir = fspec.GetPath(); StreamString cs_path; cs_path.Printf( @@ -247,7 +248,7 @@ CoreSimulatorSupport::Device PlatformAppleSimulator::GetSimulatorDevice() { if (!m_device.hasValue()) { const CoreSimulatorSupport::DeviceType::ProductFamilyID dev_id = CoreSimulatorSupport::DeviceType::ProductFamilyID::iPhone; - std::string developer_dir = GetXcodeDeveloperDirectory().GetPath(); + std::string developer_dir = HostInfo::GetXcodeDeveloperDirectory().GetPath(); m_device = CoreSimulatorSupport::DeviceSet::GetAvailableDevices( developer_dir.c_str()) .GetFanciest(dev_id); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp index fa5f93b..82114c7 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp @@ -255,7 +255,7 @@ EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft, const char *PlatformAppleTVSimulator::GetSDKDirectoryAsCString() { std::lock_guard guard(m_sdk_dir_mutex); if (m_sdk_directory.empty()) { - if (FileSpec fspec = GetXcodeDeveloperDirectory()) { + if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) { std::string developer_dir = fspec.GetPath(); char sdks_directory[PATH_MAX]; char sdk_dirname[PATH_MAX]; diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp index 6cd2016..c345c0c 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp @@ -255,7 +255,7 @@ EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft, const char *PlatformAppleWatchSimulator::GetSDKDirectoryAsCString() { std::lock_guard guard(m_sdk_dir_mutex); if (m_sdk_directory.empty()) { - if (FileSpec fspec = GetXcodeDeveloperDirectory()) { + if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) { std::string developer_dir = fspec.GetPath(); char sdks_directory[PATH_MAX]; char sdk_dirname[PATH_MAX]; diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 635dd1f..85cd000 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1133,19 +1133,6 @@ static FileSpec GetXcodeSelectPath() { return g_xcode_select_filespec; } -lldb_private::FileSpec PlatformDarwin::GetXcodeDeveloperDirectory() { - static lldb_private::FileSpec g_developer_directory; - static llvm::once_flag g_once_flag; - llvm::call_once(g_once_flag, []() { - if (FileSpec fspec = GetXcodeContentsDirectory()) { - fspec.AppendPathComponent("Developer"); - if (FileSystem::Instance().Exists(fspec)) - g_developer_directory = fspec; - } - }); - return g_developer_directory; -} - BreakpointSP PlatformDarwin::SetThreadCreationBreakpoint(Target &target) { BreakpointSP bp_sp; static const char *g_bp_names[] = { @@ -1260,7 +1247,7 @@ FileSpec PlatformDarwin::FindSDKInXcodeForModules(XcodeSDK::Type sdk_type, } FileSpec PlatformDarwin::GetSDKDirectoryForModules(XcodeSDK::Type sdk_type) { - FileSpec sdks_spec = GetXcodeContentsDirectory(); + FileSpec sdks_spec = HostInfo::GetXcodeContentsDirectory(); sdks_spec.AppendPathComponent("Developer"); sdks_spec.AppendPathComponent("Platforms"); @@ -1586,7 +1573,7 @@ lldb_private::FileSpec PlatformDarwin::LocateExecutable(const char *basename) { llvm::call_once(g_once_flag, []() { // When locating executables, trust the DEVELOPER_DIR first if it is set - FileSpec xcode_contents_dir = GetXcodeContentsDirectory(); + FileSpec xcode_contents_dir = HostInfo::GetXcodeContentsDirectory(); if (xcode_contents_dir) { FileSpec xcode_lldb_resources = xcode_contents_dir; xcode_lldb_resources.AppendPathComponent("SharedFrameworks"); @@ -1738,72 +1725,6 @@ std::string PlatformDarwin::FindComponentInPath(llvm::StringRef path, return {}; } -std::string -PlatformDarwin::FindXcodeContentsDirectoryInPath(llvm::StringRef path) { - auto begin = llvm::sys::path::begin(path); - auto end = llvm::sys::path::end(path); - - // Iterate over the path components until we find something that ends with - // .app. If the next component is Contents then we've found the Contents - // directory. - for (auto it = begin; it != end; ++it) { - if (it->endswith(".app")) { - auto next = it; - if (++next != end && *next == "Contents") { - llvm::SmallString<128> buffer; - llvm::sys::path::append(buffer, begin, ++next, - llvm::sys::path::Style::posix); - return buffer.str().str(); - } - } - } - - return {}; -} - -FileSpec PlatformDarwin::GetXcodeContentsDirectory() { - static FileSpec g_xcode_contents_path; - static std::once_flag g_once_flag; - std::call_once(g_once_flag, [&]() { - // Try the shlib dir first. - if (FileSpec fspec = HostInfo::GetShlibDir()) { - if (FileSystem::Instance().Exists(fspec)) { - std::string xcode_contents_dir = - FindXcodeContentsDirectoryInPath(fspec.GetPath()); - if (!xcode_contents_dir.empty()) { - g_xcode_contents_path = FileSpec(xcode_contents_dir); - return; - } - } - } - - if (const char *developer_dir_env_var = getenv("DEVELOPER_DIR")) { - FileSpec fspec(developer_dir_env_var); - if (FileSystem::Instance().Exists(fspec)) { - std::string xcode_contents_dir = - FindXcodeContentsDirectoryInPath(fspec.GetPath()); - if (!xcode_contents_dir.empty()) { - g_xcode_contents_path = FileSpec(xcode_contents_dir); - return; - } - } - } - - FileSpec fspec(HostInfo::GetXcodeSDKPath(XcodeSDK::GetAnyMacOS())); - if (fspec) { - if (FileSystem::Instance().Exists(fspec)) { - std::string xcode_contents_dir = - FindXcodeContentsDirectoryInPath(fspec.GetPath()); - if (!xcode_contents_dir.empty()) { - g_xcode_contents_path = FileSpec(xcode_contents_dir); - return; - } - } - } - }); - return g_xcode_contents_path; -} - FileSpec PlatformDarwin::GetCurrentToolchainDirectory() { if (FileSpec fspec = HostInfo::GetShlibDir()) return FileSpec(FindComponentInPath(fspec.GetPath(), ".xctoolchain")); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h index f93f8f4..8e28a7000 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h @@ -89,9 +89,6 @@ public: llvm::Expected FetchExtendedCrashInformation(lldb_private::Process &process) override; - static lldb_private::FileSpec GetXcodeContentsDirectory(); - static lldb_private::FileSpec GetXcodeDeveloperDirectory(); - /// Return the toolchain directory the current LLDB instance is located in. static lldb_private::FileSpec GetCurrentToolchainDirectory(); @@ -165,7 +162,6 @@ protected: static std::string FindComponentInPath(llvm::StringRef path, llvm::StringRef component); - static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path); std::string m_developer_directory; llvm::StringMap m_sdk_path; diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp index 6d9f20a..f6c0f26 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp @@ -17,6 +17,7 @@ #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" #include "lldb/Host/Host.h" +#include "lldb/Host/HostInfo.h" #include "lldb/Interpreter/OptionValueFileSpecList.h" #include "lldb/Interpreter/OptionValueProperties.h" #include "lldb/Interpreter/Property.h" @@ -327,7 +328,7 @@ void PlatformDarwinKernel::CollectKextAndKernelDirectories() { // DeveloperDirectory is something like // "/Applications/Xcode.app/Contents/Developer" - std::string developer_dir = GetXcodeDeveloperDirectory().GetPath(); + std::string developer_dir = HostInfo::GetXcodeDeveloperDirectory().GetPath(); if (developer_dir.empty()) developer_dir = "/Applications/Xcode.app/Contents/Developer"; diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp index 84bc85e..0b7f898e 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp @@ -197,7 +197,7 @@ ConstString PlatformMacOSX::GetSDKDirectory(lldb_private::Target &target) { return {}; // First try to find an SDK that matches the given SDK version. - if (FileSpec fspec = GetXcodeContentsDirectory()) { + if (FileSpec fspec = HostInfo::GetXcodeContentsDirectory()) { StreamString sdk_path; sdk_path.Printf("%s/Developer/Platforms/MacOSX.platform/Developer/" "SDKs/MacOSX%u.%u.sdk", diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp index 40dd903..e4ede0d 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp @@ -15,6 +15,7 @@ #include "lldb/Core/PluginManager.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" +#include "lldb/Host/HostInfo.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" #include "lldb/Utility/FileSpec.h" @@ -342,7 +343,7 @@ PlatformRemoteDarwinDevice::GetSDKDirectoryForLatestOSVersion() { const char *PlatformRemoteDarwinDevice::GetDeviceSupportDirectory() { std::string platform_dir = "/Platforms/" + GetPlatformName() + "/DeviceSupport"; if (m_device_support_directory.empty()) { - if (FileSpec fspec = GetXcodeDeveloperDirectory()) { + if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) { m_device_support_directory = fspec.GetPath(); m_device_support_directory.append(platform_dir.c_str()); } else { diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp index b09c405..1a3e087 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp @@ -260,7 +260,7 @@ EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft, const char *PlatformiOSSimulator::GetSDKDirectoryAsCString() { std::lock_guard guard(m_sdk_dir_mutex); if (m_sdk_directory.empty()) { - if (FileSpec fspec = GetXcodeDeveloperDirectory()) { + if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) { std::string developer_dir = fspec.GetPath(); char sdks_directory[PATH_MAX]; char sdk_dirname[PATH_MAX]; diff --git a/lldb/source/Utility/XcodeSDK.cpp b/lldb/source/Utility/XcodeSDK.cpp index d5ef8e2..066bf45 100644 --- a/lldb/source/Utility/XcodeSDK.cpp +++ b/lldb/source/Utility/XcodeSDK.cpp @@ -285,3 +285,25 @@ XcodeSDK::Type XcodeSDK::GetSDKTypeForTriple(const llvm::Triple &triple) { return XcodeSDK::unknown; } } + +std::string XcodeSDK::FindXcodeContentsDirectoryInPath(llvm::StringRef path) { + auto begin = llvm::sys::path::begin(path); + auto end = llvm::sys::path::end(path); + + // Iterate over the path components until we find something that ends with + // .app. If the next component is Contents then we've found the Contents + // directory. + for (auto it = begin; it != end; ++it) { + if (it->endswith(".app")) { + auto next = it; + if (++next != end && *next == "Contents") { + llvm::SmallString<128> buffer; + llvm::sys::path::append(buffer, begin, ++next, + llvm::sys::path::Style::posix); + return buffer.str().str(); + } + } + } + + return {}; +} diff --git a/lldb/unittests/Platform/PlatformDarwinTest.cpp b/lldb/unittests/Platform/PlatformDarwinTest.cpp index 0a4c802..285dc2e 100644 --- a/lldb/unittests/Platform/PlatformDarwinTest.cpp +++ b/lldb/unittests/Platform/PlatformDarwinTest.cpp @@ -20,7 +20,6 @@ using namespace lldb_private; struct PlatformDarwinTester : public PlatformDarwin { public: using PlatformDarwin::FindComponentInPath; - using PlatformDarwin::FindXcodeContentsDirectoryInPath; }; TEST(PlatformDarwinTest, TestParseVersionBuildDir) { @@ -51,44 +50,6 @@ TEST(PlatformDarwinTest, TestParseVersionBuildDir) { EXPECT_EQ(llvm::VersionTuple(3, 4, 5), V); } -TEST(PlatformDarwinTest, FindXcodeContentsDirectoryInPath) { - std::string standard = - "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/" - "Developer/SDKs/MacOSX.sdk"; - EXPECT_EQ("/Applications/Xcode.app/Contents", - PlatformDarwinTester::FindXcodeContentsDirectoryInPath(standard)); - - std::string standard_version = - "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/" - "Developer/SDKs/MacOSX10.15.sdk"; - EXPECT_EQ( - "/Applications/Xcode.app/Contents", - PlatformDarwinTester::FindXcodeContentsDirectoryInPath(standard_version)); - - std::string beta = "/Applications/Xcode-beta.app/Contents/Developer/" - "Platforms/MacOSX.platform/" - "Developer/SDKs/MacOSX10.15.sdk"; - EXPECT_EQ("/Applications/Xcode-beta.app/Contents", - PlatformDarwinTester::FindXcodeContentsDirectoryInPath(beta)); - - std::string no_app = - "/Applications/Xcode/Contents/Developer/Platforms/MacOSX.platform/" - "Developer/SDKs/MacOSX10.15.sdk"; - EXPECT_EQ("", PlatformDarwinTester::FindXcodeContentsDirectoryInPath(no_app)); - - std::string no_contents = - "/Applications/Xcode.app/Developer/Platforms/MacOSX.platform/" - "Developer/SDKs/MacOSX10.15.sdk"; - EXPECT_EQ( - "", PlatformDarwinTester::FindXcodeContentsDirectoryInPath(no_contents)); - - std::string no_capitalization = - "/Applications/Xcode.app/contents/Developer/Platforms/MacOSX.platform/" - "Developer/SDKs/MacOSX10.15.sdk"; - EXPECT_EQ("", PlatformDarwinTester::FindXcodeContentsDirectoryInPath( - no_capitalization)); -} - TEST(PlatformDarwinTest, FindComponentInPath) { EXPECT_EQ("/path/to/foo", PlatformDarwinTester::FindComponentInPath("/path/to/foo/", "foo")); diff --git a/lldb/unittests/Utility/XcodeSDKTest.cpp b/lldb/unittests/Utility/XcodeSDKTest.cpp index 21419a2..69e4d2c 100644 --- a/lldb/unittests/Utility/XcodeSDKTest.cpp +++ b/lldb/unittests/Utility/XcodeSDKTest.cpp @@ -204,3 +204,38 @@ TEST(XcodeSDKTest, GetSDKTypeForTriple) { EXPECT_EQ(XcodeSDK::GetSDKTypeForTriple(llvm::Triple("i386-unknown-netbsd")), XcodeSDK::Type::unknown); } + +TEST(XcodeSDKTest, FindXcodeContentsDirectoryInPath) { + std::string standard = + "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/" + "Developer/SDKs/MacOSX.sdk"; + EXPECT_EQ("/Applications/Xcode.app/Contents", + XcodeSDK::FindXcodeContentsDirectoryInPath(standard)); + + std::string standard_version = + "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/" + "Developer/SDKs/MacOSX10.15.sdk"; + EXPECT_EQ("/Applications/Xcode.app/Contents", + XcodeSDK::FindXcodeContentsDirectoryInPath(standard_version)); + + std::string beta = "/Applications/Xcode-beta.app/Contents/Developer/" + "Platforms/MacOSX.platform/" + "Developer/SDKs/MacOSX10.15.sdk"; + EXPECT_EQ("/Applications/Xcode-beta.app/Contents", + XcodeSDK::FindXcodeContentsDirectoryInPath(beta)); + + std::string no_app = + "/Applications/Xcode/Contents/Developer/Platforms/MacOSX.platform/" + "Developer/SDKs/MacOSX10.15.sdk"; + EXPECT_EQ("", XcodeSDK::FindXcodeContentsDirectoryInPath(no_app)); + + std::string no_contents = + "/Applications/Xcode.app/Developer/Platforms/MacOSX.platform/" + "Developer/SDKs/MacOSX10.15.sdk"; + EXPECT_EQ("", XcodeSDK::FindXcodeContentsDirectoryInPath(no_contents)); + + std::string no_capitalization = + "/Applications/Xcode.app/contents/Developer/Platforms/MacOSX.platform/" + "Developer/SDKs/MacOSX10.15.sdk"; + EXPECT_EQ("", XcodeSDK::FindXcodeContentsDirectoryInPath(no_capitalization)); +} -- 2.7.4