OS::Mac: look up CLT SDK on 10.14+

This commit is contained in:
Misty De Meo 2018-06-12 14:55:31 -07:00
parent 3bce1c78bc
commit 8450ffa8ad
No known key found for this signature in database
GPG Key ID: 76CF846A2F674B2C
2 changed files with 50 additions and 10 deletions

View File

@ -85,14 +85,19 @@ module OS
# specifically been requested according to the rules above.
def sdk(v = nil)
@locator ||= SDKLocator.new
@locator ||= if Xcode.without_clt?
XcodeSDKLocator.new
else
CLTSDKLocator.new
end
begin
sdk = if v.nil?
(Xcode.version.to_i >= 7) ? @locator.latest_sdk : @locator.sdk_for(version)
else
@locator.sdk_for v
end
rescue SDKLocator::NoSDKError
rescue BaseSDKLocator::NoSDKError
sdk = @locator.latest_sdk
end
# Only return an SDK older than the OS version if it was specifically requested

View File

@ -11,7 +11,7 @@ module OS
end
end
class SDKLocator
class BaseSDKLocator
class NoSDKError < StandardError; end
def sdk_for(v)
@ -30,15 +30,12 @@ module OS
private
def sdk_prefix
""
end
def sdk_paths
@sdk_paths ||= begin
# Xcode.prefix is pretty smart, so let's look inside to find the sdk
sdk_prefix = "#{Xcode.prefix}/Platforms/MacOSX.platform/Developer/SDKs"
# Xcode < 4.3 style
sdk_prefix = "/Developer/SDKs" unless File.directory? sdk_prefix
# Finally query Xcode itself (this is slow, so check it last)
sdk_prefix = File.join(Utils.popen_read(DevelopmentTools.locate("xcrun"), "--show-sdk-platform-path").chomp, "Developer", "SDKs") unless File.directory? sdk_prefix
# Bail out if there is no SDK prefix at all
if !File.directory? sdk_prefix
{}
@ -55,5 +52,43 @@ module OS
end
end
end
class XcodeSDKLocator < BaseSDKLocator
private
def sdk_prefix
@sdk_prefix ||= begin
# Xcode.prefix is pretty smart, so let's look inside to find the sdk
sdk_prefix = "#{Xcode.prefix}/Platforms/MacOSX.platform/Developer/SDKs"
# Xcode < 4.3 style
sdk_prefix = "/Developer/SDKs" unless File.directory? sdk_prefix
# Finally query Xcode itself (this is slow, so check it last)
sdk_prefix = File.join(Utils.popen_read(DevelopmentTools.locate("xcrun"), "--show-sdk-platform-path").chomp, "Developer", "SDKs") unless File.directory? sdk_prefix
sdk_prefix
end
end
end
class CLTSDKLocator < BaseSDKLocator
private
# While CLT SDKs existed prior to Xcode 10, those packages also
# installed a traditional Unix-style header layout and we prefer
# using that
# As of Xcode 10, the Unix-style headers are installed via a
# separate package, so we can't rely on their being present.
# This will only look up SDKs on Xcode 10 or newer, and still
# return nil SDKs for Xcode 9 and older.
def sdk_prefix
@sdk_prefix ||= begin
if !CLT.separate_header_package?
""
else
"#{CLT::PKG_PATH}/SDKs"
end
end
end
end
end
end