brew/bin/brew

263 lines
7.8 KiB
Plaintext
Raw Normal View History

2009-05-21 00:04:43 +01:00
#!/usr/bin/ruby
2009-09-03 17:10:35 +02:00
# -*- coding: utf-8 -*-
# Many Pathname operations use getwd when they shouldn't, and then throw
# odd exceptions. Reduce our support burden by showing a user-friendly error.
Dir.getwd rescue abort "The current working directory doesn't exist, cannot proceed."
HOMEBREW_BREW_FILE = ENV['HOMEBREW_BREW_FILE'] = File.expand_path(__FILE__)
require 'pathname'
$:.unshift((Pathname.new(__FILE__).realpath.dirname.parent+"Library"+"Homebrew").to_s)
require 'global'
case ARGV.first
when '--cache'
puts HOMEBREW_CACHE
exit 0
2009-10-26 18:22:22 +00:00
when '-h', '--help', '--usage', '-?', nil
puts ARGV.usage
exit 0
when '--version'
puts HOMEBREW_VERSION
exit 0
when '-v'
if ARGV.length > 1
puts "Homebrew #{HOMEBREW_VERSION}"
# continue in verbose mode
ARGV << ARGV.shift
else
puts HOMEBREW_VERSION
exit 0
end
end
case HOMEBREW_PREFIX.to_s when '/', '/usr'
# it may work, but I only see pain this route and don't want to support it
abort "Cowardly refusing to continue at this prefix: #{HOMEBREW_PREFIX}"
end
2009-09-25 18:12:19 +01:00
if MACOS_VERSION < 10.5
abort "Homebrew requires Leopard or higher, but you could fork it and fix that..."
2009-08-12 01:56:40 +01:00
end
def dump_config
require 'hardware'
bits = Hardware.is_64_bit? ? 64 : 32
2009-11-09 18:48:05 +00:00
cores = case Hardware.processor_count
when 1 then 'single'
when 2 then 'dual'
when 4 then 'quad'
else
Hardware.processor_count
end
llvm = llvm_build
2009-11-11 18:37:13 +00:00
sha = `git rev-parse --verify HEAD`.chomp
puts <<-EOS
HOMEBREW_VERSION: #{HOMEBREW_VERSION}
2009-11-11 18:37:13 +00:00
HEAD: #{sha}
2009-11-09 18:48:05 +00:00
HOMEBREW_PREFIX: #{HOMEBREW_PREFIX}
HOMEBREW_CELLAR: #{HOMEBREW_CELLAR}
HOMEBREW_CACHE: #{HOMEBREW_CACHE}
HOMEBREW_REPOSITORY: #{HOMEBREW_REPOSITORY}
Library path: #{$:.first}
2009-11-09 18:48:05 +00:00
Hardware: #{cores}-core #{bits}-bit #{Hardware.intel_family}
OS X: #{MACOS_FULL_VERSION}
Ruby: #{RUBY_VERSION}-#{RUBY_PATCHLEVEL}
GCC: 4.2 build #{gcc_build}
2009-11-09 18:48:05 +00:00
LLVM: #{llvm ? "build #{llvm}" : "N/A" }
MacPorts or Fink? #{macports_or_fink_installed?}
EOS
end
begin
require 'brew.h'
case arg = ARGV.shift
when '--prefix'
puts HOMEBREW_PREFIX
when '--config'
dump_config
when 'home', 'homepage'
if ARGV.named.empty?
exec "open", HOMEBREW_WWW
else
exec "open", *ARGV.formulae.collect {|f| f.homepage}
end
when 'ls', 'list'
if ARGV.flag? '--unbrewed'
dirs = HOMEBREW_PREFIX.children.select { |pn| pn.directory? }.collect { |pn| pn.basename.to_s }
dirs -= ['Library', 'Cellar', '.git']
Dir.chdir HOMEBREW_PREFIX
exec 'find', *dirs + %w[-type f ( ! -iname .ds_store ! -iname brew )]
elsif ARGV.named.empty?
ENV['CLICOLOR']=nil
exec 'ls', *ARGV.options<<HOMEBREW_CELLAR if HOMEBREW_CELLAR.exist?
elsif ARGV.verbose? or not $stdout.tty?
exec "find", *ARGV.kegs+%w[-not -type d -print]
else
ARGV.kegs.each { |keg| PrettyListing.new keg }
end
when 'search', '-S'
formulae = (HOMEBREW_REPOSITORY+'Library/Formula').children.sort.map{|f| f.basename('.rb') }
if ARGV.first =~ /^\/(.*)\/$/
puts_columns formulae.grep(Regexp.new($1))
else
puts_columns formulae.grep(/.*#{ARGV.first}.*/)
end
2009-06-26 13:03:49 +01:00
when 'edit'
if ARGV.named.empty?
# 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_REPOSITORY}/Library/*"]<<
"#{HOMEBREW_REPOSITORY}/bin/brew"<<
"#{HOMEBREW_REPOSITORY}/README.md"
else
# we don't use ARGV.formulae as that will throw if the file doesn't parse
paths = ARGV.named.collect do |name|
unless File.exist? path = "#{HOMEBREW_REPOSITORY}/Library/Formula/#{name}.rb"
require 'formula'
raise FormulaUnavailableError, name
else
path
end
2009-06-26 13:03:49 +01:00
end
exec_editor *paths
end
2009-06-26 13:03:49 +01:00
when 'up', 'update'
require 'update'
updater = RefreshBrew.new
old_revision = updater.current_revision
unless updater.update_from_masterbrew!
puts "Already up-to-date."
else
puts "Updated Homebrew from #{old_revision[0,8]} to #{updater.current_revision[0,8]}."
if updater.pending_formulae_changes?
ohai "The following formulae were updated:"
puts_columns updater.updated_formulae
else
puts "No formulae were updated." unless updater.pending_formulae_changes?
end
end
when 'ln', 'link'
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
when 'rm', 'uninstall', 'remove'
ARGV.kegs.each do |keg|
puts "Uninstalling #{keg}..."
keg.uninstall
keg.unlink
end
when 'prune'
prune
# 'make' supported until 0.7 for historic reasons
when 'mk', 'make'
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'
if ARGV.include? '--macports'
exec "open", "http://www.macports.org/ports.php?by=name&substr=#{ARGV.next}"
elsif ARGV.named.empty?
raise UsageError
else
2009-10-15 16:33:12 +01:00
exec_editor *ARGV.named.collect {|name| make name}
end
2009-08-22 15:54:26 +01:00
when 'diy', 'configure'
puts diy
when 'info', 'abv'
if ARGV.named.empty?
puts `ls #{HOMEBREW_CELLAR} | wc -l`.strip+" kegs, "+HOMEBREW_CELLAR.abv
elsif ARGV[0][0..6] == 'http://'
puts Pathname.new(ARGV.shift).version
2009-06-13 12:59:18 +01:00
else
ARGV.named.each {|name| info name}
2009-06-05 12:57:00 +01:00
end
when 'install'
require 'formula_installer'
2009-11-03 19:03:56 +00:00
require 'hardware'
############################################################ sanity checks
case Hardware.cpu_type when :ppc, :dunno
abort "Sorry, Homebrew does not support your computer's CPU architecture."
end
raise "Cannot write to #{HOMEBREW_CELLAR}" if HOMEBREW_CELLAR.exist? and not HOMEBREW_CELLAR.writable?
raise "Cannot write to #{HOMEBREW_PREFIX}" unless HOMEBREW_PREFIX.writable?
################################################################# warnings
if MACOS_VERSION >= 10.6
2009-11-09 18:47:26 +00:00
opoo "You should upgrade to Xcode 3.2.1" if llvm_build < 2206
else
2009-11-09 12:07:47 -08:00
opoo "You should upgrade to Xcode 3.1.4" if gcc_build < 5577
end
if macports_or_fink_installed?
opoo "It appears you have Macports or Fink installed"
puts "Although, unlikely, this can break builds or cause obscure runtime issues."
puts "If you experience problems try uninstalling these tools."
end
################################################################# install!
installer = FormulaInstaller.new
installer.install_deps = !ARGV.include?('--ignore-dependencies')
ARGV.formulae.each do |f|
if not f.installed? or ARGV.force?
installer.install f
else
puts "Formula already installed: #{f.prefix}"
end
end
when 'log'
2009-10-26 18:21:30 +00:00
Dir.chdir HOMEBREW_REPOSITORY
exec "git", "log", ARGV.formulae.first.path, *ARGV.options
else
2009-10-26 18:22:22 +00:00
onoe "Unknown command: #{arg}"
end
2009-05-23 16:37:24 +01:00
rescue FormulaUnspecifiedError
abort "This command requires a formula argument"
rescue KegUnspecifiedError
abort "This command requires a keg argument"
rescue UsageError
onoe "Invalid usage"
abort ARGV.usage
rescue SystemExit
puts "Kernel.exit" if ARGV.verbose?
rescue Interrupt => e
puts # seemingly a newline is typical
exit 130
rescue Exception => e
fatal = !(RuntimeError === e or SystemCallError === e)
onoe e
if BuildError === e or fatal
puts "#{Tty.white}Please report this bug to #{Tty.em}#{HOMEBREW_WWW}#{Tty.reset}"
dump_config
puts "Exit status: #{e.status}" if BuildError === e
end
puts e.backtrace if fatal or ARGV.debug?
exit 1
end