mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Better version extraction and more flexible funcs
This commit is contained in:
parent
b3b14a7e0a
commit
cbbc7b0f0f
@ -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
|
||||
if ARGV.include? '--verbose'
|
||||
puts s
|
||||
else
|
||||
out+=s
|
||||
puts s if ARGV.include? '--verbose'
|
||||
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
|
||||
|
||||
|
@ -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
|
||||
|
21
bin/brew
21
bin/brew
@ -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)
|
||||
|
||||
t=Template.new
|
||||
/(.*)[-_.]#{t.version}/.match File.basename(t.url)
|
||||
t.name = $1
|
||||
/(.*?)[-_.]?#{version}/.match File.basename(url)
|
||||
raise "Couldn't parse name from #{url}" if $1.nil?
|
||||
|
||||
f=File.new $formula+(t.name+'.rb'), 'w'
|
||||
path=$formula+($1+'.rb')
|
||||
raise "#{path} already exists!" if File.exist? path
|
||||
|
||||
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}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user