2011-03-16 02:46:46 +01:00
|
|
|
require 'pathname'
|
2011-09-14 12:18:35 -07:00
|
|
|
require 'exceptions'
|
2011-03-16 02:46:46 +01:00
|
|
|
|
2009-10-15 14:42:19 +01:00
|
|
|
class Tty
|
|
|
|
class <<self
|
|
|
|
def blue; bold 34; end
|
|
|
|
def white; bold 39; end
|
|
|
|
def red; underline 31; end
|
|
|
|
def yellow; underline 33 ; end
|
|
|
|
def reset; escape 0; end
|
2009-11-11 18:36:50 +00:00
|
|
|
def em; underline 39; end
|
2011-08-23 23:19:32 +01:00
|
|
|
def green; color 92 end
|
|
|
|
|
|
|
|
def width
|
|
|
|
`/usr/bin/tput cols`.strip.to_i
|
|
|
|
end
|
2011-07-25 10:21:44 +08:00
|
|
|
|
2009-10-15 14:42:19 +01:00
|
|
|
private
|
|
|
|
def color n
|
|
|
|
escape "0;#{n}"
|
|
|
|
end
|
|
|
|
def bold n
|
|
|
|
escape "1;#{n}"
|
|
|
|
end
|
|
|
|
def underline n
|
|
|
|
escape "4;#{n}"
|
|
|
|
end
|
|
|
|
def escape n
|
|
|
|
"\033[#{n}m" if $stdout.tty?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-08 14:05:09 +01:00
|
|
|
# args are additional inputs to puts until a nil arg is encountered
|
2009-09-16 19:29:43 +01:00
|
|
|
def ohai title, *sput
|
2012-02-10 17:47:39 -06:00
|
|
|
title = title.to_s[0, Tty.width - 4] if $stdout.tty? unless ARGV.verbose?
|
2009-10-15 14:42:19 +01:00
|
|
|
puts "#{Tty.blue}==>#{Tty.white} #{title}#{Tty.reset}"
|
2010-10-25 21:11:45 -07:00
|
|
|
puts sput unless sput.empty?
|
2009-07-31 02:51:17 +01:00
|
|
|
end
|
2009-07-31 03:56:46 +01:00
|
|
|
|
2011-08-23 23:19:32 +01:00
|
|
|
def oh1 title
|
2012-02-10 17:47:39 -06:00
|
|
|
title = title.to_s[0, Tty.width - 4] if $stdout.tty? unless ARGV.verbose?
|
2011-08-23 23:19:32 +01:00
|
|
|
puts "#{Tty.green}==> #{Tty.reset}#{title}"
|
|
|
|
end
|
|
|
|
|
2009-07-31 03:56:46 +01:00
|
|
|
def opoo warning
|
2009-10-15 14:42:19 +01:00
|
|
|
puts "#{Tty.red}Warning#{Tty.reset}: #{warning}"
|
2009-08-10 16:48:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def onoe error
|
2009-10-01 15:41:15 +01:00
|
|
|
lines = error.to_s.split'\n'
|
2009-10-15 14:42:19 +01:00
|
|
|
puts "#{Tty.red}Error#{Tty.reset}: #{lines.shift}"
|
2010-10-25 21:11:45 -07:00
|
|
|
puts lines unless lines.empty?
|
2009-08-10 16:48:30 +01:00
|
|
|
end
|
|
|
|
|
2012-04-14 17:17:16 +10:00
|
|
|
def ofail error
|
2012-04-30 14:08:59 +10:00
|
|
|
onoe error
|
|
|
|
Homebrew.failed = true
|
|
|
|
end
|
|
|
|
|
|
|
|
def odie error
|
2012-04-14 17:17:16 +10:00
|
|
|
onoe error
|
|
|
|
exit 1
|
|
|
|
end
|
2010-11-09 13:00:33 +00:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
def pretty_duration s
|
2009-09-03 20:58:33 +01:00
|
|
|
return "2 seconds" if s < 3 # avoids the plural problem ;)
|
|
|
|
return "#{s.to_i} seconds" if s < 120
|
|
|
|
return "%.1f minutes" % (s/60)
|
2009-08-10 16:48:30 +01:00
|
|
|
end
|
|
|
|
|
2010-08-20 10:01:49 -07:00
|
|
|
def interactive_shell f=nil
|
|
|
|
unless f.nil?
|
|
|
|
ENV['HOMEBREW_DEBUG_PREFIX'] = f.prefix
|
|
|
|
ENV['HOMEBREW_DEBUG_INSTALL'] = f.name
|
|
|
|
end
|
|
|
|
|
2010-06-11 17:18:05 -07:00
|
|
|
fork {exec ENV['SHELL'] }
|
2009-11-09 17:44:29 +00:00
|
|
|
Process.wait
|
|
|
|
unless $?.success?
|
|
|
|
puts "Aborting due to non-zero exit status"
|
|
|
|
exit $?
|
|
|
|
end
|
2009-07-31 03:56:46 +01:00
|
|
|
end
|
2009-08-11 12:20:55 -07:00
|
|
|
|
2010-01-13 09:00:51 +00:00
|
|
|
module Homebrew
|
|
|
|
def self.system cmd, *args
|
|
|
|
puts "#{cmd} #{args*' '}" if ARGV.verbose?
|
|
|
|
fork do
|
|
|
|
yield if block_given?
|
|
|
|
args.collect!{|arg| arg.to_s}
|
|
|
|
exec(cmd, *args) rescue nil
|
|
|
|
exit! 1 # never gets here unless exec failed
|
|
|
|
end
|
|
|
|
Process.wait
|
|
|
|
$?.success?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-11 12:20:55 -07:00
|
|
|
# Kernel.system but with exceptions
|
|
|
|
def safe_system cmd, *args
|
2010-09-11 20:22:54 +01:00
|
|
|
unless Homebrew.system cmd, *args
|
2011-03-14 13:30:46 -07:00
|
|
|
args = args.map{ |arg| arg.to_s.gsub " ", "\\ " } * " "
|
2011-09-19 23:29:07 +01:00
|
|
|
raise ErrorDuringExecution, "Failure while executing: #{cmd} #{args}"
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
2010-01-13 09:00:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# prints no output
|
|
|
|
def quiet_system cmd, *args
|
|
|
|
Homebrew.system(cmd, *args) do
|
|
|
|
$stdout.close
|
|
|
|
$stderr.close
|
2009-11-09 17:44:29 +00:00
|
|
|
end
|
2009-08-11 12:20:55 -07:00
|
|
|
end
|
|
|
|
|
2009-09-04 15:28:18 +01:00
|
|
|
def curl *args
|
2011-09-14 12:18:35 -07:00
|
|
|
curl = Pathname.new '/usr/bin/curl'
|
2011-09-19 23:29:07 +01:00
|
|
|
raise "#{curl} is not executable" unless curl.exist? and curl.executable?
|
2011-09-14 12:18:35 -07:00
|
|
|
|
|
|
|
args = [HOMEBREW_CURL_ARGS, HOMEBREW_USER_AGENT, *args]
|
2011-08-26 13:27:55 +01:00
|
|
|
# See https://github.com/mxcl/homebrew/issues/6103
|
|
|
|
args << "--insecure" if MacOS.version < 10.6
|
2011-12-07 19:09:00 -06:00
|
|
|
args << "--verbose" if ENV['HOMEBREW_CURL_VERBOSE']
|
2012-02-10 17:47:39 -06:00
|
|
|
args << "--silent" unless $stdout.tty?
|
2011-08-26 13:27:55 +01:00
|
|
|
|
2011-09-19 23:29:07 +01:00
|
|
|
safe_system curl, *args
|
2009-08-11 12:20:55 -07:00
|
|
|
end
|
2009-09-04 15:22:25 -07:00
|
|
|
|
2011-01-01 00:49:05 +00:00
|
|
|
def puts_columns items, star_items=[]
|
2009-12-18 16:28:30 -08:00
|
|
|
return if items.empty?
|
|
|
|
|
2011-01-01 00:49:05 +00:00
|
|
|
if star_items && star_items.any?
|
|
|
|
items = items.map{|item| star_items.include?(item) ? "#{item}*" : item}
|
|
|
|
end
|
|
|
|
|
2009-09-22 20:43:06 +02:00
|
|
|
if $stdout.tty?
|
2009-11-14 13:43:07 +13:00
|
|
|
# determine the best width to display for different console sizes
|
2010-01-16 13:12:38 +00:00
|
|
|
console_width = `/bin/stty size`.chomp.split(" ").last.to_i
|
|
|
|
console_width = 80 if console_width <= 0
|
2009-11-14 13:43:07 +13:00
|
|
|
longest = items.sort_by { |item| item.length }.last
|
|
|
|
optimal_col_width = (console_width.to_f / (longest.length + 2).to_f).floor
|
|
|
|
cols = optimal_col_width > 1 ? optimal_col_width : 1
|
|
|
|
|
2010-03-06 03:11:30 +02:00
|
|
|
IO.popen("/usr/bin/pr -#{cols} -t -w#{console_width}", "w"){|io| io.puts(items) }
|
2009-09-22 20:43:06 +02:00
|
|
|
else
|
2010-10-25 21:11:45 -07:00
|
|
|
puts items
|
2009-09-22 20:43:06 +02:00
|
|
|
end
|
2009-09-04 15:22:25 -07:00
|
|
|
end
|
2009-09-05 14:03:41 -04:00
|
|
|
|
2012-05-07 20:32:04 -05:00
|
|
|
def which cmd
|
|
|
|
path = `/usr/bin/which #{cmd} 2>/dev/null`.chomp
|
2012-03-03 15:50:24 -08:00
|
|
|
if path.empty?
|
|
|
|
nil
|
|
|
|
else
|
|
|
|
Pathname.new(path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-16 14:27:58 -08:00
|
|
|
def which_editor
|
|
|
|
editor = ENV['HOMEBREW_EDITOR'] || ENV['EDITOR']
|
|
|
|
# If an editor wasn't set, try to pick a sane default
|
|
|
|
return editor unless editor.nil?
|
|
|
|
|
|
|
|
# Find Textmate
|
2012-05-07 20:32:04 -05:00
|
|
|
return 'mate' if which "mate"
|
2011-12-16 14:27:58 -08:00
|
|
|
# Find # BBEdit / TextWrangler
|
2012-05-07 20:32:04 -05:00
|
|
|
return 'edit' if which "edit"
|
2011-12-16 14:27:58 -08:00
|
|
|
# Default to vim
|
|
|
|
return '/usr/bin/vim'
|
|
|
|
end
|
|
|
|
|
2009-09-05 14:03:41 -04:00
|
|
|
def exec_editor *args
|
2010-11-08 13:06:45 +00:00
|
|
|
return if args.to_s.empty?
|
|
|
|
|
2011-04-12 10:09:33 -07:00
|
|
|
# Invoke bash to evaluate env vars in $EDITOR
|
|
|
|
# This also gets us proper argument quoting.
|
|
|
|
# See: https://github.com/mxcl/homebrew/issues/5123
|
2011-12-16 14:27:58 -08:00
|
|
|
system "bash", "-c", which_editor + ' "$@"', "--", *args
|
2009-09-05 14:03:41 -04:00
|
|
|
end
|
2009-09-08 15:31:28 -07:00
|
|
|
|
2010-11-09 13:00:33 +00:00
|
|
|
# GZips the given paths, and returns the gzipped paths
|
2010-09-12 22:55:52 +02:00
|
|
|
def gzip *paths
|
|
|
|
paths.collect do |path|
|
|
|
|
system "/usr/bin/gzip", path
|
2010-11-09 13:00:33 +00:00
|
|
|
Pathname.new("#{path}.gz")
|
2010-09-12 22:55:52 +02:00
|
|
|
end
|
2010-01-29 10:15:33 -08:00
|
|
|
end
|
|
|
|
|
2010-05-10 10:14:20 -07:00
|
|
|
# Returns array of architectures that the given command or library is built for.
|
2010-01-13 11:14:58 +00:00
|
|
|
def archs_for_command cmd
|
2012-05-28 20:39:05 -05:00
|
|
|
cmd = which(cmd) unless Pathname.new(cmd).absolute?
|
|
|
|
Pathname.new(cmd).archs
|
2009-09-08 15:31:28 -07:00
|
|
|
end
|
2009-10-15 12:36:09 +01:00
|
|
|
|
2009-12-17 12:41:54 -08:00
|
|
|
def inreplace path, before=nil, after=nil
|
2010-02-20 02:07:51 +00:00
|
|
|
[*path].each do |path|
|
2010-02-19 15:56:21 +00:00
|
|
|
f = File.open(path, 'r')
|
|
|
|
s = f.read
|
2009-12-17 12:41:54 -08:00
|
|
|
|
2010-02-19 15:56:21 +00:00
|
|
|
if before == nil and after == nil
|
2010-11-12 21:05:35 -08:00
|
|
|
s.extend(StringInreplaceExtension)
|
2010-02-19 15:56:21 +00:00
|
|
|
yield s
|
|
|
|
else
|
2012-02-23 21:05:49 -06:00
|
|
|
sub = s.gsub!(before, after)
|
|
|
|
if sub.nil?
|
|
|
|
opoo "inreplace in '#{path}' failed"
|
|
|
|
puts "Expected replacement of '#{before}' with '#{after}'"
|
|
|
|
end
|
2010-02-19 15:56:21 +00:00
|
|
|
end
|
2009-12-17 12:41:54 -08:00
|
|
|
|
2010-02-19 15:56:21 +00:00
|
|
|
f.reopen(path, 'w').write(s)
|
|
|
|
f.close
|
|
|
|
end
|
2009-10-15 12:36:09 +01:00
|
|
|
end
|
2009-11-06 17:09:14 +00:00
|
|
|
|
|
|
|
def ignore_interrupts
|
|
|
|
std_trap = trap("INT") {}
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
trap("INT", std_trap)
|
|
|
|
end
|
2009-11-09 18:24:36 +00:00
|
|
|
|
|
|
|
def nostdout
|
|
|
|
if ARGV.verbose?
|
|
|
|
yield
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
require 'stringio'
|
|
|
|
real_stdout = $stdout
|
|
|
|
$stdout = StringIO.new
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
$stdout = real_stdout
|
|
|
|
end
|
|
|
|
end
|
2010-01-13 09:00:51 +00:00
|
|
|
end
|
2010-04-07 21:01:12 -07:00
|
|
|
|
2010-09-11 20:22:54 +01:00
|
|
|
module MacOS extend self
|
2011-08-26 13:27:55 +01:00
|
|
|
def version
|
|
|
|
MACOS_VERSION
|
|
|
|
end
|
2011-03-16 02:46:46 +01:00
|
|
|
|
2012-03-07 20:44:19 -05:00
|
|
|
def cat
|
|
|
|
if mountain_lion?
|
|
|
|
:mountainlion
|
|
|
|
elsif lion?
|
|
|
|
:lion
|
|
|
|
elsif snow_leopard?
|
|
|
|
:snowleopard
|
|
|
|
elsif leopard?
|
|
|
|
:leopard
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-16 18:00:04 +00:00
|
|
|
def dev_tools_path
|
|
|
|
@dev_tools_path ||= if File.file? "/usr/bin/cc" and File.file? "/usr/bin/make"
|
|
|
|
# probably a safe enough assumption
|
|
|
|
"/usr/bin"
|
|
|
|
elsif File.file? "#{xcode_prefix}/usr/bin/make"
|
|
|
|
# cc stopped existing with Xcode 4.3, there are c89 and c99 options though
|
|
|
|
"#{xcode_prefix}/usr/bin"
|
|
|
|
else
|
|
|
|
# yes this seems dumb, but we can't throw because the existance of
|
|
|
|
# dev tools is not mandatory for installing formula. Eventually we
|
2012-03-28 20:21:09 -03:00
|
|
|
# should make formula specify if they need dev tools or not.
|
2012-02-16 18:00:04 +00:00
|
|
|
"/usr/bin"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-21 10:32:48 +00:00
|
|
|
def xctools_fucked?
|
|
|
|
# Xcode 4.3 tools hang if "/" is set
|
|
|
|
`/usr/bin/xcode-select -print-path 2>/dev/null`.chomp == "/"
|
|
|
|
end
|
|
|
|
|
2012-02-18 01:53:42 +00:00
|
|
|
def default_cc
|
2012-02-21 10:32:48 +00:00
|
|
|
cc = unless xctools_fucked?
|
|
|
|
out = `/usr/bin/xcrun -find cc 2> /dev/null`.chomp
|
|
|
|
out if $?.success?
|
|
|
|
end
|
|
|
|
cc = "#{dev_tools_path}/cc" if cc.nil? or cc.empty?
|
2012-02-18 01:53:42 +00:00
|
|
|
|
|
|
|
unless File.executable? cc
|
|
|
|
# If xcode-select isn't setup then xcrun fails and on Xcode 4.3
|
|
|
|
# the cc binary is not at #{dev_tools_path}. This return is almost
|
|
|
|
# worthless however since in this particular setup nothing much builds
|
|
|
|
# but I wrote the code now and maybe we'll fix the other issues later.
|
|
|
|
cc = "#{xcode_prefix}/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc"
|
2012-02-17 13:34:06 +00:00
|
|
|
end
|
|
|
|
|
2012-02-17 13:08:46 +00:00
|
|
|
Pathname.new(cc).realpath.basename.to_s rescue nil
|
2011-03-16 02:46:46 +01:00
|
|
|
end
|
|
|
|
|
2011-08-31 16:59:04 +01:00
|
|
|
def default_compiler
|
|
|
|
case default_cc
|
|
|
|
when /^gcc/ then :gcc
|
|
|
|
when /^llvm/ then :llvm
|
|
|
|
when "clang" then :clang
|
2012-02-16 18:00:04 +00:00
|
|
|
else
|
|
|
|
# guess :(
|
2012-02-16 23:39:57 +00:00
|
|
|
if xcode_version >= "4.3"
|
|
|
|
:clang
|
|
|
|
elsif xcode_version >= "4.2"
|
2012-02-16 18:00:04 +00:00
|
|
|
:llvm
|
|
|
|
else
|
|
|
|
:gcc
|
|
|
|
end
|
2011-08-31 16:59:04 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-11 20:22:54 +01:00
|
|
|
def gcc_42_build_version
|
2012-02-16 18:00:04 +00:00
|
|
|
@gcc_42_build_version ||= if File.exist? "#{dev_tools_path}/gcc-4.2" \
|
|
|
|
and not Pathname.new("#{dev_tools_path}/gcc-4.2").realpath.basename.to_s =~ /^llvm/
|
|
|
|
`#{dev_tools_path}/gcc-4.2 --version` =~ /build (\d{4,})/
|
2010-09-11 20:22:54 +01:00
|
|
|
$1.to_i
|
|
|
|
end
|
|
|
|
end
|
2010-04-07 21:01:12 -07:00
|
|
|
|
2010-09-11 20:22:54 +01:00
|
|
|
def gcc_40_build_version
|
2012-02-16 18:00:04 +00:00
|
|
|
@gcc_40_build_version ||= if File.exist? "#{dev_tools_path}/gcc-4.0"
|
|
|
|
`#{dev_tools_path}/gcc-4.0 --version` =~ /build (\d{4,})/
|
2010-09-11 20:22:54 +01:00
|
|
|
$1.to_i
|
Add command "brew --env"
"brew --env" will set up a build environment and then dump certain ENV
variables (CC, CXX, LD, CFLAGS, CXXFLAGS, MAKEFLAGS).
If any of CC, CXX, LD are symlinks, now also output the target compiler.
(Typically these will be symlinks from eg /usr/bin/cc to /usr/bin/gcc-4.2).
This is a diagnostic command which may be merged into --config, turned
into an external command, or removed if it doesn't turn out to be useful.
2010-07-13 14:20:52 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-11-13 22:45:22 +00:00
|
|
|
def xcode_prefix
|
|
|
|
@xcode_prefix ||= begin
|
2012-02-17 13:08:46 +00:00
|
|
|
path = `/usr/bin/xcode-select -print-path 2>/dev/null`.chomp
|
2010-11-13 22:45:22 +00:00
|
|
|
path = Pathname.new path
|
2012-02-20 18:24:36 +00:00
|
|
|
if $?.success? and path.directory? and path.absolute?
|
2010-11-13 22:45:22 +00:00
|
|
|
path
|
|
|
|
elsif File.directory? '/Developer'
|
|
|
|
# we do this to support cowboys who insist on installing
|
|
|
|
# only a subset of Xcode
|
2011-04-26 14:13:53 -07:00
|
|
|
Pathname.new '/Developer'
|
2012-02-16 15:29:22 +00:00
|
|
|
elsif File.directory? '/Applications/Xcode.app/Contents/Developer'
|
|
|
|
# fallback for broken Xcode 4.3 installs
|
|
|
|
Pathname.new '/Applications/Xcode.app/Contents/Developer'
|
2010-11-13 22:45:22 +00:00
|
|
|
else
|
2012-02-17 12:12:05 +00:00
|
|
|
# Ask Spotlight where Xcode is. If the user didn't install the
|
|
|
|
# helper tools and installed Xcode in a non-conventional place, this
|
|
|
|
# is our only option. See: http://superuser.com/questions/390757
|
|
|
|
path = `mdfind "kMDItemDisplayName==Xcode&&kMDItemKind==Application"`
|
|
|
|
path = "#{path}/Contents/Developer"
|
|
|
|
if path.empty? or not File.directory? path
|
|
|
|
nil
|
|
|
|
else
|
|
|
|
path
|
|
|
|
end
|
2010-11-13 22:45:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-18 16:10:31 +01:00
|
|
|
def xcode_version
|
2011-08-23 23:19:32 +01:00
|
|
|
@xcode_version ||= begin
|
2012-03-16 15:14:20 +13:00
|
|
|
return "0" unless MACOS
|
|
|
|
|
2012-03-16 00:59:09 +00:00
|
|
|
# this shortcut makes xcode_version work for people who don't realise you
|
|
|
|
# need to install the CLI tools
|
|
|
|
xcode43build = "/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild"
|
|
|
|
if File.file? xcode43build
|
|
|
|
`#{xcode43build} -version 2>/dev/null` =~ /Xcode (\d(\.\d)*)/
|
|
|
|
return $1 if $1
|
|
|
|
end
|
|
|
|
|
2012-02-20 18:24:36 +00:00
|
|
|
# Xcode 4.3 xc* tools hang indefinately if xcode-select path is set thus
|
|
|
|
raise if `xcode-select -print-path 2>/dev/null`.chomp == "/"
|
|
|
|
|
2012-05-07 20:32:04 -05:00
|
|
|
raise unless which "xcodebuild"
|
2012-02-20 18:24:36 +00:00
|
|
|
`xcodebuild -version 2>/dev/null` =~ /Xcode (\d(\.\d)*)/
|
|
|
|
raise if $1.nil? or not $?.success?
|
2011-08-23 23:19:32 +01:00
|
|
|
$1
|
2011-09-02 11:53:41 +01:00
|
|
|
rescue
|
2012-02-26 12:58:54 +00:00
|
|
|
# For people who's xcode-select is unset, or who have installed
|
|
|
|
# xcode-gcc-installer or whatever other combinations we can try and
|
|
|
|
# supprt. See https://github.com/mxcl/homebrew/wiki/Xcode
|
2012-03-16 00:59:09 +00:00
|
|
|
case llvm_build_version.to_i
|
|
|
|
when 1..2063 then "3.1.0"
|
2011-09-02 11:53:41 +01:00
|
|
|
when 2064..2065 then "3.1.4"
|
|
|
|
when 2366..2325
|
|
|
|
# we have no data for this range so we are guessing
|
|
|
|
"3.2.0"
|
|
|
|
when 2326
|
|
|
|
# also applies to "3.2.3"
|
|
|
|
"3.2.4"
|
|
|
|
when 2327..2333 then "3.2.5"
|
|
|
|
when 2335
|
|
|
|
# this build number applies to 3.2.6, 4.0 and 4.1
|
|
|
|
# https://github.com/mxcl/homebrew/wiki/Xcode
|
|
|
|
"4.0"
|
|
|
|
else
|
2012-02-26 12:58:54 +00:00
|
|
|
case (clang_version.to_f * 10).to_i
|
2012-03-16 00:59:09 +00:00
|
|
|
when 0
|
|
|
|
"dunno"
|
|
|
|
when 1..14
|
2012-02-26 12:58:54 +00:00
|
|
|
"3.2.2"
|
|
|
|
when 15
|
|
|
|
"3.2.4"
|
|
|
|
when 16
|
|
|
|
"3.2.5"
|
|
|
|
when 17..20
|
|
|
|
"4.0"
|
|
|
|
when 21
|
|
|
|
"4.1"
|
|
|
|
when 22..30
|
|
|
|
"4.2"
|
|
|
|
when 31
|
|
|
|
"4.3"
|
|
|
|
else
|
|
|
|
"4.3"
|
|
|
|
end
|
2011-09-02 11:53:41 +01:00
|
|
|
end
|
2011-08-23 23:19:32 +01:00
|
|
|
end
|
2011-05-18 16:10:31 +01:00
|
|
|
end
|
|
|
|
|
2010-09-11 20:22:54 +01:00
|
|
|
def llvm_build_version
|
2011-09-03 11:21:31 +01:00
|
|
|
# for Xcode 3 on OS X 10.5 this will not exist
|
|
|
|
# NOTE may not be true anymore but we can't test
|
2012-02-16 18:00:04 +00:00
|
|
|
@llvm_build_version ||= if File.exist? "#{dev_tools_path}/llvm-gcc"
|
|
|
|
`#{dev_tools_path}/llvm-gcc --version` =~ /LLVM build (\d{4,})/
|
2011-09-03 11:21:31 +01:00
|
|
|
$1.to_i
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
2010-04-07 21:01:12 -07:00
|
|
|
end
|
2010-06-29 10:21:40 -07:00
|
|
|
|
2011-11-03 21:08:59 -05:00
|
|
|
def clang_version
|
2012-02-16 18:00:04 +00:00
|
|
|
@clang_version ||= if File.exist? "#{dev_tools_path}/clang"
|
|
|
|
`#{dev_tools_path}/clang --version` =~ /clang version (\d\.\d)/
|
2011-11-03 21:08:59 -05:00
|
|
|
$1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def clang_build_version
|
2012-02-16 18:00:04 +00:00
|
|
|
@clang_build_version ||= if File.exist? "#{dev_tools_path}/clang"
|
|
|
|
`#{dev_tools_path}/clang --version` =~ %r[tags/Apple/clang-(\d{2,})]
|
2012-01-11 02:02:32 -06:00
|
|
|
$1.to_i
|
2011-11-03 21:08:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-11-09 13:00:33 +00:00
|
|
|
def x11_installed?
|
|
|
|
Pathname.new('/usr/X11/lib/libpng.dylib').exist?
|
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
|
|
|
|
def macports_or_fink_installed?
|
|
|
|
# See these issues for some history:
|
|
|
|
# http://github.com/mxcl/homebrew/issues/#issue/13
|
|
|
|
# http://github.com/mxcl/homebrew/issues/#issue/41
|
|
|
|
# http://github.com/mxcl/homebrew/issues/#issue/48
|
2012-03-16 15:14:20 +13:00
|
|
|
return false unless MACOS
|
2010-09-11 20:22:54 +01:00
|
|
|
|
|
|
|
%w[port fink].each do |ponk|
|
2012-05-13 19:00:10 -05:00
|
|
|
path = which(ponk)
|
|
|
|
return ponk unless path.nil?
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# we do the above check because macports can be relocated and fink may be
|
|
|
|
# able to be relocated in the future. This following check is because if
|
|
|
|
# fink and macports are not in the PATH but are still installed it can
|
|
|
|
# *still* break the build -- because some build scripts hardcode these paths:
|
|
|
|
%w[/sw/bin/fink /opt/local/bin/port].each do |ponk|
|
|
|
|
return ponk if File.exist? ponk
|
|
|
|
end
|
|
|
|
|
|
|
|
# finally, sometimes people make their MacPorts or Fink read-only so they
|
|
|
|
# can quickly test Homebrew out, but still in theory obey the README's
|
|
|
|
# advise to rename the root directory. This doesn't work, many build scripts
|
|
|
|
# error out when they try to read from these now unreadable directories.
|
|
|
|
%w[/sw /opt/local].each do |path|
|
|
|
|
path = Pathname.new(path)
|
|
|
|
return path if path.exist? and not path.readable?
|
|
|
|
end
|
|
|
|
|
|
|
|
false
|
|
|
|
end
|
2011-03-18 10:30:26 -07:00
|
|
|
|
2011-04-08 11:16:37 -07:00
|
|
|
def leopard?
|
|
|
|
10.5 == MACOS_VERSION
|
|
|
|
end
|
|
|
|
|
|
|
|
def snow_leopard?
|
|
|
|
10.6 <= MACOS_VERSION # Actually Snow Leopard or newer
|
|
|
|
end
|
|
|
|
|
2011-07-25 10:21:44 +08:00
|
|
|
def lion?
|
2012-02-21 20:14:30 -08:00
|
|
|
10.7 <= MACOS_VERSION # Actually Lion or newer
|
|
|
|
end
|
|
|
|
|
|
|
|
def mountain_lion?
|
|
|
|
10.8 <= MACOS_VERSION # Actually Mountain Lion or newer
|
2011-07-25 10:21:44 +08:00
|
|
|
end
|
|
|
|
|
2011-03-18 10:30:26 -07:00
|
|
|
def prefer_64_bit?
|
2012-02-21 20:14:30 -08:00
|
|
|
Hardware.is_64_bit? and not leopard?
|
2011-03-18 10:30:26 -07:00
|
|
|
end
|
2012-04-08 11:10:22 -05:00
|
|
|
|
|
|
|
StandardCompilers = {
|
2012-04-15 17:49:49 -05:00
|
|
|
"3.1.4" => {:gcc_40_build_version=>5493, :gcc_42_build_version=>5577},
|
2012-04-08 11:10:22 -05:00
|
|
|
"3.2.6" => {:gcc_40_build_version=>5494, :gcc_42_build_version=>5666, :llvm_build_version=>2335, :clang_version=>"1.7", :clang_build_version=>77},
|
2012-04-11 21:42:16 -05:00
|
|
|
"4.0" => {:gcc_40_build_version=>5494, :gcc_42_build_version=>5666, :llvm_build_version=>2335, :clang_version=>"2.0", :clang_build_version=>137},
|
2012-04-08 11:10:22 -05:00
|
|
|
"4.0.1" => {:gcc_40_build_version=>5494, :gcc_42_build_version=>5666, :llvm_build_version=>2335, :clang_version=>"2.0", :clang_build_version=>137},
|
|
|
|
"4.0.2" => {:gcc_40_build_version=>5494, :gcc_42_build_version=>5666, :llvm_build_version=>2335, :clang_version=>"2.0", :clang_build_version=>137},
|
2012-04-11 21:42:16 -05:00
|
|
|
"4.2" => {:llvm_build_version=>2336, :clang_version=>"3.0", :clang_build_version=>211},
|
|
|
|
"4.3" => {:llvm_build_version=>2336, :clang_version=>"3.1", :clang_build_version=>318},
|
2012-04-08 11:10:22 -05:00
|
|
|
"4.3.1" => {:llvm_build_version=>2336, :clang_version=>"3.1", :clang_build_version=>318},
|
|
|
|
"4.3.2" => {:llvm_build_version=>2336, :clang_version=>"3.1", :clang_build_version=>318}
|
|
|
|
}
|
|
|
|
|
|
|
|
def compilers_standard?
|
|
|
|
xcode = MacOS.xcode_version
|
2012-04-11 21:42:16 -05:00
|
|
|
# Assume compilers are okay if Xcode version not in hash
|
|
|
|
return true unless StandardCompilers.keys.include? xcode
|
2012-04-08 11:10:22 -05:00
|
|
|
|
|
|
|
StandardCompilers[xcode].all? {|k,v| MacOS.send(k) == v}
|
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
module GitHub extend self
|
|
|
|
def issues_for_formula name
|
|
|
|
# bit basic as depends on the issue at github having the exact name of the
|
|
|
|
# formula in it. Which for stuff like objective-caml is unlikely. So we
|
|
|
|
# really should search for aliases too.
|
|
|
|
|
|
|
|
name = f.name if Formula === name
|
|
|
|
|
|
|
|
require 'open-uri'
|
2012-06-12 11:51:05 -05:00
|
|
|
require 'vendor/multi_json'
|
2010-09-11 20:22:54 +01:00
|
|
|
|
|
|
|
issues = []
|
|
|
|
|
2012-06-12 11:51:05 -05:00
|
|
|
uri = URI.parse("https://api.github.com/legacy/issues/search/mxcl/homebrew/open/#{name}")
|
|
|
|
|
|
|
|
open uri do |f|
|
|
|
|
MultiJson.decode(f.read)['issues'].each do |issue|
|
2011-08-31 15:39:16 +01:00
|
|
|
# don't include issues that just refer to the tool in their body
|
2012-06-12 11:51:05 -05:00
|
|
|
issues << issue['html_url'] if issue['title'].include? name
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
issues
|
|
|
|
rescue
|
|
|
|
[]
|
|
|
|
end
|
2012-01-11 20:49:08 -06:00
|
|
|
|
|
|
|
def find_pull_requests rx
|
|
|
|
require 'open-uri'
|
|
|
|
require 'vendor/multi_json'
|
|
|
|
|
2012-01-14 18:39:24 +04:00
|
|
|
query = rx.source.delete('.*').gsub('\\', '')
|
2012-06-12 11:51:05 -05:00
|
|
|
uri = URI.parse("https://api.github.com/legacy/issues/search/mxcl/homebrew/open/#{query}")
|
2012-01-11 20:49:08 -06:00
|
|
|
|
|
|
|
open uri do |f|
|
2012-06-12 11:51:05 -05:00
|
|
|
MultiJson.decode(f.read)['issues'].each do |pull|
|
|
|
|
yield pull['pull_request_url'] if rx.match pull['title'] and pull['pull_request_url']
|
2012-01-11 20:49:08 -06:00
|
|
|
end
|
2012-01-13 18:30:40 -06:00
|
|
|
end
|
2012-01-11 20:49:08 -06:00
|
|
|
rescue
|
2012-01-12 21:10:03 -06:00
|
|
|
nil
|
2012-01-11 20:49:08 -06:00
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|