2012-02-04 18:45:08 -08:00
|
|
|
require 'download_strategy'
|
2013-04-04 12:34:24 -05:00
|
|
|
require 'checksum'
|
2012-07-10 16:01:02 -05:00
|
|
|
require 'version'
|
2012-02-04 18:45:08 -08:00
|
|
|
|
2012-04-05 21:09:24 -05:00
|
|
|
class SoftwareSpec
|
2012-06-25 21:39:28 -05:00
|
|
|
attr_reader :checksum, :mirrors, :specs
|
2012-02-04 18:45:08 -08:00
|
|
|
|
2012-06-26 12:44:43 -05:00
|
|
|
def initialize url=nil, version=nil
|
|
|
|
@url = url
|
|
|
|
@version = version
|
2012-07-05 13:11:44 -05:00
|
|
|
@mirrors = []
|
2013-02-11 20:50:52 -06:00
|
|
|
@specs = {}
|
2013-03-28 17:37:29 -05:00
|
|
|
@checksum = nil
|
|
|
|
@using = nil
|
2012-06-26 12:44:43 -05:00
|
|
|
end
|
|
|
|
|
2012-02-04 18:45:08 -08:00
|
|
|
def download_strategy
|
2012-10-15 01:19:31 -05:00
|
|
|
@download_strategy ||= DownloadStrategyDetector.detect(@url, @using)
|
2012-02-04 18:45:08 -08:00
|
|
|
end
|
|
|
|
|
2012-06-18 19:58:35 -05:00
|
|
|
def verify_download_integrity fn
|
|
|
|
fn.verify_checksum @checksum
|
|
|
|
rescue ChecksumMissingError
|
|
|
|
opoo "Cannot verify package integrity"
|
|
|
|
puts "The formula did not provide a download checksum"
|
|
|
|
puts "For your reference the SHA1 is: #{fn.sha1}"
|
|
|
|
rescue ChecksumMismatchError => e
|
|
|
|
e.advice = <<-EOS.undent
|
|
|
|
Archive: #{fn}
|
|
|
|
(To retry an incomplete download, remove the file above.)
|
|
|
|
EOS
|
|
|
|
raise e
|
|
|
|
end
|
|
|
|
|
2012-04-05 21:09:24 -05:00
|
|
|
# The methods that follow are used in the block-form DSL spec methods
|
2012-06-18 19:58:35 -05:00
|
|
|
Checksum::TYPES.each do |cksum|
|
2013-03-12 00:38:52 -05:00
|
|
|
class_eval <<-EOS, __FILE__, __LINE__ + 1
|
2013-03-18 14:59:10 -05:00
|
|
|
def #{cksum}(val)
|
|
|
|
@checksum = Checksum.new(:#{cksum}, val)
|
2012-04-05 21:09:24 -05:00
|
|
|
end
|
2013-03-12 00:38:52 -05:00
|
|
|
EOS
|
2012-04-05 21:09:24 -05:00
|
|
|
end
|
|
|
|
|
2013-02-11 20:50:52 -06:00
|
|
|
def url val=nil, specs={}
|
2012-04-05 21:09:24 -05:00
|
|
|
return @url if val.nil?
|
|
|
|
@url = val
|
2013-02-11 20:50:52 -06:00
|
|
|
@using = specs.delete(:using)
|
|
|
|
@specs.merge!(specs)
|
2012-04-05 21:09:24 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def version val=nil
|
2012-07-10 21:45:17 -05:00
|
|
|
@version ||= case val
|
|
|
|
when nil then Version.parse(@url)
|
|
|
|
when Hash
|
|
|
|
key, value = val.shift
|
|
|
|
scheme = VersionSchemeDetector.new(value).detect
|
|
|
|
scheme.new(key)
|
|
|
|
else Version.new(val)
|
|
|
|
end
|
2012-04-05 21:09:24 -05:00
|
|
|
end
|
|
|
|
|
2012-06-26 01:35:37 -05:00
|
|
|
def mirror val
|
|
|
|
@mirrors << val
|
2012-04-05 21:09:24 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class HeadSoftwareSpec < SoftwareSpec
|
2012-07-10 16:01:02 -05:00
|
|
|
def initialize url=nil, version=Version.new(:HEAD)
|
2012-04-05 21:09:24 -05:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def verify_download_integrity fn
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Bottle < SoftwareSpec
|
|
|
|
attr_writer :url
|
|
|
|
|
2013-02-09 19:06:54 -08:00
|
|
|
def initialize
|
2012-06-18 19:58:35 -05:00
|
|
|
super
|
2012-04-05 21:09:24 -05:00
|
|
|
@revision = 0
|
2013-03-11 18:56:26 +00:00
|
|
|
@prefix = '/usr/local'
|
2013-02-28 22:14:59 +00:00
|
|
|
@cellar = '/usr/local/Cellar'
|
2012-04-05 21:09:24 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# Checksum methods in the DSL's bottle block optionally take
|
|
|
|
# a Hash, which indicates the platform the checksum applies on.
|
2012-06-18 19:58:35 -05:00
|
|
|
Checksum::TYPES.each do |cksum|
|
2013-03-12 00:38:52 -05:00
|
|
|
class_eval <<-EOS, __FILE__, __LINE__ + 1
|
2013-03-18 14:59:10 -05:00
|
|
|
def #{cksum}(val)
|
2012-04-05 21:09:24 -05:00
|
|
|
@#{cksum} ||= Hash.new
|
|
|
|
case val
|
|
|
|
when Hash
|
|
|
|
key, value = val.shift
|
2012-06-18 19:58:35 -05:00
|
|
|
@#{cksum}[value] = Checksum.new(:#{cksum}, key)
|
2012-04-05 21:09:24 -05:00
|
|
|
end
|
2012-06-18 19:58:35 -05:00
|
|
|
|
2013-01-27 18:41:06 +00:00
|
|
|
if @#{cksum}.has_key? MacOS.cat
|
|
|
|
@checksum = @#{cksum}[MacOS.cat]
|
|
|
|
end
|
2012-04-05 21:09:24 -05:00
|
|
|
end
|
2013-03-12 00:38:52 -05:00
|
|
|
EOS
|
2012-04-05 21:09:24 -05:00
|
|
|
end
|
|
|
|
|
2013-02-09 19:05:53 -08:00
|
|
|
def root_url val=nil
|
|
|
|
val.nil? ? @root_url : @root_url = val
|
2013-03-11 18:56:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def prefix val=nil
|
|
|
|
val.nil? ? @prefix : @prefix = val
|
2013-02-09 19:05:53 -08:00
|
|
|
end
|
|
|
|
|
2013-02-28 22:14:59 +00:00
|
|
|
def cellar val=nil
|
|
|
|
val.nil? ? @cellar : @cellar = val
|
|
|
|
end
|
|
|
|
|
2013-02-09 19:06:54 -08:00
|
|
|
def revision val=nil
|
|
|
|
val.nil? ? @revision : @revision = val
|
2012-04-05 21:09:24 -05:00
|
|
|
end
|
2012-02-04 18:45:08 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Used to annotate formulae that duplicate OS X provided software
|
|
|
|
# or cause conflicts when linked in.
|
|
|
|
class KegOnlyReason
|
|
|
|
attr_reader :reason, :explanation
|
|
|
|
|
|
|
|
def initialize reason, explanation=nil
|
|
|
|
@reason = reason
|
|
|
|
@explanation = explanation
|
2012-08-09 02:00:58 -05:00
|
|
|
@valid = case @reason
|
2012-08-23 09:49:08 -07:00
|
|
|
when :provided_pre_mountain_lion then MacOS.version < :mountain_lion
|
2012-08-09 02:00:58 -05:00
|
|
|
else true
|
|
|
|
end
|
2012-02-04 18:45:08 -08:00
|
|
|
end
|
|
|
|
|
2012-08-09 02:00:58 -05:00
|
|
|
def valid?
|
|
|
|
@valid
|
|
|
|
end
|
2012-02-04 18:45:08 -08:00
|
|
|
|
2012-08-09 02:00:58 -05:00
|
|
|
def to_s
|
|
|
|
case @reason
|
|
|
|
when :provided_by_osx then <<-EOS.undent
|
|
|
|
Mac OS X already provides this software and installing another version in
|
|
|
|
parallel can cause all kinds of trouble.
|
|
|
|
|
|
|
|
#{@explanation}
|
|
|
|
EOS
|
2012-08-23 09:49:08 -07:00
|
|
|
when :provided_pre_mountain_lion then <<-EOS.undent
|
|
|
|
Mac OS X already provides this software in versions before Mountain Lion.
|
2012-08-09 02:00:58 -05:00
|
|
|
|
|
|
|
#{@explanation}
|
|
|
|
EOS
|
2012-02-04 18:45:08 -08:00
|
|
|
else
|
2012-08-09 02:00:58 -05:00
|
|
|
@reason
|
|
|
|
end.strip
|
2012-02-04 18:45:08 -08:00
|
|
|
end
|
|
|
|
end
|