aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Howell2009-09-21 18:42:24 +0100
committerMax Howell2009-09-21 18:46:28 +0100
commite9701dbc81510640bdaff131501828b97066ba31 (patch)
tree2d4c487be0e271eeb1fa414f1b098713651e7a5d
parent3d421c864971bc86b1d7603e69d05f5fed79a60e (diff)
parent77dd27e8e6e9e2f31fc8ca90bb6d63399922d013 (diff)
downloadbrew-e9701dbc81510640bdaff131501828b97066ba31.tar.bz2
Merge branch 'deps'
Conflicts: Library/Formula/imagemagick.rb Library/Formula/taglib.rb Library/Homebrew/brew.h.rb Library/Homebrew/formula.rb bin/brew
-rw-r--r--Library/Homebrew/ARGV+yeast.rb3
-rw-r--r--Library/Homebrew/brew.h.rb9
-rw-r--r--Library/Homebrew/formula.rb37
-rwxr-xr-xLibrary/Homebrew/unittest.rb23
-rwxr-xr-xbin/brew46
5 files changed, 92 insertions, 26 deletions
diff --git a/Library/Homebrew/ARGV+yeast.rb b/Library/Homebrew/ARGV+yeast.rb
index f9f50c01a..8825718d4 100644
--- a/Library/Homebrew/ARGV+yeast.rb
+++ b/Library/Homebrew/ARGV+yeast.rb
@@ -66,6 +66,9 @@ module HomebrewArgvExtension
def quieter?
flag? '--quieter'
end
+ def interactive?
+ flag? '--interactive'
+ end
def flag? flag
options.each do |arg|
diff --git a/Library/Homebrew/brew.h.rb b/Library/Homebrew/brew.h.rb
index f482559f6..d02d44dc1 100644
--- a/Library/Homebrew/brew.h.rb
+++ b/Library/Homebrew/brew.h.rb
@@ -144,6 +144,15 @@ def clean f
end
+def expand_deps ff
+ deps = []
+ ff.deps.collect do |f|
+ deps += expand_deps(Formula.factory(f))
+ end
+ deps << ff
+end
+
+
def prune
$n=0
$d=0
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index ee9bd36f6..ffb71bb44 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -116,9 +116,7 @@ class Formula
# }
# The final option is to return DATA, then put a diff after __END__. You
# can still return a Hash with DATA as the value for a patch level key.
- def patches; end
- # reimplement and specify dependencies
- def deps; end
+ def patches; [] end
# sometimes the clean process breaks things, return true to skip anything
def skip_clean? path; false end
# rarely, you don't want your library symlinked into the main prefix
@@ -129,7 +127,7 @@ class Formula
def brew
validate_variable :name
validate_variable :version
-
+
stage do
begin
patch
@@ -165,6 +163,7 @@ class Formula
end
def self.factory name
+ return name if name.kind_of? Formula
path = Pathname.new(name)
if path.absolute?
require name
@@ -181,6 +180,10 @@ class Formula
HOMEBREW_PREFIX+'Library'+'Formula'+"#{name.downcase}.rb"
end
+ def deps
+ self.class.deps or []
+ end
+
protected
# Pretty titles the command and buffers stdout/stderr
# Throws if there's an error
@@ -327,9 +330,31 @@ private
end
class <<self
- attr_reader :url, :version, :homepage, :head
+ attr_reader :url, :version, :homepage, :head, :deps
attr_reader *CHECKSUM_TYPES
- end
+
+ def depends_on name, *args
+ @deps ||= []
+
+ case name
+ when String
+ # noop
+ when Hash
+ name = name.keys.first # indeed, we only support one mapping
+ when Symbol
+ name = name.to_s
+ when Formula
+ @deps << name
+ return # we trust formula dev to not dupe their own instantiations
+ else
+ raise "Unsupported type #{name.class}"
+ end
+
+ # we get duplicates because every new fork of this process repeats this
+ # step for some reason I am not sure about
+ @deps << name unless @deps.include? name
+ end
+ end
end
# see ack.rb for an example usage
diff --git a/Library/Homebrew/unittest.rb b/Library/Homebrew/unittest.rb
index 0b2d7df7f..15336ebde 100755
--- a/Library/Homebrew/unittest.rb
+++ b/Library/Homebrew/unittest.rb
@@ -42,7 +42,8 @@ class MostlyAbstractFormula <Formula
end
class TestBall <Formula
- def initialize
+ # name parameter required for some Formula::factory
+ def initialize name=nil
@url="file:///#{Pathname.new(ABS__FILE__).parent.realpath}/testball-0.1.tbz"
super "testball"
end
@@ -123,9 +124,13 @@ def nostdout
end
module ExtendArgvPlusYeast
- def stick_an_arg_in_thar
+ def reset
@named=nil
- unshift 'foo'
+ @formulae=nil
+ @kegs=nil
+ while ARGV.count > 0
+ ARGV.shift
+ end
end
end
ARGV.extend ExtendArgvPlusYeast
@@ -372,8 +377,9 @@ class BeerTasting <Test::Unit::TestCase
end
def test_no_ARGV_dupes
- ARGV.unshift'foo'
- ARGV.unshift'foo'
+ ARGV.reset
+ ARGV.unshift 'foo'
+ ARGV.unshift 'foo'
n=0
ARGV.named.each{|arg| n+=1 if arg == 'foo'}
assert_equal 1, n
@@ -385,9 +391,10 @@ class BeerTasting <Test::Unit::TestCase
assert_raises(UsageError) { ARGV.kegs }
assert ARGV.named_empty?
- (HOMEBREW_CELLAR+'foo'+'0.1').mkpath
+ (HOMEBREW_CELLAR+'mxcl'+'10.0').mkpath
- ARGV.stick_an_arg_in_thar
+ ARGV.reset
+ ARGV.unshift 'mxcl'
assert_equal 1, ARGV.named.length
assert_equal 1, ARGV.kegs.length
assert_raises(FormulaUnavailableError) { ARGV.formulae }
@@ -425,7 +432,7 @@ class BeerTasting <Test::Unit::TestCase
nostdout do
assert_nothing_raised do
f=TestBall.new
- make 'http://example.com/testball-0.1.tbz'
+ make f.url
info f.name
clean f
prune
diff --git a/bin/brew b/bin/brew
index 556797374..eae57d15f 100755
--- a/bin/brew
+++ b/bin/brew
@@ -22,6 +22,7 @@ unless system "which -s gcc-4.2" and $?.success?
abort "Sorry, Homebrew requires gcc 4.2, which is provided by Xcode 3.1"
end
+
begin
case ARGV.shift
when '--prefix' then puts HOMEBREW_PREFIX
@@ -76,24 +77,48 @@ begin
puts "#{f}: #{ENV[f]}" unless ENV[f].to_s.empty?
end
end
-
- unless system "which #{ENV['CC'] or 'cc'} &> /dev/null" and $?.success?
- raise "We cannot find a c compiler, have you installed the latest Xcode?"
+
+ if ARGV.interactive? and ARGV.formulae.count > 1
+ # 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"
end
- require 'beer_events'
-
- watch_out_for_spill do
- ARGV.formulae.each do |f|
- if f.installed? and not ARGV.force?
+ unless ARGV.force?
+ unless system "which #{ENV['CC'] or 'cc'} &> /dev/null" and $?.success?
+ raise "We cannot find a c compiler, have you installed the latest Xcode?"
+ end
+ formulae = ARGV.formulae.reject do |f|
+ if f.installed?
message = "Formula already installed: #{f.prefix}"
if ARGV.formulae.count > 1
opoo message
else
puts message # if only one is being installed a warning looks severe
end
- next
+ true
end
+ end
+ exit 0 if formulae.empty?
+ else
+ formulae = ARGV.formulae
+ end
+
+ deps = []
+ formulae.each { |f| deps += expand_deps f }
+ formulae = deps.reject { |f| f.installed? }
+
+ require 'set'
+ done = Set.new
+
+ require 'beer_events'
+ watch_out_for_spill do
+ formulae.each do |f|
+ next if done.include? f.class
+ done << f.class
# 1. formulae can modify ENV, so we must ensure that each
# installation has a pristine ENV when it starts, forking now is
@@ -133,9 +158,6 @@ begin
when 'unlink'
ARGV.kegs.each {|keg| puts "#{keg.unlink} links removed for #{keg}"}
- when 'unlink'
- ARGV.kegs.each {|keg| puts "#{keg.unlink} links removed for #{keg}"}
-
when 'rm', 'uninstall', 'remove'
ARGV.kegs.each do |keg|
puts "Uninstalling #{keg}..."