diff options
| author | Max Howell | 2009-06-08 11:42:28 +0100 |
|---|---|---|
| committer | Max Howell | 2009-06-08 11:42:28 +0100 |
| commit | 03f225acef70152bdf2de7a5f1c1ea31eef15246 (patch) | |
| tree | 9540417716357cc6b9bbef2c5c437c40f3b63983 | |
| parent | 1ee9ac42ddb6d3551c24d7ffaacba71f531e3f88 (diff) | |
| download | homebrew-03f225acef70152bdf2de7a5f1c1ea31eef15246.tar.bz2 | |
Better version extraction and more flexible funcs
| -rw-r--r-- | Library/Homebrew/brewkit.rb | 69 | ||||
| -rwxr-xr-x | Library/Homebrew/unittest.rb | 2 | ||||
| -rwxr-xr-x | bin/brew | 21 |
3 files changed, 53 insertions, 39 deletions
diff --git a/Library/Homebrew/brewkit.rb b/Library/Homebrew/brewkit.rb index 619e97cec..a51c080f5 100644 --- a/Library/Homebrew/brewkit.rb +++ b/Library/Homebrew/brewkit.rb @@ -49,6 +49,29 @@ def appsupport return appsupport end +class BuildError <RuntimeError + def initialize cmd + super "Build failed during: #{cmd}" + end +end + +# pass in the basename of the filename _without_ any file extension +def extract_version basename + # eg. foobar4.5.1 + # eg. foobar-4.5.1 + # eg. foobar-4.5.1b + /^[^0-9]*((\d+\.)*(\d+-)?\d+[abc]?)$/.match basename + return $1 if $1 + + # eg. boost_1_39_0 + /^[^0-9]*((\d+_)*\d+)$/.match basename + return $1.gsub('_', '.') if $1 + + # eg. (erlang) otp_src_R13B + /^.*[-_.](.*)$/.match basename + return $1 if $1 +end + # make our code neater class Pathname @@ -62,6 +85,17 @@ class Pathname FileUtils.cp_r to_s, dst end end + + def extname + /\.(zip|tar\.(gz|bz2)|tgz)$/.match to_s + return ".#{$1}" if $1 + return File.extname(to_s) + end + + # for files we support, basename without extension + def stem + return File.basename(to_s, extname) + end end @@ -109,24 +143,6 @@ class AbstractFormula # end ruby is weird section end -protected - # pass in the basename of the filename _without_ any file extension - def extract_version basename - # eg. foobar4.5.1 - # eg. foobar-4.5.1 - # eg. foobar-4.5.1b - /^[^0-9]*((\d+\.)*(\d+-)?\d+[abc]?)$/.match basename - return @version=$1 if $1 - - # eg. boost_1_39_0 - /^[^0-9]*((\d+_)*\d+)$/.match basename - return @version=$1.gsub('_', '.') if $1 - - # eg. (erlang) otp_src_R13B - /^.*[-_.](.*)$/.match basename - return @version=$1 if $1 - end - private def maybe_mkpath path path.mkpath unless path.exist? @@ -265,12 +281,6 @@ class UnidentifiedFormula <AbstractFormula end private - def extname - /\.(zip|tar\.(gz|bz2)|tgz)$/.match @url - return ".#{$1}" if $1 - raise "Only tarballs and zips are supported by this class" - end - def uncompress(path) if path.extname == '.zip' `unzip -qq "#{path}"` @@ -297,7 +307,7 @@ end class Formula <UnidentifiedFormula def initialize name super name - extract_version File.basename(@url, extname) + @version=extract_version Pathname.new(File.basename(@url)).stem end end @@ -338,14 +348,17 @@ def system cmd IO.popen("#{cmd} 2>&1") do |f| until f.eof? s=f.gets - out+=s - puts s if ARGV.include? '--verbose' + if ARGV.include? '--verbose' + puts s + else + out+=s + end end end unless $? == 0 puts out unless ARGV.include? '--verbose' #already did that above - raise "Failure during: #{cmd}" + raise BuildError.new(cmd) end end diff --git a/Library/Homebrew/unittest.rb b/Library/Homebrew/unittest.rb index d619b9601..4ae7bc4f0 100755 --- a/Library/Homebrew/unittest.rb +++ b/Library/Homebrew/unittest.rb @@ -71,8 +71,6 @@ class BeerTasting <Test::Unit::TestCase TestFormula.new 'test-0.1.tgz' TestFormula.new 'test-0.1.zip' end - assert_raise(RuntimeError) {TestFormula.new 'test-0.1.7'} - assert_raise(RuntimeError) {TestFormula.new 'test-0.1.arse'} end def test_prefix @@ -235,19 +235,20 @@ begin shift_formulae_from_ARGV.each {|name| rm name} when 'mk' require 'brewkit' - class Template <Formula - @url=ARGV.shift - end + url=ARGV.shift + version=extract_version File.basename(url, Pathname.new(url).extname) + + /(.*?)[-_.]?#{version}/.match File.basename(url) + raise "Couldn't parse name from #{url}" if $1.nil? - t=Template.new - /(.*)[-_.]#{t.version}/.match File.basename(t.url) - t.name = $1 + path=$formula+($1+'.rb') + raise "#{path} already exists!" if File.exist? path - f=File.new $formula+(t.name+'.rb'), 'w' + f=File.new path, 'w' f.puts "require 'brewkit'" f.puts - f.puts "class #{__class t.name} <Formula" - f.puts " @url=#{t.url}" + f.puts "class #{__class $1} <Formula" + f.puts " @url='#{url}'" f.puts " @md5=''" f.puts " @homepage=''" f.puts @@ -257,6 +258,8 @@ begin f.puts " end" f.puts "end" f.close + + puts path when 'info' o=__obj shift_formulae_from_ARGV[0] puts "#{o.name} #{o.version}" |
