2009-08-31 16:01:36 +01:00
|
|
|
# Copyright 2009 Max Howell and other contributors.
|
2009-07-24 15:10:01 +01:00
|
|
|
#
|
2009-08-31 16:01:36 +01:00
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
2009-07-24 15:10:01 +01:00
|
|
|
#
|
2009-08-31 16:01:36 +01:00
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
2009-07-24 15:10:01 +01:00
|
|
|
#
|
2009-08-31 16:01:36 +01:00
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2009-08-21 20:30:13 +01:00
|
|
|
#
|
2009-10-15 09:07:12 +01:00
|
|
|
require 'download_strategy'
|
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
class ExecutionError <RuntimeError
|
|
|
|
def initialize cmd, args=[]
|
2009-09-05 20:46:07 +01:00
|
|
|
super "Failure while executing: #{cmd} #{args*' '}"
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
|
|
|
end
|
2009-08-21 20:30:13 +01:00
|
|
|
class BuildError <ExecutionError
|
|
|
|
end
|
2009-08-10 16:48:30 +01:00
|
|
|
class FormulaUnavailableError <RuntimeError
|
|
|
|
def initialize name
|
2009-09-23 10:06:19 -07:00
|
|
|
@name = name
|
2009-08-10 16:48:30 +01:00
|
|
|
super "No available formula for #{name}"
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
2009-09-23 10:06:19 -07:00
|
|
|
|
|
|
|
attr_reader :name
|
2009-08-10 16:48:30 +01:00
|
|
|
end
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-08-11 18:16:12 +01:00
|
|
|
|
2009-08-21 20:20:44 +01:00
|
|
|
# Derive and define at least @url, see Library/Formula for examples
|
|
|
|
class Formula
|
|
|
|
# Homebrew determines the name
|
2009-08-22 17:26:15 +01:00
|
|
|
def initialize name='__UNKNOWN__'
|
2009-09-22 13:03:46 -04:00
|
|
|
set_instance_variable 'url'
|
|
|
|
set_instance_variable 'head'
|
2009-10-17 14:35:24 +02:00
|
|
|
set_instance_variable 'specs'
|
2009-08-23 17:57:45 +01:00
|
|
|
|
|
|
|
if @head and (not @url or ARGV.flag? '--HEAD')
|
|
|
|
@url=@head
|
|
|
|
@version='HEAD'
|
|
|
|
end
|
|
|
|
|
2009-08-11 12:20:55 -07:00
|
|
|
raise if @url.nil?
|
2009-08-21 20:20:44 +01:00
|
|
|
@name=name
|
2009-08-22 17:26:15 +01:00
|
|
|
validate_variable :name
|
2009-09-22 13:03:46 -04:00
|
|
|
|
|
|
|
set_instance_variable 'version'
|
|
|
|
@version ||= Pathname.new(@url).version
|
2009-08-22 17:26:15 +01:00
|
|
|
validate_variable :version if @version
|
2009-09-22 13:03:46 -04:00
|
|
|
|
|
|
|
set_instance_variable 'homepage'
|
2009-09-26 02:20:00 +01:00
|
|
|
# raise if @homepage.nil? # not a good idea while we have eg GitManpages!
|
2009-09-22 13:03:46 -04:00
|
|
|
|
2009-09-07 16:10:50 +02:00
|
|
|
CHECKSUM_TYPES.each do |type|
|
2009-09-22 13:03:46 -04:00
|
|
|
set_instance_variable type
|
2009-09-07 16:10:50 +02:00
|
|
|
end
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# if the dir is there, but it's empty we consider it not installed
|
|
|
|
def installed?
|
2009-07-29 00:57:55 +01:00
|
|
|
return prefix.children.length > 0
|
2009-07-24 15:10:01 +01:00
|
|
|
rescue
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
def prefix
|
2009-08-22 17:26:15 +01:00
|
|
|
validate_variable :name
|
|
|
|
validate_variable :version
|
2009-07-31 02:51:17 +01:00
|
|
|
HOMEBREW_CELLAR+@name+@version
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
2009-08-01 17:54:18 +01:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
def path
|
2009-08-21 20:20:44 +01:00
|
|
|
self.class.path name
|
2009-08-10 16:48:30 +01:00
|
|
|
end
|
|
|
|
|
2009-10-17 14:35:24 +02:00
|
|
|
attr_reader :url, :version, :homepage, :name, :specs
|
2009-08-10 16:48:30 +01:00
|
|
|
|
|
|
|
def bin; prefix+'bin' end
|
2009-08-12 09:43:16 +08:00
|
|
|
def sbin; prefix+'sbin' end
|
2009-08-10 16:48:30 +01:00
|
|
|
def doc; prefix+'share'+'doc'+name end
|
|
|
|
def lib; prefix+'lib' end
|
2009-08-21 16:24:14 -07:00
|
|
|
def libexec; prefix+'libexec' end
|
2009-08-10 16:48:30 +01:00
|
|
|
def man; prefix+'share'+'man' end
|
2009-08-01 17:54:18 +01:00
|
|
|
def man1; man+'man1' end
|
2009-08-10 16:48:30 +01:00
|
|
|
def info; prefix+'share'+'info' end
|
2009-08-01 17:54:18 +01:00
|
|
|
def include; prefix+'include' end
|
2009-09-08 22:01:41 +01:00
|
|
|
def share; prefix+'share' end
|
2009-10-02 15:55:34 +01:00
|
|
|
|
2009-10-03 15:23:28 +01:00
|
|
|
# generally we don't want var stuff inside the keg
|
2009-10-01 14:44:40 +01:00
|
|
|
def var; HOMEBREW_PREFIX+'var' end
|
2009-10-03 15:23:28 +01:00
|
|
|
# configuration needs to be preserved past upgrades
|
2009-10-02 15:55:34 +01:00
|
|
|
def etc; HOMEBREW_PREFIX+'etc' end
|
2009-10-03 15:23:28 +01:00
|
|
|
|
2009-08-11 12:20:55 -07:00
|
|
|
# reimplement if we don't autodetect the download strategy you require
|
|
|
|
def download_strategy
|
|
|
|
case url
|
2009-09-27 19:30:39 -04:00
|
|
|
when %r[^cvs://] then CVSDownloadStrategy
|
|
|
|
when %r[^hg://] then MercurialDownloadStrategy
|
2009-09-06 15:17:46 -04:00
|
|
|
when %r[^svn://] then SubversionDownloadStrategy
|
2009-10-19 02:59:15 +01:00
|
|
|
when %r[^svn+http://] then SubversionDownloadStrategy
|
2009-09-06 15:17:46 -04:00
|
|
|
when %r[^git://] then GitDownloadStrategy
|
|
|
|
when %r[^http://(.+?\.)?googlecode\.com/svn] then SubversionDownloadStrategy
|
2009-09-30 16:36:06 -07:00
|
|
|
when %r[^http://(.+?\.)?sourceforge\.net/svnroot/] then SubversionDownloadStrategy
|
2009-09-06 15:17:46 -04:00
|
|
|
when %r[^http://svn.apache.org/repos/] then SubversionDownloadStrategy
|
2009-10-02 18:36:58 +01:00
|
|
|
else CurlDownloadStrategy
|
2009-08-11 12:20:55 -07:00
|
|
|
end
|
|
|
|
end
|
2009-09-28 14:06:53 -07:00
|
|
|
|
|
|
|
# tell the user about any caveats regarding this package, return a string
|
2009-08-10 16:48:30 +01:00
|
|
|
def caveats; nil end
|
2009-09-28 14:06:53 -07:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
# patches are automatically applied after extracting the tarball
|
2009-08-11 18:16:12 +01:00
|
|
|
# return an array of strings, or if you need a patch level other than -p0
|
|
|
|
# return a Hash eg.
|
|
|
|
# {
|
|
|
|
# :p0 => ['http://foo.com/patch1', 'http://foo.com/patch2'],
|
|
|
|
# :p1 => 'http://bar.com/patch2',
|
|
|
|
# :p2 => ['http://moo.com/patch5', 'http://moo.com/patch6']
|
|
|
|
# }
|
2009-09-17 21:10:39 +01:00
|
|
|
# The final option is to return DATA, then put a diff after __END__. You
|
2009-09-04 15:28:18 +01:00
|
|
|
# can still return a Hash with DATA as the value for a patch level key.
|
2009-09-21 23:51:31 +01:00
|
|
|
def patches; end
|
2009-09-28 14:06:53 -07:00
|
|
|
|
2009-09-17 21:10:39 +01:00
|
|
|
# rarely, you don't want your library symlinked into the main prefix
|
|
|
|
# see gettext.rb for an example
|
|
|
|
def keg_only?; false end
|
2009-08-10 16:48:30 +01:00
|
|
|
|
2009-09-28 14:06:53 -07:00
|
|
|
# sometimes the clean process breaks things
|
|
|
|
# skip cleaning paths in a formula with a class method like this:
|
|
|
|
# skip_clean [bin+"foo", lib+"bar"]
|
|
|
|
# redefining skip_clean? in formulas is now deprecated
|
|
|
|
def skip_clean? path
|
|
|
|
to_check = path.relative_path_from(prefix).to_s
|
|
|
|
self.class.skip_clean_paths.include?(to_check)
|
|
|
|
end
|
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
# yields self with current working directory set to the uncompressed tarball
|
|
|
|
def brew
|
2009-08-22 17:26:15 +01:00
|
|
|
validate_variable :name
|
|
|
|
validate_variable :version
|
Dependency resolution
Specify dependencies in your formula's deps function. You can return an Array,
String or Hash, eg:
def deps
{ :optional => 'libogg', :required => %w[flac sdl], :recommended => 'cmake' }
end
Note currently the Hash is flattened and qualifications are ignored. If you
only return an Array or String, the qualification is assumed to be :required.
Other packaging systems have problems when it comes to packages requiring a
specific version of a package, or some patches that may not work well with
other software. With Homebrew we have some options:
1. If the formula is vanilla but an older version we can cherry-pick the old
version and install it in the Cellar in parallel, but just not symlink it
into /usr/local while forcing the formula that depends on it to link to
that one and not any other versions of it.
2. If the dependency requires patches then we shouldn't install this for use
by any other tools, (I guess this needs to be decided on a per-situation
basis). It can be installed into the parent formula's prefix, and not
symlinked into /usr/local. In this case the dependency's Formula
derivation should be saved in the parent formula's file (check git or
flac for an example of this).
Both the above can be done currently with hacks, so I'll flesh out a proper
way sometime this week.
2009-09-07 01:06:08 +01:00
|
|
|
|
2009-08-11 12:20:55 -07:00
|
|
|
stage do
|
2009-08-10 16:48:30 +01:00
|
|
|
begin
|
|
|
|
patch
|
2009-09-04 15:28:18 +01:00
|
|
|
# we allow formulas to do anything they want to the Ruby process
|
|
|
|
# so load any deps before this point! And exit asap afterwards
|
2009-08-10 16:48:30 +01:00
|
|
|
yield self
|
|
|
|
rescue Interrupt, RuntimeError, SystemCallError => e
|
|
|
|
raise unless ARGV.debug?
|
|
|
|
onoe e.inspect
|
|
|
|
puts e.backtrace
|
|
|
|
ohai "Rescuing build..."
|
2009-08-27 13:46:19 -07:00
|
|
|
puts "When you exit this shell Homebrew will attempt to finalise the installation."
|
|
|
|
puts "If nothing is installed or the shell exits with a non-zero error code,"
|
|
|
|
puts "Homebrew will abort. The installation prefix is:"
|
|
|
|
puts prefix
|
2009-08-10 16:48:30 +01:00
|
|
|
interactive_shell
|
|
|
|
end
|
|
|
|
end
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
2009-08-10 16:48:30 +01:00
|
|
|
|
2009-08-21 20:20:44 +01:00
|
|
|
# we don't have a std_autotools variant because autotools is a lot less
|
|
|
|
# consistent and the standard parameters are more memorable
|
|
|
|
# really Homebrew should determine what works inside brew() then
|
|
|
|
# we could add --disable-dependency-tracking when it will work
|
|
|
|
def std_cmake_parameters
|
|
|
|
# The None part makes cmake use the environment's CFLAGS etc. settings
|
|
|
|
"-DCMAKE_INSTALL_PREFIX='#{prefix}' -DCMAKE_BUILD_TYPE=None"
|
|
|
|
end
|
|
|
|
|
2009-09-11 14:22:46 +01:00
|
|
|
def self.class_s name
|
2009-08-21 20:20:44 +01:00
|
|
|
#remove invalid characters and camelcase
|
2009-10-19 01:43:57 +01:00
|
|
|
name.capitalize.gsub(/[-_\s]([a-zA-Z0-9])/) { $1.upcase }.gsub('+', 'x')
|
2009-08-21 20:20:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.factory name
|
2009-09-18 19:16:39 +01:00
|
|
|
return name if name.kind_of? Formula
|
2009-09-04 15:28:18 +01:00
|
|
|
path = Pathname.new(name)
|
|
|
|
if path.absolute?
|
|
|
|
require name
|
|
|
|
name = path.stem
|
|
|
|
else
|
|
|
|
require self.path(name)
|
|
|
|
end
|
2009-09-23 10:06:19 -07:00
|
|
|
begin
|
|
|
|
klass_name =self.class_s(name)
|
|
|
|
klass = eval(klass_name)
|
|
|
|
rescue NameError
|
|
|
|
# TODO really this text should be encoded into the exception
|
|
|
|
# and only shown if the UI deems it correct to show it
|
|
|
|
onoe "class \"#{klass_name}\" expected but not found in #{name}.rb"
|
|
|
|
puts "Double-check the name of the class in that formula."
|
|
|
|
raise LoadError
|
|
|
|
end
|
|
|
|
return klass.new(name)
|
2009-08-21 20:20:44 +01:00
|
|
|
rescue LoadError
|
|
|
|
raise FormulaUnavailableError.new(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.path name
|
|
|
|
HOMEBREW_PREFIX+'Library'+'Formula'+"#{name.downcase}.rb"
|
|
|
|
end
|
|
|
|
|
2009-09-18 19:16:39 +01:00
|
|
|
def deps
|
|
|
|
self.class.deps or []
|
|
|
|
end
|
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
protected
|
2009-07-24 15:10:01 +01:00
|
|
|
# Pretty titles the command and buffers stdout/stderr
|
|
|
|
# Throws if there's an error
|
2009-08-10 16:48:30 +01:00
|
|
|
def system cmd, *args
|
|
|
|
full="#{cmd} #{args*' '}".strip
|
|
|
|
ohai full
|
|
|
|
if ARGV.verbose?
|
|
|
|
safe_system cmd, *args
|
2009-07-24 15:10:01 +01:00
|
|
|
else
|
|
|
|
out=''
|
2009-08-10 16:48:30 +01:00
|
|
|
# TODO write a ruby extension that does a good popen :P
|
|
|
|
IO.popen "#{full} 2>&1" do |f|
|
2009-07-24 15:10:01 +01:00
|
|
|
until f.eof?
|
|
|
|
out+=f.gets
|
|
|
|
end
|
|
|
|
end
|
2009-08-10 16:48:30 +01:00
|
|
|
unless $? == 0
|
2009-09-08 11:14:03 -07:00
|
|
|
puts "Exit code: #{$?}"
|
2009-08-10 16:48:30 +01:00
|
|
|
puts out
|
|
|
|
raise
|
|
|
|
end
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
2009-08-10 16:48:30 +01:00
|
|
|
rescue
|
|
|
|
raise BuildError.new(cmd, args)
|
|
|
|
end
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
private
|
2009-08-11 12:20:55 -07:00
|
|
|
# creates a temporary directory then yields, when the block returns it
|
|
|
|
# recursively deletes the temporary directory
|
2009-08-10 16:48:30 +01:00
|
|
|
def mktemp
|
2009-08-23 17:57:45 +01:00
|
|
|
# I used /tmp rather than mktemp -td because that generates a directory
|
|
|
|
# name with exotic characters like + in it, and these break badly written
|
|
|
|
# scripts that don't escape strings before trying to regexp them :(
|
2009-09-23 16:44:10 +01:00
|
|
|
tmp=Pathname.new `/usr/bin/mktemp -d /tmp/homebrew-#{name}-#{version}-XXXX`.strip
|
2009-08-23 17:57:45 +01:00
|
|
|
raise "Couldn't create build sandbox" if not tmp.directory? or $? != 0
|
2009-08-10 16:48:30 +01:00
|
|
|
begin
|
|
|
|
wd=Dir.pwd
|
|
|
|
Dir.chdir tmp
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
Dir.chdir wd
|
|
|
|
tmp.rmtree
|
|
|
|
end
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
|
|
|
|
2009-09-07 16:10:50 +02:00
|
|
|
CHECKSUM_TYPES=[:md5, :sha1, :sha256].freeze
|
|
|
|
|
2009-07-31 11:05:23 -07:00
|
|
|
def verify_download_integrity fn
|
|
|
|
require 'digest'
|
2009-09-07 16:10:50 +02:00
|
|
|
type=CHECKSUM_TYPES.detect { |type| instance_variable_defined?("@#{type}") }
|
|
|
|
type ||= :md5
|
|
|
|
supplied=instance_variable_get("@#{type}")
|
|
|
|
type=type.to_s.upcase
|
|
|
|
hash=Digest.const_get(type).hexdigest(fn.read)
|
2009-07-31 11:05:23 -07:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
if supplied and not supplied.empty?
|
2009-07-31 11:05:23 -07:00
|
|
|
raise "#{type} mismatch: #{hash}" unless supplied.upcase == hash.upcase
|
|
|
|
else
|
|
|
|
opoo "Cannot verify package integrity"
|
|
|
|
puts "The formula did not provide a download checksum"
|
2009-08-11 12:20:55 -07:00
|
|
|
puts "For your reference the #{type} is: #{hash}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def stage
|
2009-10-17 14:35:24 +02:00
|
|
|
ds=download_strategy.new url, name, version, specs
|
2009-08-11 12:20:55 -07:00
|
|
|
HOMEBREW_CACHE.mkpath
|
|
|
|
dl=ds.fetch
|
|
|
|
verify_download_integrity dl if dl.kind_of? Pathname
|
|
|
|
mktemp do
|
|
|
|
ds.stage
|
|
|
|
yield
|
2009-07-31 11:05:23 -07:00
|
|
|
end
|
|
|
|
end
|
2009-09-04 15:28:18 +01:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
def patch
|
2009-09-16 17:08:32 +01:00
|
|
|
return if patches.nil?
|
2009-09-15 20:07:40 +01:00
|
|
|
|
2009-08-11 18:16:12 +01:00
|
|
|
ohai "Patching"
|
2009-09-09 11:59:46 -04:00
|
|
|
if not patches.kind_of? Hash
|
|
|
|
# We assume -p0
|
2009-09-16 17:08:32 +01:00
|
|
|
patch_defns = { :p1 => patches }
|
2009-09-09 11:59:46 -04:00
|
|
|
else
|
|
|
|
patch_defns = patches
|
|
|
|
end
|
|
|
|
|
|
|
|
patch_list=[]
|
|
|
|
n=0
|
|
|
|
patch_defns.each do |arg, urls|
|
2009-09-16 17:08:32 +01:00
|
|
|
# DATA.each does each line, which doesn't work so great
|
|
|
|
urls = [urls] unless urls.kind_of? Array
|
|
|
|
|
2009-09-09 11:59:46 -04:00
|
|
|
urls.each do |url|
|
2009-09-04 15:28:18 +01:00
|
|
|
p = {:filename => '%03d-homebrew.diff' % n+=1, :compression => false}
|
2009-09-15 20:07:40 +01:00
|
|
|
|
2009-09-04 15:28:18 +01:00
|
|
|
if defined? DATA and url == DATA
|
|
|
|
pn=Pathname.new p[:filename]
|
|
|
|
pn.write DATA.read
|
|
|
|
elsif url =~ %r[^\w+\://]
|
2009-09-15 20:07:40 +01:00
|
|
|
out_fn = p[:filename]
|
|
|
|
case url
|
|
|
|
when /\.gz$/
|
|
|
|
p[:compression] = :gzip
|
2009-09-04 15:28:18 +01:00
|
|
|
out_fn += '.gz'
|
2009-09-15 20:07:40 +01:00
|
|
|
when /\.bz2$/
|
|
|
|
p[:compression] = :bzip2
|
2009-09-04 15:28:18 +01:00
|
|
|
out_fn += '.bz2'
|
2009-09-15 20:07:40 +01:00
|
|
|
end
|
|
|
|
p[:curl_args] = [url, '-o', out_fn]
|
|
|
|
else
|
|
|
|
# it's a file on the local filesystem
|
|
|
|
p[:filename] = url
|
2009-08-11 18:16:12 +01:00
|
|
|
end
|
2009-09-15 20:07:40 +01:00
|
|
|
|
|
|
|
p[:args] = ["-#{arg}", '-i', p[:filename]]
|
|
|
|
|
|
|
|
patch_list << p
|
2009-08-11 18:16:12 +01:00
|
|
|
end
|
2009-09-09 11:59:46 -04:00
|
|
|
end
|
2009-09-04 15:28:18 +01:00
|
|
|
|
|
|
|
return if patch_list.empty?
|
2009-09-15 20:07:40 +01:00
|
|
|
|
2009-09-09 11:59:46 -04:00
|
|
|
# downloading all at once is much more efficient, espeically for FTP
|
2009-09-04 15:28:18 +01:00
|
|
|
curl *(patch_list.collect{|p| p[:curl_args]}.select{|p| p}.flatten)
|
2009-09-15 20:07:40 +01:00
|
|
|
|
2009-09-09 11:59:46 -04:00
|
|
|
patch_list.each do |p|
|
|
|
|
case p[:compression]
|
2009-09-23 16:44:10 +01:00
|
|
|
when :gzip then safe_system "/usr/bin/gunzip", p[:filename]+'.gz'
|
|
|
|
when :bzip2 then safe_system "/usr/bin/bunzip2", p[:filename]+'.bz2'
|
2009-08-11 18:16:12 +01:00
|
|
|
end
|
2009-09-09 11:59:46 -04:00
|
|
|
# -f means it doesn't prompt the user if there are errors, if just
|
|
|
|
# exits with non-zero status
|
2009-09-23 16:44:10 +01:00
|
|
|
safe_system '/usr/bin/patch', '-f', *(p[:args])
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
|
|
|
end
|
2009-08-11 18:16:12 +01:00
|
|
|
|
2009-08-22 17:26:15 +01:00
|
|
|
def validate_variable name
|
2009-09-28 14:10:20 -07:00
|
|
|
v = instance_variable_get("@#{name}")
|
2009-08-30 16:11:44 +01:00
|
|
|
raise "Invalid @#{name}" if v.to_s.empty? or v =~ /\s/
|
2009-08-22 17:26:15 +01:00
|
|
|
end
|
2009-09-28 14:10:20 -07:00
|
|
|
|
2009-09-22 13:03:46 -04:00
|
|
|
def set_instance_variable(type)
|
|
|
|
if !instance_variable_defined?("@#{type}")
|
|
|
|
class_value = self.class.send(type)
|
|
|
|
instance_variable_set("@#{type}", class_value) if class_value
|
|
|
|
end
|
|
|
|
end
|
2009-08-22 17:26:15 +01:00
|
|
|
|
2009-07-31 14:17:56 +01:00
|
|
|
def method_added method
|
|
|
|
raise 'You cannot override Formula.brew' if method == 'brew'
|
|
|
|
end
|
2009-08-21 20:20:44 +01:00
|
|
|
|
2009-09-28 14:06:53 -07:00
|
|
|
class << self
|
|
|
|
|
2009-09-22 12:31:53 -04:00
|
|
|
def self.attr_rw(*attrs)
|
|
|
|
attrs.each do |attr|
|
|
|
|
class_eval %Q{
|
|
|
|
def #{attr}(val=nil)
|
|
|
|
val.nil? ? @#{attr} : @#{attr} = val
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2009-09-28 14:06:53 -07:00
|
|
|
|
2009-10-17 14:35:24 +02:00
|
|
|
attr_rw :url, :version, :homepage, :specs, :deps, *CHECKSUM_TYPES
|
|
|
|
|
|
|
|
def head val=nil, specs=nil
|
|
|
|
if specs
|
|
|
|
@specs = specs
|
|
|
|
end
|
|
|
|
val.nil? ? @head : @head = val
|
|
|
|
end
|
2009-09-28 14:06:53 -07:00
|
|
|
|
2009-09-18 19:16:39 +01:00
|
|
|
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
|
2009-09-28 14:06:53 -07:00
|
|
|
|
|
|
|
def skip_clean paths
|
|
|
|
@skip_clean_paths ||= []
|
|
|
|
[paths].flatten.each do |p|
|
|
|
|
@skip_clean_paths << p.to_s unless @skip_clean_paths.include? p.to_s
|
|
|
|
end
|
|
|
|
end
|
2009-09-29 23:51:37 +01:00
|
|
|
|
|
|
|
def skip_clean_paths
|
|
|
|
@skip_clean_paths or []
|
|
|
|
end
|
2009-09-28 14:06:53 -07:00
|
|
|
end
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# see ack.rb for an example usage
|
2009-08-21 20:20:44 +01:00
|
|
|
class ScriptFileFormula <Formula
|
2009-07-24 15:10:01 +01:00
|
|
|
def install
|
2009-08-11 12:20:55 -07:00
|
|
|
bin.install Dir['*']
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
# see flac.rb for example usage
|
2009-07-24 15:10:01 +01:00
|
|
|
class GithubGistFormula <ScriptFileFormula
|
2009-08-30 15:32:15 +01:00
|
|
|
def initialize name='__UNKNOWN__'
|
2009-08-21 20:20:44 +01:00
|
|
|
super name
|
2009-08-30 15:32:15 +01:00
|
|
|
@version=File.basename(File.dirname(url))[0,6]
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
|
|
|
end
|