Merge pull request #7870 from Bo98/sdk-diag

Add SDK availability diagnostic
This commit is contained in:
Mike McQuaid 2020-07-01 17:34:09 +01:00 committed by GitHub
commit 1b1e3b449e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 26 deletions

View File

@ -12,6 +12,7 @@ module Homebrew
check_xcode_minimum_version check_xcode_minimum_version
check_clt_minimum_version check_clt_minimum_version
check_if_xcode_needs_clt_installed check_if_xcode_needs_clt_installed
check_if_supported_sdk_available
].freeze ].freeze
end end
@ -357,6 +358,34 @@ module Homebrew
Untap them with `brew untap`. Untap them with `brew untap`.
EOS EOS
end 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 end
end end

View File

@ -97,14 +97,16 @@ module OS
# If no specific SDK is requested, the SDK matching the OS version is returned, # If no specific SDK is requested, the SDK matching the OS version is returned,
# if available. Otherwise, the latest SDK is returned. # if available. Otherwise, the latest SDK is returned.
def sdk(v = nil) def sdk_locator
@locator ||= if CLT.installed? && CLT.provides_sdk? if CLT.installed? && CLT.provides_sdk?
CLTSDKLocator.new CLT.sdk_locator
else else
XcodeSDKLocator.new Xcode.sdk_locator
end end
end
@locator.sdk_if_applicable(v) def sdk(v = nil)
sdk_locator.sdk_if_applicable(v)
end end
def sdk_for_formula(f, v = nil) def sdk_for_formula(f, v = nil)

View File

@ -31,6 +31,10 @@ module OS
SDK.new v, path, source SDK.new v, path, source
end end
def all_sdks
sdk_paths.map { |v, p| SDK.new v, p, source }
end
def sdk_if_applicable(v = nil) def sdk_if_applicable(v = nil)
sdk = begin sdk = begin
if v.nil? if v.nil?
@ -47,15 +51,11 @@ module OS
sdk sdk
end end
private
def source def source
nil nil
end end
def source_version private
OS::Mac::Version::NULL
end
def sdk_prefix def sdk_prefix
"" ""
@ -81,15 +81,11 @@ module OS
end end
class XcodeSDKLocator < BaseSDKLocator class XcodeSDKLocator < BaseSDKLocator
private
def source def source
:xcode :xcode
end end
def source_version private
OS::Mac::Xcode.version
end
def sdk_prefix def sdk_prefix
@sdk_prefix ||= begin @sdk_prefix ||= begin
@ -105,15 +101,11 @@ module OS
end end
class CLTSDKLocator < BaseSDKLocator class CLTSDKLocator < BaseSDKLocator
private
def source def source
:clt :clt
end end
def source_version private
OS::Mac::CLT.version
end
# While CLT SDKs existed prior to Xcode 10, those packages also # While CLT SDKs existed prior to Xcode 10, those packages also
# installed a traditional Unix-style header layout and we prefer # installed a traditional Unix-style header layout and we prefer

View File

@ -107,10 +107,12 @@ module OS
!prefix.nil? !prefix.nil?
end end
def sdk(v = nil) def sdk_locator
@locator ||= XcodeSDKLocator.new @sdk_locator ||= XcodeSDKLocator.new
end
@locator.sdk_if_applicable(v) def sdk(v = nil)
sdk_locator.sdk_if_applicable(v)
end end
def sdk_path(v = nil) def sdk_path(v = nil)
@ -219,10 +221,12 @@ module OS
version >= "8" version >= "8"
end end
def sdk(v = nil) def sdk_locator
@locator ||= CLTSDKLocator.new @sdk_locator ||= CLTSDKLocator.new
end
@locator.sdk_if_applicable(v) def sdk(v = nil)
sdk_locator.sdk_if_applicable(v)
end end
def sdk_path(v = nil) def sdk_path(v = nil)