aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/formula.rb
diff options
context:
space:
mode:
authorMax Howell2009-09-04 15:28:18 +0100
committerMax Howell2009-09-16 14:49:06 +0100
commitc28bd7b57193c808f896c0f2a0eac20e8fd075bb (patch)
treec8958503c4ae1017b3404ad013877e38c360d882 /Library/Homebrew/formula.rb
parentfd5ed391be80b4170efa9d34ab47b011c94f9e54 (diff)
downloadbrew-c28bd7b57193c808f896c0f2a0eac20e8fd075bb.tar.bz2
Allow formulae to use __END__
For this to work the "running script" must be the formulae file. Making this so wasn't so hard, there is now an install.rb script which is included with the -r flag to the ruby executable. An at_exit handler calls the install function. Having the install logic in its own file made it feel like there was so much space that I added extra error handling. So there is something to be said for separating functionality out into its own files. Still the error handling sucks, we'll need to marshall the exception back to the bin/brew command. Which is another PITA. Still overall I think this will prove worthwhile. But if it doesn't we'll revert. As a first usage, you can put a diff after __END__ and return DATA from Formula::patches to make Homebrew aware of it.
Diffstat (limited to 'Library/Homebrew/formula.rb')
-rw-r--r--Library/Homebrew/formula.rb29
1 files changed, 22 insertions, 7 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index a5a69b496..bf7e55865 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -114,6 +114,8 @@ class Formula
# :p1 => 'http://bar.com/patch2',
# :p2 => ['http://moo.com/patch5', 'http://moo.com/patch6']
# }
+ # The final option is to return DATA, then put a diff after __END__ and 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
@@ -128,6 +130,8 @@ class Formula
stage do
begin
patch
+ # we allow formulas to do anything they want to the Ruby process
+ # so load any deps before this point! And exit asap afterwards
yield self
rescue Interrupt, RuntimeError, SystemCallError => e
raise unless ARGV.debug?
@@ -158,7 +162,13 @@ class Formula
end
def self.factory name
- require self.path(name)
+ path = Pathname.new(name)
+ if path.absolute?
+ require name
+ name = path.stem
+ else
+ require self.path(name)
+ end
return eval(self.class_s(name)).new(name)
rescue LoadError
raise FormulaUnavailableError.new(name)
@@ -242,7 +252,7 @@ private
yield
end
end
-
+
def patch
return if patches.empty?
@@ -258,17 +268,20 @@ private
n=0
patch_defns.each do |arg, urls|
urls.each do |url|
- p = {:filename => '%03d-homebrew.patch' % n+=1, :compression => false}
+ p = {:filename => '%03d-homebrew.diff' % n+=1, :compression => false}
- if url =~ %r[^\w+\://]
+ if defined? DATA and url == DATA
+ pn=Pathname.new p[:filename]
+ pn.write DATA.read
+ elsif url =~ %r[^\w+\://]
out_fn = p[:filename]
case url
when /\.gz$/
p[:compression] = :gzip
- out_fn << '.gz'
+ out_fn += '.gz'
when /\.bz2$/
p[:compression] = :bzip2
- out_fn << '.bz2'
+ out_fn += '.bz2'
end
p[:curl_args] = [url, '-o', out_fn]
else
@@ -281,9 +294,11 @@ private
patch_list << p
end
end
+
+ return if patch_list.empty?
# downloading all at once is much more efficient, espeically for FTP
- curl *(patch_list.collect { |p| p[:curl_args] }).flatten
+ curl *(patch_list.collect{|p| p[:curl_args]}.select{|p| p}.flatten)
patch_list.each do |p|
case p[:compression]