Index: lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm =================================================================== --- lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm +++ lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm @@ -297,46 +297,47 @@ } } -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; - } - } +static FileSpec GetXcodeContentsDirectory(bool use_xcrun) { + // 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()) + return FileSpec(xcode_contents_dir); } + } - 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; - } - } + 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()) + return FileSpec(xcode_contents_dir); } + } - 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; - } - } + if (!use_xcrun) + 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()) + return FileSpec(xcode_contents_dir); } + } + return {}; +} + +FileSpec HostInfoMacOSX::GetXcodeContentsDirectory() { + static FileSpec g_xcode_contents_path; + static std::once_flag g_once_flag; + std::call_once(g_once_flag, [&]() { + g_xcode_contents_path = ::GetXcodeContentsDirectory(true); }); return g_xcode_contents_path; } @@ -358,7 +359,19 @@ XcodeSDK::Info info = sdk.Parse(); std::string sdk_name = XcodeSDK::GetCanonicalName(info); auto find_sdk = [](std::string sdk_name) -> std::string { - std::string xcrun_cmd = "xcrun --show-sdk-path --sdk " + sdk_name; + std::string xcrun_cmd; + Environment env = Host::GetEnvironment(); + std::string developer_dir = env.lookup("DEVELOPER_DIR"); + if (developer_dir.empty()) { + // Avoid infinite recursion GetXcodeContentsDirectory calling GetXcodeSDK. + FileSpec path = ::GetXcodeContentsDirectory(false); + if (path.RemoveLastPathComponent()) + developer_dir = path.GetPath(); + } + if (!developer_dir.empty()) + xcrun_cmd = "/usr/bin/env DEVELOPER_DIR=" + developer_dir + " "; + xcrun_cmd += "xcrun --show-sdk-path --sdk " + sdk_name; + int status = 0; int signo = 0; std::string output_str;