2015-08-03 13:09:07 +01:00
|
|
|
require "hardware"
|
2016-04-25 18:01:03 +01:00
|
|
|
require "development_tools"
|
2015-08-03 13:09:07 +01:00
|
|
|
require "os/mac/version"
|
|
|
|
require "os/mac/xcode"
|
|
|
|
require "os/mac/xquartz"
|
2015-10-16 17:08:11 +08:00
|
|
|
require "os/mac/pathname"
|
2015-12-04 13:58:22 -08:00
|
|
|
require "os/mac/sdk"
|
2013-10-18 12:56:51 -05:00
|
|
|
|
|
|
|
module OS
|
|
|
|
module Mac
|
2016-09-24 20:11:54 +02:00
|
|
|
module_function
|
2013-10-18 12:56:51 -05:00
|
|
|
|
2016-09-24 20:11:54 +02:00
|
|
|
::MacOS = self # rubocop:disable Style/ConstantName
|
2013-10-18 12:56:51 -05:00
|
|
|
|
2016-04-25 17:53:43 +01:00
|
|
|
raise "Loaded OS::Mac on generic OS!" if ENV["HOMEBREW_TEST_GENERIC_OS"]
|
|
|
|
|
2013-10-18 12:56:51 -05:00
|
|
|
# This can be compared to numerics, strings, or symbols
|
|
|
|
# using the standard Ruby Comparable methods.
|
|
|
|
def version
|
2015-10-16 16:41:14 +08:00
|
|
|
@version ||= Version.new(full_version.to_s[/10\.\d+/])
|
|
|
|
end
|
|
|
|
|
|
|
|
# This can be compared to numerics, strings, or symbols
|
|
|
|
# using the standard Ruby Comparable methods.
|
|
|
|
def full_version
|
2016-09-19 09:17:35 +01:00
|
|
|
@full_version ||= Version.new((ENV["HOMEBREW_MACOS_VERSION"] || ENV["HOMEBREW_OSX_VERSION"]).chomp)
|
2013-10-18 12:56:51 -05:00
|
|
|
end
|
|
|
|
|
2017-01-20 09:00:53 +01:00
|
|
|
def full_version=(version)
|
|
|
|
@full_version = Version.new(version.chomp)
|
|
|
|
@version = nil
|
|
|
|
end
|
|
|
|
|
2015-10-23 00:07:12 +02:00
|
|
|
def prerelease?
|
|
|
|
# TODO: bump version when new OS is released
|
2016-09-17 12:59:32 +01:00
|
|
|
version >= "10.13"
|
2015-10-23 00:07:12 +02:00
|
|
|
end
|
|
|
|
|
2016-01-09 10:21:25 +00:00
|
|
|
def outdated_release?
|
|
|
|
# TODO: bump version when new OS is released
|
2016-09-18 19:59:07 +01:00
|
|
|
version < "10.10"
|
2016-01-09 10:21:25 +00:00
|
|
|
end
|
|
|
|
|
2013-10-18 12:56:51 -05:00
|
|
|
def cat
|
|
|
|
version.to_sym
|
|
|
|
end
|
|
|
|
|
2016-09-10 04:24:55 +02:00
|
|
|
def languages
|
2016-09-25 20:43:03 +02:00
|
|
|
return @languages unless @languages.nil?
|
|
|
|
|
|
|
|
@languages = Utils.popen_read("defaults", "read", ".GlobalPreferences", "AppleLanguages").scan(/[^ \n"(),]+/)
|
|
|
|
|
|
|
|
if ENV["HOMEBREW_LANGUAGES"]
|
|
|
|
@languages = ENV["HOMEBREW_LANGUAGES"].split(",") + @languages
|
2016-09-21 21:56:59 +02:00
|
|
|
end
|
2016-09-25 20:43:03 +02:00
|
|
|
|
|
|
|
if ARGV.value("language")
|
|
|
|
@languages = ARGV.value("language").split(",") + @languages
|
|
|
|
end
|
|
|
|
|
|
|
|
@languages = @languages.uniq
|
2016-09-10 04:24:55 +02:00
|
|
|
end
|
|
|
|
|
2016-09-09 00:11:43 +02:00
|
|
|
def language
|
2016-09-10 04:24:55 +02:00
|
|
|
languages.first
|
2016-09-09 00:11:43 +02:00
|
|
|
end
|
|
|
|
|
2014-05-01 18:36:46 -05:00
|
|
|
def active_developer_dir
|
2014-12-16 15:27:36 -05:00
|
|
|
@active_developer_dir ||= Utils.popen_read("/usr/bin/xcode-select", "-print-path").strip
|
2014-05-01 18:36:46 -05:00
|
|
|
end
|
|
|
|
|
2016-03-30 05:13:41 -07:00
|
|
|
# If a specific SDK is requested
|
|
|
|
# a) The requested SDK is returned, if it's installed.
|
|
|
|
# b) If the requested SDK is not installed, the newest SDK (if any SDKs
|
|
|
|
# are available) is returned.
|
|
|
|
# c) If no SDKs are available, nil is returned.
|
|
|
|
# If no specific SDK is requested
|
|
|
|
# a) For Xcode >= 7, the latest SDK is returned even if the latest SDK is
|
|
|
|
# named after a newer OS version than the running OS. The
|
|
|
|
# MACOSX_DEPLOYMENT_TARGET must be set to the OS for which you're
|
|
|
|
# actually building (usually the running OS version).
|
2016-05-01 14:55:45 +02:00
|
|
|
# https://github.com/Homebrew/legacy-homebrew/pull/50355
|
2016-03-30 05:13:41 -07:00
|
|
|
# https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/Introduction.html#//apple_ref/doc/uid/TP40004626
|
|
|
|
# Section "About SDKs and Simulator"
|
|
|
|
# b) For Xcode < 7, proceed as if the SDK for the running OS version had
|
|
|
|
# specifically been requested according to the rules above.
|
|
|
|
|
2016-03-23 04:34:21 -07:00
|
|
|
def sdk(v = nil)
|
2015-12-04 13:58:22 -08:00
|
|
|
@locator ||= SDKLocator.new
|
|
|
|
begin
|
2016-03-23 04:34:21 -07:00
|
|
|
sdk = if v.nil?
|
2017-05-29 18:24:52 +01:00
|
|
|
(Xcode.version.to_i >= 7) ? @locator.latest_sdk : @locator.sdk_for(version)
|
2016-03-23 04:34:21 -07:00
|
|
|
else
|
|
|
|
@locator.sdk_for v
|
|
|
|
end
|
2015-12-04 13:58:22 -08:00
|
|
|
rescue SDKLocator::NoSDKError
|
2015-12-04 14:40:24 -08:00
|
|
|
sdk = @locator.latest_sdk
|
2013-10-18 12:56:51 -05:00
|
|
|
end
|
2016-03-30 04:03:19 -07:00
|
|
|
# Only return an SDK older than the OS version if it was specifically requested
|
|
|
|
sdk if v || (!sdk.nil? && sdk.version >= version)
|
2013-10-18 12:56:51 -05:00
|
|
|
end
|
|
|
|
|
2015-12-04 13:58:22 -08:00
|
|
|
# Returns the path to an SDK or nil, following the rules set by #sdk.
|
2016-03-23 04:34:21 -07:00
|
|
|
def sdk_path(v = nil)
|
2015-12-04 13:58:22 -08:00
|
|
|
s = sdk(v)
|
|
|
|
s.path unless s.nil?
|
|
|
|
end
|
|
|
|
|
2013-10-18 12:56:51 -05:00
|
|
|
# See these issues for some history:
|
2016-05-01 14:55:45 +02:00
|
|
|
# https://github.com/Homebrew/legacy-homebrew/issues/13
|
|
|
|
# https://github.com/Homebrew/legacy-homebrew/issues/41
|
|
|
|
# https://github.com/Homebrew/legacy-homebrew/issues/48
|
2013-10-18 12:56:51 -05:00
|
|
|
def macports_or_fink
|
|
|
|
paths = []
|
|
|
|
|
|
|
|
# First look in the path because MacPorts is relocatable and Fink
|
|
|
|
# may become relocatable in the future.
|
2015-08-03 13:09:07 +01:00
|
|
|
%w[port fink].each do |ponk|
|
2013-10-18 12:56:51 -05:00
|
|
|
path = which(ponk)
|
|
|
|
paths << path unless path.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
# Look in the standard locations, because even if port or fink are
|
|
|
|
# not in the path they can still break builds if the build scripts
|
|
|
|
# have these paths baked in.
|
2015-08-03 13:09:07 +01:00
|
|
|
%w[/sw/bin/fink /opt/local/bin/port].each do |ponk|
|
2013-10-18 12:56:51 -05:00
|
|
|
path = Pathname.new(ponk)
|
|
|
|
paths << path if path.exist?
|
|
|
|
end
|
|
|
|
|
|
|
|
# Finally, some users make their MacPorts or Fink directorie
|
|
|
|
# read-only in order to try out Homebrew, but this doens't work as
|
|
|
|
# some build scripts error out when trying to read from these now
|
|
|
|
# unreadable paths.
|
2015-08-03 13:09:07 +01:00
|
|
|
%w[/sw /opt/local].map { |p| Pathname.new(p) }.each do |path|
|
2013-10-18 12:56:51 -05:00
|
|
|
paths << path if path.exist? && !path.readable?
|
|
|
|
end
|
|
|
|
|
|
|
|
paths.uniq
|
|
|
|
end
|
|
|
|
|
|
|
|
def prefer_64_bit?
|
2013-10-28 08:45:36 -07:00
|
|
|
if ENV["HOMEBREW_PREFER_64_BIT"] && version == :leopard
|
|
|
|
Hardware::CPU.is_64_bit?
|
|
|
|
else
|
|
|
|
Hardware::CPU.is_64_bit? && version > :leopard
|
|
|
|
end
|
2013-10-18 12:56:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def preferred_arch
|
2013-11-26 20:23:19 -06:00
|
|
|
if prefer_64_bit?
|
2013-10-18 12:56:51 -05:00
|
|
|
Hardware::CPU.arch_64_bit
|
|
|
|
else
|
|
|
|
Hardware::CPU.arch_32_bit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
STANDARD_COMPILERS = {
|
2016-12-30 20:20:13 +00:00
|
|
|
"2.0" => { gcc_4_0_build: 4061 },
|
|
|
|
"2.5" => { gcc_4_0_build: 5370 },
|
|
|
|
"3.1.4" => { gcc_4_0_build: 5493, gcc_4_2_build: 5577 },
|
|
|
|
"3.2.6" => { gcc_4_0_build: 5494, gcc_4_2_build: 5666, clang: "1.7", clang_build: 77 },
|
|
|
|
"4.0" => { gcc_4_0_build: 5494, gcc_4_2_build: 5666, clang: "2.0", clang_build: 137 },
|
|
|
|
"4.0.1" => { gcc_4_0_build: 5494, gcc_4_2_build: 5666, clang: "2.0", clang_build: 137 },
|
|
|
|
"4.0.2" => { gcc_4_0_build: 5494, gcc_4_2_build: 5666, clang: "2.0", clang_build: 137 },
|
2016-09-17 15:32:44 +01:00
|
|
|
"4.2" => { clang: "3.0", clang_build: 211 },
|
|
|
|
"4.3" => { clang: "3.1", clang_build: 318 },
|
|
|
|
"4.3.1" => { clang: "3.1", clang_build: 318 },
|
|
|
|
"4.3.2" => { clang: "3.1", clang_build: 318 },
|
|
|
|
"4.3.3" => { clang: "3.1", clang_build: 318 },
|
|
|
|
"4.4" => { clang: "4.0", clang_build: 421 },
|
|
|
|
"4.4.1" => { clang: "4.0", clang_build: 421 },
|
|
|
|
"4.5" => { clang: "4.1", clang_build: 421 },
|
|
|
|
"4.5.1" => { clang: "4.1", clang_build: 421 },
|
|
|
|
"4.5.2" => { clang: "4.1", clang_build: 421 },
|
|
|
|
"4.6" => { clang: "4.2", clang_build: 425 },
|
|
|
|
"4.6.1" => { clang: "4.2", clang_build: 425 },
|
|
|
|
"4.6.2" => { clang: "4.2", clang_build: 425 },
|
|
|
|
"4.6.3" => { clang: "4.2", clang_build: 425 },
|
|
|
|
"5.0" => { clang: "5.0", clang_build: 500 },
|
|
|
|
"5.0.1" => { clang: "5.0", clang_build: 500 },
|
|
|
|
"5.0.2" => { clang: "5.0", clang_build: 500 },
|
|
|
|
"5.1" => { clang: "5.1", clang_build: 503 },
|
|
|
|
"5.1.1" => { clang: "5.1", clang_build: 503 },
|
|
|
|
"6.0" => { clang: "6.0", clang_build: 600 },
|
|
|
|
"6.0.1" => { clang: "6.0", clang_build: 600 },
|
|
|
|
"6.1" => { clang: "6.0", clang_build: 600 },
|
|
|
|
"6.1.1" => { clang: "6.0", clang_build: 600 },
|
|
|
|
"6.2" => { clang: "6.0", clang_build: 600 },
|
|
|
|
"6.3" => { clang: "6.1", clang_build: 602 },
|
|
|
|
"6.3.1" => { clang: "6.1", clang_build: 602 },
|
|
|
|
"6.3.2" => { clang: "6.1", clang_build: 602 },
|
|
|
|
"6.4" => { clang: "6.1", clang_build: 602 },
|
|
|
|
"7.0" => { clang: "7.0", clang_build: 700 },
|
|
|
|
"7.0.1" => { clang: "7.0", clang_build: 700 },
|
|
|
|
"7.1" => { clang: "7.0", clang_build: 700 },
|
|
|
|
"7.1.1" => { clang: "7.0", clang_build: 700 },
|
|
|
|
"7.2" => { clang: "7.0", clang_build: 700 },
|
|
|
|
"7.2.1" => { clang: "7.0", clang_build: 700 },
|
|
|
|
"7.3" => { clang: "7.3", clang_build: 703 },
|
|
|
|
"7.3.1" => { clang: "7.3", clang_build: 703 },
|
|
|
|
"8.0" => { clang: "8.0", clang_build: 800 },
|
2017-03-28 11:16:02 -04:00
|
|
|
"8.1" => { clang: "8.0", clang_build: 800 },
|
|
|
|
"8.2" => { clang: "8.0", clang_build: 800 },
|
|
|
|
"8.2.1" => { clang: "8.0", clang_build: 800 },
|
|
|
|
"8.3" => { clang: "8.1", clang_build: 802 },
|
2017-04-18 20:40:20 -04:00
|
|
|
"8.3.1" => { clang: "8.1", clang_build: 802 },
|
|
|
|
"8.3.2" => { clang: "8.1", clang_build: 802 },
|
2017-06-06 04:14:55 +01:00
|
|
|
"8.3.3" => { clang: "8.1", clang_build: 802 },
|
2017-06-06 04:29:18 +01:00
|
|
|
"9.0" => { clang: "9.0", clang_build: 900 },
|
2016-09-11 17:49:27 +01:00
|
|
|
}.freeze
|
2013-10-18 12:56:51 -05:00
|
|
|
|
|
|
|
def compilers_standard?
|
|
|
|
STANDARD_COMPILERS.fetch(Xcode.version.to_s).all? do |method, build|
|
|
|
|
send(:"#{method}_version") == build
|
|
|
|
end
|
|
|
|
rescue IndexError
|
|
|
|
onoe <<-EOS.undent
|
|
|
|
Homebrew doesn't know what compiler versions ship with your version
|
2016-05-01 14:59:39 +02:00
|
|
|
of Xcode (#{Xcode.version}). Please `brew update` and if that doesn't
|
|
|
|
help, file an issue with the output of `brew --config`:
|
|
|
|
https://github.com/Homebrew/brew/issues
|
2013-10-18 12:56:51 -05:00
|
|
|
|
2014-01-22 17:48:47 -08:00
|
|
|
Note that we only track stable, released versions of Xcode.
|
|
|
|
|
2013-10-18 12:56:51 -05:00
|
|
|
Thanks!
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
|
2014-04-01 20:47:26 -05:00
|
|
|
def app_with_bundle_id(*ids)
|
|
|
|
path = mdfind(*ids).first
|
2015-08-03 13:09:07 +01:00
|
|
|
Pathname.new(path) unless path.nil? || path.empty?
|
2013-10-18 12:56:51 -05:00
|
|
|
end
|
|
|
|
|
2014-04-01 20:47:26 -05:00
|
|
|
def mdfind(*ids)
|
2013-10-18 12:56:51 -05:00
|
|
|
return [] unless OS.mac?
|
2014-04-01 20:47:26 -05:00
|
|
|
(@mdfind ||= {}).fetch(ids) do
|
2014-07-11 15:51:19 -05:00
|
|
|
@mdfind[ids] = Utils.popen_read("/usr/bin/mdfind", mdfind_query(*ids)).split("\n")
|
2013-10-18 12:56:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-01 20:47:26 -05:00
|
|
|
def pkgutil_info(id)
|
2014-04-01 20:49:11 -05:00
|
|
|
(@pkginfo ||= {}).fetch(id) do |key|
|
2014-07-11 15:51:19 -05:00
|
|
|
@pkginfo[key] = Utils.popen_read("/usr/sbin/pkgutil", "--pkg-info", key).strip
|
2013-10-18 12:56:51 -05:00
|
|
|
end
|
|
|
|
end
|
2014-04-01 20:47:26 -05:00
|
|
|
|
|
|
|
def mdfind_query(*ids)
|
|
|
|
ids.map! { |id| "kMDItemCFBundleIdentifier == #{id}" }.join(" || ")
|
|
|
|
end
|
2013-10-18 12:56:51 -05:00
|
|
|
end
|
|
|
|
end
|