os/mac: add sdk_root_needed? and sdk_for_formula

This commit is contained in:
Bo Anderson 2020-04-07 16:43:59 +01:00
parent bb33a59c7b
commit 1fe0212ff2
2 changed files with 23 additions and 4 deletions

View File

@ -53,6 +53,10 @@ module OS
languages.first languages.first
end end
def sdk_root_needed?
false
end
def sdk_path_if_needed(_v = nil) def sdk_path_if_needed(_v = nil)
nil nil
end end

View File

@ -74,6 +74,17 @@ module OS
@active_developer_dir ||= Utils.popen_read("/usr/bin/xcode-select", "-print-path").strip @active_developer_dir ||= Utils.popen_read("/usr/bin/xcode-select", "-print-path").strip
end end
def sdk_root_needed?
if MacOS::CLT.installed?
# If there's no CLT SDK, return false
return false unless MacOS::CLT.provides_sdk?
# If the CLT is installed and headers are provided by the system, return false
return false unless MacOS::CLT.separate_header_package?
end
true
end
# If a specific SDK is requested: # If a specific SDK is requested:
# #
# 1. The requested SDK is returned, if it's installed. # 1. The requested SDK is returned, if it's installed.
@ -94,6 +105,13 @@ module OS
@locator.sdk_if_applicable(v) @locator.sdk_if_applicable(v)
end end
def sdk_for_formula(f, v = nil)
# If the formula requires Xcode, don't return the CLT SDK
return Xcode.sdk if f.requirements.any? { |req| req.is_a? XcodeRequirement }
sdk(v)
end
# Returns the path to an SDK or nil, following the rules set by {.sdk}. # Returns the path to an SDK or nil, following the rules set by {.sdk}.
def sdk_path(v = nil) def sdk_path(v = nil)
s = sdk(v) s = sdk(v)
@ -109,10 +127,7 @@ module OS
# 4. On CLT-only systems with a CLT SDK, where headers are provided by the system, return nil. # 4. On CLT-only systems with a CLT SDK, where headers are provided by the system, return nil.
# 5. On CLT-only systems with a CLT SDK, where headers are not provided by the system, return the CLT SDK. # 5. On CLT-only systems with a CLT SDK, where headers are not provided by the system, return the CLT SDK.
# If there's no CLT SDK, return early return unless sdk_root_needed?
return if MacOS::CLT.installed? && !MacOS::CLT.provides_sdk?
# If the CLT is installed and headers are provided by the system, return early
return if MacOS::CLT.installed? && !MacOS::CLT.separate_header_package?
sdk_path(v) sdk_path(v)
end end