diff options
| author | Max Howell | 2009-06-08 11:42:28 +0100 |
|---|---|---|
| committer | Max Howell | 2009-06-08 11:42:28 +0100 |
| commit | cbbc7b0f0f00132c1c9a1beeadd230e4ad6e63e1 (patch) | |
| tree | 6af3d83eb3075859aaefe2b65f5b797577cebac6 /Library | |
| parent | b3b14a7e0aeab993413bba9601fa98da272ee8da (diff) | |
| download | brew-cbbc7b0f0f00132c1c9a1beeadd230e4ad6e63e1.tar.bz2 | |
Better version extraction and more flexible funcs
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/brewkit.rb | 69 | ||||
| -rwxr-xr-x | Library/Homebrew/unittest.rb | 2 |
2 files changed, 41 insertions, 30 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 |
