2009-05-21 00:04:43 +01:00
|
|
|
#!/usr/bin/ruby
|
2009-07-31 02:51:17 +01:00
|
|
|
$:.unshift __FILE__+'/../../Library/Homebrew'
|
2009-06-04 19:21:19 +01:00
|
|
|
require 'env'
|
2009-07-31 02:51:17 +01:00
|
|
|
require 'find'
|
2009-05-21 00:04:43 +01:00
|
|
|
|
2009-08-02 00:04:15 +01:00
|
|
|
PRISTINE_ARGV=ARGV.dup
|
|
|
|
|
2009-06-26 13:01:23 +01:00
|
|
|
# often causes Ruby to throw exception ffs
|
2009-07-10 00:57:27 +01:00
|
|
|
Dir.chdir '/' unless File.directory? ENV['PWD']
|
2009-06-26 13:01:23 +01:00
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
######################################################################## funcs
|
2009-08-02 00:04:15 +01:00
|
|
|
# remove symlinks that no longer point to files
|
2009-05-22 00:09:08 +01:00
|
|
|
def prune
|
2009-05-22 16:20:27 +01:00
|
|
|
n=0
|
|
|
|
dirs=Array.new
|
2009-07-31 02:51:17 +01:00
|
|
|
HOMEBREW_PREFIX.find do |path|
|
2009-05-22 00:09:08 +01:00
|
|
|
if path.directory?
|
2009-07-31 02:51:17 +01:00
|
|
|
name=path.relative_path_from(HOMEBREW_PREFIX).to_s
|
2009-07-28 00:33:08 +01:00
|
|
|
if name == '.git' or name == 'Cellar' or name == 'Library'
|
2009-05-22 16:20:27 +01:00
|
|
|
Find.prune
|
|
|
|
else
|
|
|
|
dirs<<path
|
|
|
|
end
|
2009-05-22 00:09:08 +01:00
|
|
|
elsif path.symlink?
|
2009-05-22 16:20:27 +01:00
|
|
|
resolved_path=path.dirname+path.readlink
|
|
|
|
unless resolved_path.exist?
|
|
|
|
path.unlink
|
|
|
|
n+=1
|
|
|
|
end
|
2009-05-22 00:09:08 +01:00
|
|
|
end
|
|
|
|
end
|
2009-06-02 13:39:39 +01:00
|
|
|
dirs.sort.reverse_each do |d|
|
|
|
|
if d.children.length == 0
|
|
|
|
d.rmdir
|
|
|
|
n+=1
|
|
|
|
end
|
|
|
|
end
|
2009-05-22 16:20:27 +01:00
|
|
|
return n
|
2009-05-22 00:09:08 +01:00
|
|
|
end
|
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
# we actually remove formulae from ARGV so that any other analysis of ARGV
|
|
|
|
# only includes relevent arguments
|
|
|
|
# TODO require will throw if no formula, so we should catch no?
|
|
|
|
def extract_named_args
|
|
|
|
args=Array.new
|
|
|
|
ARGV.delete_if do |arg|
|
|
|
|
if arg[0,1] == '-'
|
|
|
|
false
|
2009-06-05 12:57:00 +01:00
|
|
|
else
|
2009-07-24 15:10:01 +01:00
|
|
|
args<<arg
|
|
|
|
true
|
2009-06-05 12:57:00 +01:00
|
|
|
end
|
2009-06-05 07:51:05 +01:00
|
|
|
end
|
2009-08-02 01:21:01 +01:00
|
|
|
raise "Expecting the name of a keg or formula, eg:\n==> brew #{PRISTINE_ARGV.join ' '} wget" if args.empty?
|
2009-07-24 15:10:01 +01:00
|
|
|
return args
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
def extract_kegs
|
|
|
|
require 'keg'
|
|
|
|
kegs=extract_named_args.collect {|name| Keg.new name}
|
|
|
|
return kegs
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
def abv keg=nil
|
2009-07-31 02:51:17 +01:00
|
|
|
path=keg ? keg.path : HOMEBREW_CELLAR
|
2009-07-24 15:10:01 +01:00
|
|
|
if path.directory?
|
|
|
|
`find #{path} -type f | wc -l`.strip+' files, '+`du -hd0 #{path} | cut -d"\t" -f1`.strip
|
|
|
|
else
|
2009-07-31 01:15:58 +01:00
|
|
|
''
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
def install formula
|
|
|
|
require 'keg'
|
|
|
|
|
|
|
|
beginning = Time.now
|
|
|
|
|
|
|
|
formula.brew do
|
|
|
|
if ARGV.include? '--interactive'
|
|
|
|
ohai "Entering interactive mode"
|
|
|
|
puts "Type `exit' to return and finalize the installation"
|
|
|
|
puts "Install to this prefix: #{formula.prefix}"
|
|
|
|
pid=fork
|
|
|
|
if pid.nil?
|
|
|
|
exec 'bash'
|
|
|
|
else
|
|
|
|
Process.wait pid
|
|
|
|
end
|
|
|
|
elsif ARGV.include? '--help'
|
|
|
|
ohai './configure --help'
|
|
|
|
puts `./configure --help`
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
formula.prefix.mkpath
|
|
|
|
formula.install
|
2009-07-31 00:14:08 +01:00
|
|
|
%w[README ChangeLog COPYING LICENSE COPYRIGHT AUTHORS].each do |file|
|
2009-07-24 15:10:01 +01:00
|
|
|
formula.prefix.install file if File.file? file
|
|
|
|
end
|
|
|
|
end
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
2009-07-31 00:55:00 +01:00
|
|
|
|
2009-08-01 17:43:54 +01:00
|
|
|
raise "Nothing was installed to #{formula.prefix}" unless formula.installed?
|
2009-07-31 00:55:00 +01:00
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
ohai 'Finishing up'
|
|
|
|
keg=Keg.new formula
|
|
|
|
keg.clean
|
|
|
|
keg.ln
|
|
|
|
if formula.caveats
|
|
|
|
ohai "Caveats"
|
|
|
|
puts formula.caveats
|
|
|
|
ohai "Summary"
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
2009-07-24 15:10:01 +01:00
|
|
|
puts "#{keg.path}: "+abv(keg)+", built in #{pretty_duration Time.now-beginning}"
|
|
|
|
rescue Exception
|
2009-07-31 00:55:00 +01:00
|
|
|
formula.prefix.rmtree if formula.prefix.directory?
|
2009-07-24 15:10:01 +01:00
|
|
|
raise
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
|
|
|
|
2009-07-28 11:02:35 +08:00
|
|
|
def mk url, mode='make'
|
2009-07-24 15:10:01 +01:00
|
|
|
require 'formula'
|
|
|
|
path=Pathname.new(url)
|
|
|
|
|
|
|
|
/(.*?)[-_.]?#{path.version}/.match path.basename
|
|
|
|
raise "Couldn't parse name from #{url}" if $1.nil? or $1.empty?
|
|
|
|
|
|
|
|
path=Formula.path $1
|
|
|
|
raise "#{path} already exists!" if File.exist? path
|
|
|
|
|
|
|
|
f=File.new path, 'w'
|
|
|
|
f.puts "require 'brewkit'"
|
|
|
|
f.puts
|
|
|
|
f.puts "class #{Formula.class $1} <Formula"
|
|
|
|
f.puts " @url='#{url}'"
|
|
|
|
f.puts " @homepage=''" # second because you fill in these two first
|
|
|
|
f.puts " @md5=''"
|
|
|
|
f.puts
|
2009-07-28 11:02:35 +08:00
|
|
|
|
|
|
|
if mode == "cmake"
|
|
|
|
f.puts " def deps"
|
|
|
|
f.puts " BinaryDep.new 'cmake'"
|
|
|
|
f.puts " end"
|
|
|
|
f.puts
|
|
|
|
end
|
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
f.puts " def install"
|
2009-07-28 11:02:35 +08:00
|
|
|
|
|
|
|
if mode == "make"
|
|
|
|
f.puts " system \"./configure --disable-debug --prefix='\#{prefix}'\""
|
|
|
|
f.puts " system \"make install\""
|
|
|
|
elsif mode == "cmake"
|
|
|
|
f.puts " system \"cmake -G 'Unix Makefiles' -DCMAKE_INSTALL_PREFIX=\#{prefix}\""
|
|
|
|
f.puts " system \"make\""
|
|
|
|
f.puts " system \"make install\""
|
|
|
|
end
|
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
f.puts " end"
|
|
|
|
f.print "end"
|
|
|
|
f.close
|
|
|
|
|
|
|
|
return path
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
def prefix
|
|
|
|
Pathname.new(__FILE__).dirname.parent.expand_path
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def usage
|
|
|
|
name=File.basename $0
|
|
|
|
<<-EOS
|
2009-06-05 07:51:23 +01:00
|
|
|
Usage: #{name} command [formula] ...
|
|
|
|
Usage: #{name} [--prefix] [--cache] [--version]
|
2009-06-18 10:32:53 +01:00
|
|
|
Usage: #{name} [--verbose]
|
2009-06-05 07:51:23 +01:00
|
|
|
|
|
|
|
Commands:
|
2009-06-18 10:32:53 +01:00
|
|
|
install formula ... [--debug] [--interactive]
|
2009-06-05 08:09:34 +01:00
|
|
|
rm formula ...
|
|
|
|
list formula ...
|
|
|
|
ln formula ...
|
2009-06-13 12:59:18 +01:00
|
|
|
info [formula]
|
2009-06-05 23:38:58 +01:00
|
|
|
mk url
|
2009-06-05 07:51:23 +01:00
|
|
|
prune
|
|
|
|
EOS
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
2009-05-23 16:37:24 +01:00
|
|
|
|
2009-06-05 08:09:34 +01:00
|
|
|
|
2009-06-15 01:41:53 +01:00
|
|
|
######################################################################## utils
|
|
|
|
def pretty_duration s
|
|
|
|
return "#{(s*1000).to_i} milliseconds" if s < 3
|
|
|
|
return "#{s.to_i} seconds" if s < 10*60
|
|
|
|
return "#{(s/60).to_i} minutes"
|
|
|
|
end
|
|
|
|
|
2009-06-02 13:39:39 +01:00
|
|
|
######################################################################### impl
|
|
|
|
begin
|
|
|
|
case ARGV.shift
|
2009-07-24 15:10:01 +01:00
|
|
|
when '--prefix' then puts prefix
|
|
|
|
when '--cache' then puts Homebrew::cache
|
|
|
|
when '-h', '--help', '--usage', '-?' then puts usage
|
|
|
|
when '-v', '--version' then puts HOMEBREW_VERSION
|
|
|
|
when 'macports' then exec "open 'http://www.macports.org/ports.php?by=name&substr=#{ARGV.shift}'"
|
|
|
|
|
2009-07-31 22:10:50 -07:00
|
|
|
when 'home', 'homepage'
|
|
|
|
homepages=extract_names.collect {|keg| Formula.create(name).homepage}
|
|
|
|
exec "open #{homepages.join' '}"
|
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
when 'ls', 'list'
|
|
|
|
dirs=extract_kegs.collect {|keg| keg.path}
|
|
|
|
exec "find #{dirs.join' '} -not -type d -print"
|
|
|
|
|
2009-06-26 13:03:49 +01:00
|
|
|
when 'edit'
|
|
|
|
if ARGV.empty?
|
2009-07-31 02:51:17 +01:00
|
|
|
r=HOMEBREW_PREFIX
|
|
|
|
exec "mate #{r}/Library/Formula #{r}/Library/Homebrew #{r}/bin/brew #{r}/README"
|
2009-06-26 13:03:49 +01:00
|
|
|
else
|
2009-07-31 01:15:58 +01:00
|
|
|
require 'formula'
|
|
|
|
paths=extract_named_args.collect {|name| Formula.path(name).to_s.gsub ' ', '\\ '}
|
2009-07-24 15:10:01 +01:00
|
|
|
exec "mate #{paths.join ' '}"
|
2009-06-26 13:03:49 +01:00
|
|
|
end
|
|
|
|
|
2009-06-02 13:39:39 +01:00
|
|
|
when 'install'
|
2009-07-24 15:10:01 +01:00
|
|
|
require 'formula'
|
|
|
|
extract_named_args.each do |name|
|
2009-07-31 00:55:00 +01:00
|
|
|
f=Formula.create(name)
|
2009-08-01 17:43:54 +01:00
|
|
|
raise "#{f.name} already installed!\n==> #{f.prefix}" if f.installed? unless ARGV.include? '--force'
|
2009-07-31 00:55:00 +01:00
|
|
|
install f
|
2009-06-05 08:09:34 +01:00
|
|
|
end
|
2009-07-22 20:27:58 +01:00
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
when 'ln', 'link'
|
2009-06-05 07:51:05 +01:00
|
|
|
n=0
|
2009-07-24 15:10:01 +01:00
|
|
|
(kegs=extract_kegs).each do |keg|
|
|
|
|
n+=nn=keg.ln
|
|
|
|
puts "Created #{nn} links for #{keg.name}" if kegs.length > 1
|
|
|
|
end
|
2009-06-05 07:51:05 +01:00
|
|
|
puts "Created #{n} links"
|
2009-07-22 20:27:58 +01:00
|
|
|
|
2009-06-18 09:50:01 +01:00
|
|
|
when 'rm', 'uninstall'
|
2009-07-24 15:10:01 +01:00
|
|
|
extract_kegs.each do |keg|
|
|
|
|
puts "Removing #{keg.name}..."
|
|
|
|
keg.rm
|
|
|
|
end
|
|
|
|
print "Pruning #{prefix}/..."
|
|
|
|
puts " #{prune} symbolic links pruned"
|
2009-06-08 11:42:28 +01:00
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
when 'prune'
|
|
|
|
puts "Pruned #{prune} symbolic links"
|
|
|
|
|
|
|
|
when 'mk', 'make'
|
2009-07-28 11:02:35 +08:00
|
|
|
mode = "make"
|
|
|
|
if ARGV.length > 0
|
|
|
|
if ARGV[0] == '--cmake'
|
|
|
|
ARGV.shift
|
|
|
|
mode = "cmake"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
paths=ARGV.collect {|arg| mk arg, mode}
|
2009-07-24 15:10:01 +01:00
|
|
|
if paths.empty?
|
|
|
|
raise "Invalid URL"
|
|
|
|
elsif Kernel.system "which mate > /dev/null" and $? == 0
|
|
|
|
paths=paths.collect {|path| path.to_s.gsub " ", "\\ "}
|
|
|
|
exec "mate #{paths.join ' '}"
|
2009-06-08 15:59:59 +01:00
|
|
|
else
|
2009-07-24 15:10:01 +01:00
|
|
|
puts paths.join("\n")
|
2009-06-08 15:59:59 +01:00
|
|
|
end
|
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
when 'info', 'abv'
|
2009-06-13 12:59:18 +01:00
|
|
|
if ARGV.empty?
|
2009-07-31 02:51:17 +01:00
|
|
|
puts `ls #{HOMEBREW_CELLAR} | wc -l`.strip+" kegs, "+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-01 17:43:54 +01:00
|
|
|
require 'formula'
|
2009-07-24 15:10:01 +01:00
|
|
|
#TODO show outdated status and that
|
2009-08-01 17:43:54 +01:00
|
|
|
frm=Formula.create(extract_named_args[0])
|
|
|
|
puts "#{frm.name} #{frm.version}"
|
2009-07-24 15:10:01 +01:00
|
|
|
puts frm.homepage
|
2009-07-29 00:55:36 +01:00
|
|
|
if frm.installed?
|
2009-08-01 17:43:54 +01:00
|
|
|
keg=Keg.new frm
|
2009-07-24 15:10:01 +01:00
|
|
|
puts "#{abv keg} (installed to #{keg.path})"
|
|
|
|
end
|
|
|
|
if frm.caveats
|
|
|
|
ohai 'Caveats'
|
|
|
|
puts frm.caveats
|
2009-06-13 12:59:18 +01:00
|
|
|
end
|
2009-06-05 12:57:00 +01:00
|
|
|
end
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-06-18 09:51:45 +01:00
|
|
|
else
|
|
|
|
puts usage
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
2009-05-23 16:37:24 +01:00
|
|
|
|
2009-06-02 13:39:39 +01:00
|
|
|
rescue StandardError, Interrupt => e
|
|
|
|
if ARGV.include? '--verbose' or ENV['HOMEBREW_DEBUG']
|
|
|
|
raise
|
|
|
|
elsif e.kind_of? Interrupt
|
|
|
|
puts # seeimgly a newline is typical
|
|
|
|
exit 130
|
|
|
|
elsif e.kind_of? StandardError and not e.kind_of? NameError
|
|
|
|
puts "\033[1;31mError\033[0;0m: #{e}"
|
|
|
|
exit 1
|
2009-05-21 00:04:43 +01:00
|
|
|
else
|
2009-06-02 13:39:39 +01:00
|
|
|
raise
|
|
|
|
end
|
2009-07-31 02:51:17 +01:00
|
|
|
end
|