2009-05-21 00:04:43 +01:00
|
|
|
#!/usr/bin/ruby
|
2009-09-03 17:10:35 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2009-09-04 15:28:18 +01:00
|
|
|
ENV['RUBYLIB']=HOMEBREW_RUBYLIB=File.expand_path(__FILE__+'/../../Library/Homebrew')
|
|
|
|
$:.unshift HOMEBREW_RUBYLIB
|
|
|
|
require 'global'
|
2009-08-10 16:48:30 +01:00
|
|
|
require 'brew.h'
|
|
|
|
|
2009-09-03 22:39:49 +01:00
|
|
|
if %w[/ /usr].include? HOMEBREW_PREFIX.to_s then abort <<-EOS
|
|
|
|
You have placed Homebrew at the prefix: #{HOMEBREW_PREFIX}
|
|
|
|
This is not currently supported. Voice your support for this feature at:
|
|
|
|
#{HOMEBREW_WWW}
|
|
|
|
EOS
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
2009-09-23 16:41:47 +01:00
|
|
|
|
|
|
|
# remove MacPorts and Fink from the PATH, this prevents issues like:
|
|
|
|
# http://github.com/mxcl/homebrew/issues/#issue/13
|
|
|
|
# http://github.com/mxcl/homebrew/issues/#issue/48
|
|
|
|
fix_PATH
|
|
|
|
|
2009-09-23 16:44:10 +01:00
|
|
|
if `/usr/bin/sw_vers -productVersion` =~ /10\.(\d)\.(\d+)/ and $1.to_i < 5
|
2009-08-12 01:56:40 +01:00
|
|
|
onoe "Homebrew requires Leopard or higher"
|
|
|
|
abort "But thanks for your interest anyway!"
|
|
|
|
end
|
2009-09-03 22:39:49 +01:00
|
|
|
if Hardware.cpu_type == :ppc or Hardware.cpu_type == :dunno
|
|
|
|
abort "Sorry, Homebrew does not support your computer's CPU architecture."
|
|
|
|
end
|
2009-09-23 16:44:10 +01:00
|
|
|
unless system "/usr/bin/which -s gcc-4.2"
|
2009-09-04 09:46:53 -07:00
|
|
|
abort "Sorry, Homebrew requires gcc 4.2, which is provided by Xcode 3.1"
|
|
|
|
end
|
2009-06-15 01:41:53 +01:00
|
|
|
|
2009-09-18 19:16:39 +01:00
|
|
|
|
2009-06-02 13:39:39 +01:00
|
|
|
begin
|
|
|
|
case ARGV.shift
|
2009-08-10 16:48:30 +01:00
|
|
|
when '--prefix' then puts HOMEBREW_PREFIX
|
2009-08-04 00:12:03 +08:00
|
|
|
when '--cache' then puts HOMEBREW_CACHE
|
2009-08-10 16:48:30 +01:00
|
|
|
when '-h', '--help', '--usage', '-?' then puts ARGV.usage
|
2009-07-24 15:10:01 +01:00
|
|
|
when '-v', '--version' then puts HOMEBREW_VERSION
|
|
|
|
|
2009-07-31 22:10:50 -07:00
|
|
|
when 'home', 'homepage'
|
2009-08-11 00:27:18 +01:00
|
|
|
if ARGV.named_empty?
|
2009-08-10 16:48:30 +01:00
|
|
|
exec "open", HOMEBREW_WWW
|
|
|
|
else
|
|
|
|
exec "open", *ARGV.formulae.collect {|f| f.homepage}
|
|
|
|
end
|
2009-07-31 22:10:50 -07:00
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
when 'ls', 'list'
|
2009-08-23 13:09:15 +01:00
|
|
|
if ARGV.named_empty?
|
|
|
|
ENV['CLICOLOR']=nil
|
|
|
|
exec 'ls', *ARGV.options<<HOMEBREW_CELLAR
|
2009-09-24 21:46:04 +01:00
|
|
|
elsif ARGV.verbose?
|
2009-08-23 13:09:15 +01:00
|
|
|
exec "find", *ARGV.kegs+%w[-not -type d -print]
|
2009-09-24 21:46:04 +01:00
|
|
|
else
|
|
|
|
ARGV.kegs.each { |keg| PrettyListing.new keg }
|
2009-08-23 13:09:15 +01:00
|
|
|
end
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-09-04 15:22:25 -07:00
|
|
|
when 'search', '-S'
|
|
|
|
formulae = (HOMEBREW_PREFIX+'Library'+'Formula').children.sort.map{|f| f.basename('.rb') }
|
|
|
|
puts_columns formulae.grep(Regexp.new(ARGV.first || ''))
|
|
|
|
|
2009-06-26 13:03:49 +01:00
|
|
|
when 'edit'
|
2009-08-11 00:27:18 +01:00
|
|
|
if ARGV.named_empty?
|
2009-09-05 14:03:41 -04:00
|
|
|
# EDITOR isn't a good fit here, we need a GUI client that actually has
|
|
|
|
# a UI for projects, so apologies if this wasn't what you expected,
|
|
|
|
# please improve it! :)
|
|
|
|
exec 'mate', *Dir["#{HOMEBREW_PREFIX}/Library/*"]<<
|
2009-08-10 16:48:30 +01:00
|
|
|
"#{HOMEBREW_PREFIX}/bin/brew"<<
|
2009-09-25 14:25:09 +02:00
|
|
|
"#{HOMEBREW_PREFIX}/README.md"
|
2009-06-26 13:03:49 +01:00
|
|
|
else
|
2009-09-05 14:03:41 -04:00
|
|
|
exec_editor *ARGV.formulae.collect {|f| f.path}
|
2009-06-26 13:03:49 +01:00
|
|
|
end
|
|
|
|
|
2009-06-02 13:39:39 +01:00
|
|
|
when 'install'
|
2009-08-29 18:46:31 +01:00
|
|
|
if ARGV.named_empty?
|
2009-09-04 15:22:25 -07:00
|
|
|
puts "You must specify a formula. Search for available formulae with `brew search'."
|
2009-08-29 18:46:31 +01:00
|
|
|
exit 0
|
|
|
|
end
|
2009-09-16 19:47:40 +01:00
|
|
|
|
|
|
|
raise "Cannot write to #{HOMEBREW_PREFIX}" unless HOMEBREW_PREFIX.writable?
|
2009-09-02 14:15:44 +01:00
|
|
|
|
2009-09-04 15:42:19 +01:00
|
|
|
require 'brewkit'
|
|
|
|
|
2009-09-02 14:15:44 +01:00
|
|
|
if ARGV.verbose?
|
|
|
|
ohai "Build Environment"
|
2009-09-16 11:28:50 +01:00
|
|
|
%w[CFLAGS LDFLAGS CPPFLAGS MAKEFLAGS CC CXX MACOSX_DEPLOYMENT_TARGET].each do |f|
|
2009-09-02 14:15:44 +01:00
|
|
|
puts "#{f}: #{ENV[f]}" unless ENV[f].to_s.empty?
|
|
|
|
end
|
|
|
|
end
|
2009-09-10 14:29:41 +01:00
|
|
|
|
2009-09-21 16:53:04 -07:00
|
|
|
if ARGV.interactive? and ARGV.formulae.length > 1
|
2009-09-10 14:29:41 +01:00
|
|
|
# the reason for this is interactive mode is a little tricky to do
|
|
|
|
# with more than one formula, AND I can't think of a time where you'd
|
|
|
|
# want to do it anyway. If someone comes up with a legitimate use for
|
|
|
|
# this we will adapt the code. "But I might want it!" is not a
|
|
|
|
# legitimate use!
|
|
|
|
raise "Interactive mode can only be used with one formula argument"
|
2009-09-04 15:42:19 +01:00
|
|
|
end
|
2009-09-02 14:15:44 +01:00
|
|
|
|
2009-09-10 14:11:04 +01:00
|
|
|
unless ARGV.force?
|
2009-09-23 16:44:10 +01:00
|
|
|
unless system "/usr/bin/which -s #{ENV.cc}"
|
2009-09-10 14:11:04 +01:00
|
|
|
raise "We cannot find a c compiler, have you installed the latest Xcode?"
|
|
|
|
end
|
2009-09-18 19:16:39 +01:00
|
|
|
formulae = ARGV.formulae.reject do |f|
|
2009-09-10 14:11:04 +01:00
|
|
|
if f.installed?
|
2009-09-03 19:48:00 +02:00
|
|
|
message = "Formula already installed: #{f.prefix}"
|
2009-09-21 16:53:04 -07:00
|
|
|
if ARGV.formulae.length > 1
|
2009-09-03 19:48:00 +02:00
|
|
|
opoo message
|
|
|
|
else
|
|
|
|
puts message # if only one is being installed a warning looks severe
|
|
|
|
end
|
2009-09-10 14:11:04 +01:00
|
|
|
true
|
2009-09-03 19:48:00 +02:00
|
|
|
end
|
Dependency resolution
Specify dependencies in your formula's deps function. You can return an Array,
String or Hash, eg:
def deps
{ :optional => 'libogg', :required => %w[flac sdl], :recommended => 'cmake' }
end
Note currently the Hash is flattened and qualifications are ignored. If you
only return an Array or String, the qualification is assumed to be :required.
Other packaging systems have problems when it comes to packages requiring a
specific version of a package, or some patches that may not work well with
other software. With Homebrew we have some options:
1. If the formula is vanilla but an older version we can cherry-pick the old
version and install it in the Cellar in parallel, but just not symlink it
into /usr/local while forcing the formula that depends on it to link to
that one and not any other versions of it.
2. If the dependency requires patches then we shouldn't install this for use
by any other tools, (I guess this needs to be decided on a per-situation
basis). It can be installed into the parent formula's prefix, and not
symlinked into /usr/local. In this case the dependency's Formula
derivation should be saved in the parent formula's file (check git or
flac for an example of this).
Both the above can be done currently with hacks, so I'll flesh out a proper
way sometime this week.
2009-09-07 01:06:08 +01:00
|
|
|
end
|
2009-09-18 19:16:39 +01:00
|
|
|
exit 0 if formulae.empty?
|
2009-09-10 14:11:04 +01:00
|
|
|
else
|
2009-09-18 19:16:39 +01:00
|
|
|
formulae = ARGV.formulae
|
Dependency resolution
Specify dependencies in your formula's deps function. You can return an Array,
String or Hash, eg:
def deps
{ :optional => 'libogg', :required => %w[flac sdl], :recommended => 'cmake' }
end
Note currently the Hash is flattened and qualifications are ignored. If you
only return an Array or String, the qualification is assumed to be :required.
Other packaging systems have problems when it comes to packages requiring a
specific version of a package, or some patches that may not work well with
other software. With Homebrew we have some options:
1. If the formula is vanilla but an older version we can cherry-pick the old
version and install it in the Cellar in parallel, but just not symlink it
into /usr/local while forcing the formula that depends on it to link to
that one and not any other versions of it.
2. If the dependency requires patches then we shouldn't install this for use
by any other tools, (I guess this needs to be decided on a per-situation
basis). It can be installed into the parent formula's prefix, and not
symlinked into /usr/local. In this case the dependency's Formula
derivation should be saved in the parent formula's file (check git or
flac for an example of this).
Both the above can be done currently with hacks, so I'll flesh out a proper
way sometime this week.
2009-09-07 01:06:08 +01:00
|
|
|
end
|
|
|
|
|
2009-09-22 19:58:10 +01:00
|
|
|
unless ARGV.include? '--ignore-dependencies'
|
|
|
|
deps = []
|
|
|
|
formulae.each { |f| deps += expand_deps f }
|
|
|
|
formulae = deps.reject { |f| f.installed? }
|
|
|
|
end
|
2009-09-03 19:48:00 +02:00
|
|
|
|
2009-09-18 19:16:39 +01:00
|
|
|
require 'set'
|
|
|
|
done = Set.new
|
Dependency resolution
Specify dependencies in your formula's deps function. You can return an Array,
String or Hash, eg:
def deps
{ :optional => 'libogg', :required => %w[flac sdl], :recommended => 'cmake' }
end
Note currently the Hash is flattened and qualifications are ignored. If you
only return an Array or String, the qualification is assumed to be :required.
Other packaging systems have problems when it comes to packages requiring a
specific version of a package, or some patches that may not work well with
other software. With Homebrew we have some options:
1. If the formula is vanilla but an older version we can cherry-pick the old
version and install it in the Cellar in parallel, but just not symlink it
into /usr/local while forcing the formula that depends on it to link to
that one and not any other versions of it.
2. If the dependency requires patches then we shouldn't install this for use
by any other tools, (I guess this needs to be decided on a per-situation
basis). It can be installed into the parent formula's prefix, and not
symlinked into /usr/local. In this case the dependency's Formula
derivation should be saved in the parent formula's file (check git or
flac for an example of this).
Both the above can be done currently with hacks, so I'll flesh out a proper
way sometime this week.
2009-09-07 01:06:08 +01:00
|
|
|
|
2009-09-18 19:16:39 +01:00
|
|
|
require 'beer_events'
|
Dependency resolution
Specify dependencies in your formula's deps function. You can return an Array,
String or Hash, eg:
def deps
{ :optional => 'libogg', :required => %w[flac sdl], :recommended => 'cmake' }
end
Note currently the Hash is flattened and qualifications are ignored. If you
only return an Array or String, the qualification is assumed to be :required.
Other packaging systems have problems when it comes to packages requiring a
specific version of a package, or some patches that may not work well with
other software. With Homebrew we have some options:
1. If the formula is vanilla but an older version we can cherry-pick the old
version and install it in the Cellar in parallel, but just not symlink it
into /usr/local while forcing the formula that depends on it to link to
that one and not any other versions of it.
2. If the dependency requires patches then we shouldn't install this for use
by any other tools, (I guess this needs to be decided on a per-situation
basis). It can be installed into the parent formula's prefix, and not
symlinked into /usr/local. In this case the dependency's Formula
derivation should be saved in the parent formula's file (check git or
flac for an example of this).
Both the above can be done currently with hacks, so I'll flesh out a proper
way sometime this week.
2009-09-07 01:06:08 +01:00
|
|
|
watch_out_for_spill do
|
2009-09-18 19:16:39 +01:00
|
|
|
formulae.each do |f|
|
|
|
|
next if done.include? f.class
|
|
|
|
done << f.class
|
2009-09-03 19:48:00 +02:00
|
|
|
|
2009-09-04 15:28:18 +01:00
|
|
|
# 1. formulae can modify ENV, so we must ensure that each
|
|
|
|
# installation has a pristine ENV when it starts, forking now is
|
|
|
|
# the easiest way to do this
|
|
|
|
# 2. formulae have access to __END__ the only way to allow this is
|
|
|
|
# to make the formula script the executed script
|
2009-09-03 19:48:00 +02:00
|
|
|
pid=fork
|
|
|
|
if pid.nil?
|
2009-09-04 15:28:18 +01:00
|
|
|
exec 'ruby', '-r', "#{HOMEBREW_RUBYLIB}/install", f.path, '--', *ARGV.options
|
2009-09-03 19:48:00 +02:00
|
|
|
else
|
|
|
|
Process.wait pid
|
|
|
|
end
|
|
|
|
#FIXME I don't think $? represents the exit code from the child fork…
|
|
|
|
exit! $? if $? != 0 # exception in other brew will be visible on screen
|
2009-08-10 16:48:30 +01:00
|
|
|
end
|
2009-08-08 14:10:32 +01:00
|
|
|
end
|
|
|
|
|
2009-07-22 20:27:58 +01:00
|
|
|
|
2009-09-08 00:02:28 +02:00
|
|
|
when 'up', 'update'
|
2009-09-17 18:39:47 +01:00
|
|
|
require 'update'
|
2009-09-08 00:02:28 +02:00
|
|
|
updater = RefreshBrew.new
|
2009-09-11 20:09:39 +02:00
|
|
|
old_revision = updater.current_revision
|
2009-09-08 00:02:28 +02:00
|
|
|
unless updater.update_from_masterbrew!
|
2009-09-21 21:41:14 +01:00
|
|
|
puts "Already up-to-date."
|
2009-09-08 00:02:28 +02:00
|
|
|
else
|
2009-09-21 21:41:14 +01:00
|
|
|
puts "Updated Homebrew from #{old_revision} to #{updater.current_revision}."
|
2009-09-11 19:24:37 +02:00
|
|
|
if updater.pending_formulae_changes?
|
2009-09-21 21:41:14 +01:00
|
|
|
ohai "The following formulae were updated:"
|
|
|
|
puts_columns updater.updated_formulae
|
2009-09-11 19:24:37 +02:00
|
|
|
else
|
2009-09-21 21:41:14 +01:00
|
|
|
puts "No formulae were updated." unless updater.pending_formulae_changes?
|
2009-09-11 19:24:37 +02:00
|
|
|
end
|
2009-09-08 00:02:28 +02:00
|
|
|
end
|
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
when 'ln', 'link'
|
2009-08-10 16:48:30 +01:00
|
|
|
ARGV.kegs.each {|keg| puts "#{keg.link} links created for #{keg}"}
|
|
|
|
|
|
|
|
when 'unlink'
|
|
|
|
ARGV.kegs.each {|keg| puts "#{keg.unlink} links removed for #{keg}"}
|
2009-07-22 20:27:58 +01:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
when 'rm', 'uninstall', 'remove'
|
|
|
|
ARGV.kegs.each do |keg|
|
|
|
|
puts "Uninstalling #{keg}..."
|
|
|
|
keg.uninstall
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
2009-08-10 16:48:30 +01:00
|
|
|
prune
|
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
when 'prune'
|
2009-08-10 16:48:30 +01:00
|
|
|
prune
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-09-07 01:34:40 +01:00
|
|
|
# 'make' supported until 0.7 for historic reasons
|
2009-07-24 15:10:01 +01:00
|
|
|
when 'mk', 'make'
|
2009-09-07 01:34:40 +01:00
|
|
|
opoo "`brew make' has changed to `brew create'"
|
|
|
|
puts "This is because make can be confused with the `make' tool."
|
|
|
|
puts "brew make will continue working until Homebrew 0.7"
|
|
|
|
exec __FILE__, "create", *ARGV
|
|
|
|
|
|
|
|
when 'create'
|
2009-08-10 16:48:30 +01:00
|
|
|
if ARGV.include? '--macports'
|
|
|
|
exec "open", "http://www.macports.org/ports.php?by=name&substr=#{ARGV.next}"
|
2009-06-08 15:59:59 +01:00
|
|
|
else
|
2009-09-05 14:03:41 -04:00
|
|
|
exec_editor *ARGV.collect {|name| make name}
|
2009-06-08 15:59:59 +01:00
|
|
|
end
|
|
|
|
|
2009-08-22 15:54:26 +01:00
|
|
|
when 'diy', 'configure'
|
2009-08-12 13:43:51 +01:00
|
|
|
puts diy
|
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
when 'info', 'abv'
|
2009-08-11 00:27:18 +01:00
|
|
|
if ARGV.named_empty?
|
2009-08-10 16:48:30 +01:00
|
|
|
puts `ls #{HOMEBREW_CELLAR} | wc -l`.strip+" kegs, "+HOMEBREW_CELLAR.abv
|
2009-07-24 15:10:01 +01:00
|
|
|
elsif ARGV[0][0..6] == 'http://'
|
|
|
|
puts Pathname.new(ARGV.shift).version
|
2009-06-13 12:59:18 +01:00
|
|
|
else
|
2009-08-10 16:48:30 +01:00
|
|
|
ARGV.named.each {|name| info name}
|
2009-06-05 12:57:00 +01:00
|
|
|
end
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-09-24 19:19:57 +01:00
|
|
|
when 'log'
|
|
|
|
Dir.chdir HOMEBREW_PREFIX
|
|
|
|
exec "git", "log", ARGV.formulae.first.path, *ARGV.options
|
|
|
|
|
|
|
|
else
|
|
|
|
puts ARGV.usage
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
2009-05-23 16:37:24 +01:00
|
|
|
|
2009-08-11 00:27:18 +01:00
|
|
|
rescue UsageError
|
|
|
|
onoe "Invalid usage"
|
|
|
|
puts ARGV.usage
|
2009-09-23 09:32:04 +01:00
|
|
|
exit 1
|
2009-08-10 16:48:30 +01:00
|
|
|
rescue SystemExit
|
|
|
|
ohai "Kernel.exit" if ARGV.verbose?
|
2009-09-23 09:32:04 +01:00
|
|
|
exit 1
|
2009-08-10 16:48:30 +01:00
|
|
|
rescue Interrupt => e
|
2009-09-05 20:46:07 +01:00
|
|
|
# puts # seemingly a newline is typical
|
|
|
|
# Above is now commented out because the system() call forks and then forks
|
|
|
|
# again, so there are two of "us" so we get two exceptions raising and thus
|
|
|
|
# two newlines, which buggers up the shell. FIXME!
|
2009-08-10 16:48:30 +01:00
|
|
|
exit 130
|
|
|
|
rescue SystemCallError, RuntimeError => e
|
2009-08-11 18:17:11 +01:00
|
|
|
if ARGV.debug?
|
2009-08-10 16:48:30 +01:00
|
|
|
onoe e.inspect
|
|
|
|
puts e.backtrace
|
2009-05-21 00:04:43 +01:00
|
|
|
else
|
2009-08-10 16:48:30 +01:00
|
|
|
onoe e
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
2009-08-10 16:48:30 +01:00
|
|
|
exit 1
|
|
|
|
rescue Exception => e
|
|
|
|
onoe "Homebrew has failed you :("
|
|
|
|
puts "Please report this bug at: #{HOMEBREW_WWW}"
|
2009-09-08 16:37:25 +01:00
|
|
|
puts "Please include the following information:"
|
|
|
|
ohai "Environment"
|
|
|
|
puts "Mac OS X: "+`sw_vers -productVersion`
|
2009-08-10 16:48:30 +01:00
|
|
|
ohai e.inspect
|
|
|
|
puts e.backtrace
|
2009-09-23 09:32:04 +01:00
|
|
|
exit 1
|
2009-07-31 02:51:17 +01:00
|
|
|
end
|