diff --git a/Library/Homebrew/extend/os/mac/diagnostic.rb b/Library/Homebrew/extend/os/mac/diagnostic.rb index fe0bf0d5be..843196de9a 100644 --- a/Library/Homebrew/extend/os/mac/diagnostic.rb +++ b/Library/Homebrew/extend/os/mac/diagnostic.rb @@ -12,6 +12,7 @@ module Homebrew check_xcode_minimum_version check_clt_minimum_version check_if_xcode_needs_clt_installed + check_if_supported_sdk_available ].freeze end @@ -357,6 +358,34 @@ module Homebrew Untap them with `brew untap`. EOS end + + def check_if_supported_sdk_available + return unless MacOS.sdk_root_needed? + return if MacOS.sdk + + locator = MacOS.sdk_locator + + source = if locator.source == :clt + "CLT" + else + "Xcode" + end + + all_sdks = locator.all_sdks + sdks_found_msg = unless all_sdks.empty? + <<~EOS + Homebrew found the following SDKs in the #{source} install: + #{locator.all_sdks.map(&:version).join("\n ")} + EOS + end + + <<~EOS + Could not find an SDK that supports macOS #{MacOS.version}. + You may have have an outdated or incompatible #{source}. + #{sdks_found_msg} + Please update #{source} or uninstall it if no updates are available. + EOS + end end end end diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index 27749cf0c8..fe658e924d 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -97,14 +97,16 @@ module OS # If no specific SDK is requested, the SDK matching the OS version is returned, # if available. Otherwise, the latest SDK is returned. - def sdk(v = nil) - @locator ||= if CLT.installed? && CLT.provides_sdk? - CLTSDKLocator.new + def sdk_locator + if CLT.installed? && CLT.provides_sdk? + CLT.sdk_locator else - XcodeSDKLocator.new + Xcode.sdk_locator end + end - @locator.sdk_if_applicable(v) + def sdk(v = nil) + sdk_locator.sdk_if_applicable(v) end def sdk_for_formula(f, v = nil) diff --git a/Library/Homebrew/os/mac/sdk.rb b/Library/Homebrew/os/mac/sdk.rb index 156c41812d..f6061c3712 100644 --- a/Library/Homebrew/os/mac/sdk.rb +++ b/Library/Homebrew/os/mac/sdk.rb @@ -31,6 +31,10 @@ module OS SDK.new v, path, source end + def all_sdks + sdk_paths.map { |v, p| SDK.new v, p, source } + end + def sdk_if_applicable(v = nil) sdk = begin if v.nil? @@ -47,15 +51,11 @@ module OS sdk end - private - def source nil end - def source_version - OS::Mac::Version::NULL - end + private def sdk_prefix "" @@ -81,15 +81,11 @@ module OS end class XcodeSDKLocator < BaseSDKLocator - private - def source :xcode end - def source_version - OS::Mac::Xcode.version - end + private def sdk_prefix @sdk_prefix ||= begin @@ -105,15 +101,11 @@ module OS end class CLTSDKLocator < BaseSDKLocator - private - def source :clt end - def source_version - OS::Mac::CLT.version - end + private # While CLT SDKs existed prior to Xcode 10, those packages also # installed a traditional Unix-style header layout and we prefer diff --git a/Library/Homebrew/os/mac/xcode.rb b/Library/Homebrew/os/mac/xcode.rb index 1e852b412c..6190e267f4 100644 --- a/Library/Homebrew/os/mac/xcode.rb +++ b/Library/Homebrew/os/mac/xcode.rb @@ -107,10 +107,12 @@ module OS !prefix.nil? end - def sdk(v = nil) - @locator ||= XcodeSDKLocator.new + def sdk_locator + @sdk_locator ||= XcodeSDKLocator.new + end - @locator.sdk_if_applicable(v) + def sdk(v = nil) + sdk_locator.sdk_if_applicable(v) end def sdk_path(v = nil) @@ -219,10 +221,12 @@ module OS version >= "8" end - def sdk(v = nil) - @locator ||= CLTSDKLocator.new + def sdk_locator + @sdk_locator ||= CLTSDKLocator.new + end - @locator.sdk_if_applicable(v) + def sdk(v = nil) + sdk_locator.sdk_if_applicable(v) end def sdk_path(v = nil)