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_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

View File

@ -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)

View File

@ -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

View File

@ -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)