2013-09-17 21:25:38 -05:00
|
|
|
require 'forwardable'
|
|
|
|
require 'resource'
|
2013-09-14 10:16:52 -05:00
|
|
|
require 'checksum'
|
|
|
|
require 'version'
|
2013-09-21 19:27:24 -05:00
|
|
|
require 'build_options'
|
2013-09-21 19:27:24 -05:00
|
|
|
require 'dependency_collector'
|
2013-10-21 21:25:42 -07:00
|
|
|
require 'bottles'
|
2014-03-13 19:51:23 -05:00
|
|
|
require 'patch'
|
2013-09-14 10:16:52 -05:00
|
|
|
|
|
|
|
class SoftwareSpec
|
2013-09-17 21:25:38 -05:00
|
|
|
extend Forwardable
|
2013-09-14 10:16:52 -05:00
|
|
|
|
2014-03-13 19:51:23 -05:00
|
|
|
attr_reader :name, :owner
|
|
|
|
attr_reader :build, :resources, :patches
|
2013-09-21 19:27:24 -05:00
|
|
|
attr_reader :dependency_collector
|
2014-03-10 14:56:02 -05:00
|
|
|
attr_reader :bottle_specification
|
2013-09-17 21:25:39 -05:00
|
|
|
|
2014-02-22 20:17:04 -05:00
|
|
|
def_delegators :@resource, :stage, :fetch, :verify_download_integrity
|
2014-02-21 00:41:07 -05:00
|
|
|
def_delegators :@resource, :cached_download, :clear_cache
|
2014-07-22 19:12:26 -05:00
|
|
|
def_delegators :@resource, :checksum, :mirrors, :specs, :using
|
2013-09-28 16:37:05 -05:00
|
|
|
def_delegators :@resource, :version, :mirror, *Checksum::TYPES
|
2013-09-14 10:16:52 -05:00
|
|
|
|
2013-09-23 21:39:19 -05:00
|
|
|
def initialize
|
|
|
|
@resource = Resource.new
|
2013-09-17 21:25:39 -05:00
|
|
|
@resources = {}
|
2013-09-21 19:27:24 -05:00
|
|
|
@build = BuildOptions.new(ARGV.options_only)
|
2013-09-21 19:27:24 -05:00
|
|
|
@dependency_collector = DependencyCollector.new
|
2014-03-10 14:56:02 -05:00
|
|
|
@bottle_specification = BottleSpecification.new
|
2014-03-13 19:51:23 -05:00
|
|
|
@patches = []
|
2013-09-17 21:25:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def owner= owner
|
2013-09-23 21:39:19 -05:00
|
|
|
@name = owner.name
|
2014-02-27 14:50:22 -06:00
|
|
|
@owner = owner
|
2013-09-23 21:39:19 -05:00
|
|
|
@resource.owner = self
|
2013-11-26 18:47:41 -06:00
|
|
|
resources.each_value do |r|
|
|
|
|
r.owner = self
|
|
|
|
r.version ||= version
|
|
|
|
end
|
2014-03-13 19:51:23 -05:00
|
|
|
patches.each { |p| p.owner = self }
|
2013-09-17 21:25:39 -05:00
|
|
|
end
|
|
|
|
|
2013-09-28 16:37:05 -05:00
|
|
|
def url val=nil, specs={}
|
|
|
|
return @resource.url if val.nil?
|
|
|
|
@resource.url(val, specs)
|
|
|
|
dependency_collector.add(@resource)
|
|
|
|
end
|
|
|
|
|
2014-03-10 14:56:02 -05:00
|
|
|
def bottled?
|
2014-04-01 16:03:08 -05:00
|
|
|
bottle_specification.tag?(bottle_tag)
|
2014-03-10 14:56:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def bottle &block
|
|
|
|
bottle_specification.instance_eval(&block)
|
|
|
|
end
|
|
|
|
|
2013-09-17 21:25:40 -05:00
|
|
|
def resource? name
|
|
|
|
resources.has_key?(name)
|
|
|
|
end
|
|
|
|
|
2013-09-17 21:25:39 -05:00
|
|
|
def resource name, &block
|
|
|
|
if block_given?
|
2013-09-17 21:25:40 -05:00
|
|
|
raise DuplicateResourceError.new(name) if resource?(name)
|
2014-03-14 23:42:53 -05:00
|
|
|
res = Resource.new(name, &block)
|
|
|
|
resources[name] = res
|
|
|
|
dependency_collector.add(res)
|
2013-09-17 21:25:39 -05:00
|
|
|
else
|
|
|
|
resources.fetch(name) { raise ResourceMissingError.new(owner, name) }
|
|
|
|
end
|
2013-09-14 10:16:52 -05:00
|
|
|
end
|
2013-09-21 19:27:24 -05:00
|
|
|
|
|
|
|
def option name, description=nil
|
2013-10-07 00:40:32 -07:00
|
|
|
name = 'c++11' if name == :cxx11
|
2013-09-21 19:27:24 -05:00
|
|
|
name = name.to_s if Symbol === name
|
|
|
|
raise "Option name is required." if name.empty?
|
|
|
|
raise "Options should not start with dashes." if name[0, 1] == "-"
|
|
|
|
build.add(name, description)
|
|
|
|
end
|
2013-09-21 19:27:24 -05:00
|
|
|
|
|
|
|
def depends_on spec
|
|
|
|
dep = dependency_collector.add(spec)
|
|
|
|
build.add_dep_option(dep) if dep
|
|
|
|
end
|
|
|
|
|
|
|
|
def deps
|
|
|
|
dependency_collector.deps
|
|
|
|
end
|
|
|
|
|
|
|
|
def requirements
|
|
|
|
dependency_collector.requirements
|
|
|
|
end
|
2014-03-13 19:51:23 -05:00
|
|
|
|
|
|
|
def patch strip=:p1, io=nil, &block
|
|
|
|
patches << Patch.create(strip, io, &block)
|
|
|
|
end
|
2014-03-13 19:51:23 -05:00
|
|
|
|
|
|
|
def add_legacy_patches(list)
|
|
|
|
list = Patch.normalize_legacy_patches(list)
|
|
|
|
list.each { |p| p.owner = self }
|
|
|
|
patches.concat(list)
|
|
|
|
end
|
2013-09-14 10:16:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class HeadSoftwareSpec < SoftwareSpec
|
2013-09-23 21:39:19 -05:00
|
|
|
def initialize
|
2013-09-14 10:16:52 -05:00
|
|
|
super
|
2013-09-23 21:39:19 -05:00
|
|
|
@resource.version = Version.new('HEAD')
|
2013-09-14 10:16:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def verify_download_integrity fn
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-10 14:56:02 -05:00
|
|
|
class Bottle
|
2014-07-18 15:14:42 -05:00
|
|
|
class Filename
|
|
|
|
attr_reader :name, :version, :tag, :revision
|
|
|
|
|
2014-07-18 15:14:42 -05:00
|
|
|
def self.create(formula, tag, revision)
|
|
|
|
new(formula.name, formula.pkg_version, tag, revision)
|
|
|
|
end
|
|
|
|
|
2014-07-18 15:14:42 -05:00
|
|
|
def initialize(name, version, tag, revision)
|
|
|
|
@name = name
|
|
|
|
@version = version
|
|
|
|
@tag = tag
|
|
|
|
@revision = revision
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
2014-07-18 15:14:42 -05:00
|
|
|
prefix + suffix
|
2014-07-18 15:14:42 -05:00
|
|
|
end
|
|
|
|
alias_method :to_str, :to_s
|
2014-07-18 15:14:42 -05:00
|
|
|
|
|
|
|
def prefix
|
|
|
|
"#{name}-#{version}.#{tag}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def suffix
|
|
|
|
s = revision > 0 ? ".#{revision}" : ""
|
|
|
|
".bottle#{s}.tar.gz"
|
|
|
|
end
|
2014-07-18 15:14:42 -05:00
|
|
|
end
|
|
|
|
|
2014-03-10 14:56:02 -05:00
|
|
|
extend Forwardable
|
|
|
|
|
2014-03-13 10:01:01 -05:00
|
|
|
attr_reader :name, :resource, :prefix, :cellar, :revision
|
2014-03-10 14:56:02 -05:00
|
|
|
|
2014-03-13 13:13:06 +00:00
|
|
|
def_delegators :resource, :url, :fetch, :verify_download_integrity
|
2014-07-22 19:12:26 -05:00
|
|
|
def_delegators :resource, :cached_download, :clear_cache
|
2013-09-14 10:16:52 -05:00
|
|
|
|
2014-07-17 20:44:56 -05:00
|
|
|
def initialize(formula, spec)
|
|
|
|
@name = formula.name
|
2014-03-13 13:13:06 +00:00
|
|
|
@resource = Resource.new
|
2014-07-17 20:44:56 -05:00
|
|
|
@resource.owner = formula
|
2014-04-01 16:03:08 -05:00
|
|
|
|
|
|
|
checksum, tag = spec.checksum_for(bottle_tag)
|
|
|
|
|
2014-07-18 15:14:42 -05:00
|
|
|
filename = Filename.create(formula, tag, spec.revision)
|
2014-07-18 15:14:42 -05:00
|
|
|
@resource.url = build_url(spec.root_url, filename)
|
2014-03-18 15:47:26 -05:00
|
|
|
@resource.download_strategy = CurlBottleDownloadStrategy
|
2014-07-17 20:44:56 -05:00
|
|
|
@resource.version = formula.pkg_version
|
2014-04-01 16:03:08 -05:00
|
|
|
@resource.checksum = checksum
|
2014-03-10 14:56:02 -05:00
|
|
|
@prefix = spec.prefix
|
|
|
|
@cellar = spec.cellar
|
|
|
|
@revision = spec.revision
|
|
|
|
end
|
2014-03-10 14:56:02 -05:00
|
|
|
|
|
|
|
def compatible_cellar?
|
|
|
|
cellar == :any || cellar == HOMEBREW_CELLAR.to_s
|
|
|
|
end
|
2014-07-18 15:14:42 -05:00
|
|
|
|
2014-07-22 19:11:09 -05:00
|
|
|
def stage
|
|
|
|
resource.downloader.stage
|
|
|
|
end
|
|
|
|
|
2014-07-18 15:14:42 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def build_url(root_url, filename)
|
|
|
|
"#{root_url}/#{filename}"
|
|
|
|
end
|
2014-03-10 14:56:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class BottleSpecification
|
2014-05-27 21:14:59 -05:00
|
|
|
DEFAULT_PREFIX = "/usr/local".freeze
|
|
|
|
DEFAULT_CELLAR = "/usr/local/Cellar".freeze
|
|
|
|
DEFAULT_ROOT_URL = "https://downloads.sf.net/project/machomebrew/Bottles".freeze
|
|
|
|
|
2014-03-10 14:56:02 -05:00
|
|
|
attr_rw :root_url, :prefix, :cellar, :revision
|
2014-04-01 16:03:08 -05:00
|
|
|
attr_reader :checksum, :collector
|
2013-09-17 21:25:38 -05:00
|
|
|
|
2013-09-14 10:16:52 -05:00
|
|
|
def initialize
|
|
|
|
@revision = 0
|
2014-05-27 21:14:59 -05:00
|
|
|
@prefix = DEFAULT_PREFIX
|
|
|
|
@cellar = DEFAULT_CELLAR
|
|
|
|
@root_url = DEFAULT_ROOT_URL
|
2014-04-01 16:03:07 -05:00
|
|
|
@collector = BottleCollector.new
|
2013-09-14 10:16:52 -05:00
|
|
|
end
|
|
|
|
|
2014-04-01 16:03:08 -05:00
|
|
|
def tag?(tag)
|
2014-07-16 14:52:18 -05:00
|
|
|
!!checksum_for(tag)
|
2014-03-10 14:56:02 -05:00
|
|
|
end
|
|
|
|
|
2013-09-14 10:16:52 -05:00
|
|
|
# Checksum methods in the DSL's bottle block optionally take
|
|
|
|
# a Hash, which indicates the platform the checksum applies on.
|
|
|
|
Checksum::TYPES.each do |cksum|
|
2014-04-01 16:03:08 -05:00
|
|
|
define_method(cksum) do |val|
|
|
|
|
digest, tag = val.shift
|
2014-07-15 21:55:14 -05:00
|
|
|
collector[tag] = Checksum.new(cksum, digest)
|
2014-04-01 16:03:08 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def checksum_for(tag)
|
2014-07-16 14:52:18 -05:00
|
|
|
collector.fetch_checksum_for(tag)
|
2013-09-14 10:16:52 -05:00
|
|
|
end
|
2013-09-21 21:16:18 +01:00
|
|
|
|
|
|
|
def checksums
|
|
|
|
checksums = {}
|
2014-04-01 16:03:07 -05:00
|
|
|
os_versions = collector.keys
|
|
|
|
os_versions.map! {|osx| MacOS::Version.from_symbol osx rescue nil }.compact!
|
|
|
|
os_versions.sort.reverse_each do |os_version|
|
|
|
|
osx = os_version.to_sym
|
|
|
|
checksum = collector[osx]
|
|
|
|
checksums[checksum.hash_type] ||= []
|
|
|
|
checksums[checksum.hash_type] << { checksum => osx }
|
2013-09-21 21:16:18 +01:00
|
|
|
end
|
|
|
|
checksums
|
|
|
|
end
|
2013-09-14 10:16:52 -05:00
|
|
|
end
|