2015-08-03 13:09:07 +01:00
|
|
|
require "forwardable"
|
|
|
|
require "resource"
|
|
|
|
require "checksum"
|
|
|
|
require "version"
|
|
|
|
require "options"
|
|
|
|
require "build_options"
|
|
|
|
require "dependency_collector"
|
2016-04-25 17:57:51 +01:00
|
|
|
require "utils/bottles"
|
2015-08-03 13:09:07 +01:00
|
|
|
require "patch"
|
|
|
|
require "compilers"
|
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-08-07 10:45:32 -05:00
|
|
|
PREDEFINED_OPTIONS = {
|
|
|
|
:universal => Option.new("universal", "Build a universal binary"),
|
|
|
|
:cxx11 => Option.new("c++11", "Build using C++11 mode"),
|
2015-08-03 13:09:07 +01:00
|
|
|
"32-bit" => Option.new("32-bit", "Build 32-bit only")
|
2014-08-07 10:45:32 -05:00
|
|
|
}
|
|
|
|
|
2015-05-27 22:15:35 +08:00
|
|
|
attr_reader :name, :full_name, :owner
|
2014-07-31 19:37:39 -05:00
|
|
|
attr_reader :build, :resources, :patches, :options
|
2014-10-16 13:00:20 +01:00
|
|
|
attr_reader :deprecated_flags, :deprecated_options
|
2013-09-21 19:27:24 -05:00
|
|
|
attr_reader :dependency_collector
|
2014-03-10 14:56:02 -05:00
|
|
|
attr_reader :bottle_specification
|
2014-08-19 17:14:02 -05:00
|
|
|
attr_reader :compiler_failures
|
2013-09-17 21:25:39 -05:00
|
|
|
|
2016-01-14 19:00:06 +08:00
|
|
|
def_delegators :@resource, :stage, :fetch, :verify_download_integrity, :source_modified_time
|
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
|
2016-07-13 10:11:59 +03:00
|
|
|
def_delegators :@resource, :downloader
|
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
|
|
|
@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 = []
|
2014-07-31 19:37:39 -05:00
|
|
|
@options = Options.new
|
2014-10-16 13:00:20 +01:00
|
|
|
@flags = ARGV.flags_only
|
|
|
|
@deprecated_flags = []
|
|
|
|
@deprecated_options = []
|
|
|
|
@build = BuildOptions.new(Options.create(@flags), options)
|
2014-08-19 17:14:02 -05:00
|
|
|
@compiler_failures = []
|
2013-09-17 21:25:39 -05:00
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def owner=(owner)
|
2013-09-23 21:39:19 -05:00
|
|
|
@name = owner.name
|
2015-05-27 22:15:35 +08:00
|
|
|
@full_name = owner.full_name
|
2015-07-03 21:34:22 +08:00
|
|
|
@bottle_specification.tap = owner.tap
|
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
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def url(val = nil, specs = {})
|
2013-09-28 16:37:05 -05:00
|
|
|
return @resource.url if val.nil?
|
|
|
|
@resource.url(val, specs)
|
|
|
|
dependency_collector.add(@resource)
|
|
|
|
end
|
|
|
|
|
2015-09-14 19:51:04 +08:00
|
|
|
def bottle_unneeded?
|
|
|
|
!!@bottle_disable_reason && @bottle_disable_reason.unneeded?
|
|
|
|
end
|
|
|
|
|
|
|
|
def bottle_disabled?
|
|
|
|
!!@bottle_disable_reason
|
|
|
|
end
|
|
|
|
|
|
|
|
def bottle_disable_reason
|
|
|
|
@bottle_disable_reason
|
|
|
|
end
|
|
|
|
|
2015-11-01 20:33:24 +08:00
|
|
|
def bottle_defined?
|
|
|
|
bottle_specification.collector.keys.any?
|
|
|
|
end
|
|
|
|
|
2014-03-10 14:56:02 -05:00
|
|
|
def bottled?
|
2016-04-25 17:57:51 +01:00
|
|
|
bottle_specification.tag?(Utils::Bottles.tag) && \
|
2015-03-27 23:57:21 +08:00
|
|
|
(bottle_specification.compatible_cellar? || ARGV.force_bottle?)
|
2014-03-10 14:56:02 -05:00
|
|
|
end
|
|
|
|
|
2015-09-14 19:51:04 +08:00
|
|
|
def bottle(disable_type = nil, disable_reason = nil, &block)
|
|
|
|
if disable_type
|
|
|
|
@bottle_disable_reason = BottleDisableReason.new(disable_type, disable_reason)
|
|
|
|
else
|
|
|
|
bottle_specification.instance_eval(&block)
|
|
|
|
end
|
2014-03-10 14:56:02 -05:00
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def resource_defined?(name)
|
|
|
|
resources.key?(name)
|
2013-09-17 21:25:40 -05:00
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def resource(name, klass = Resource, &block)
|
2013-09-17 21:25:39 -05:00
|
|
|
if block_given?
|
2014-07-30 18:56:37 -05:00
|
|
|
raise DuplicateResourceError.new(name) if resource_defined?(name)
|
2014-06-02 23:32:42 -07:00
|
|
|
res = klass.new(name, &block)
|
2014-03-14 23:42:53 -05:00
|
|
|
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
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def go_resource(name, &block)
|
2015-04-02 21:43:28 -07:00
|
|
|
resource name, Resource::Go, &block
|
|
|
|
end
|
|
|
|
|
2014-07-31 19:37:39 -05:00
|
|
|
def option_defined?(name)
|
|
|
|
options.include?(name)
|
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def option(name, description = "")
|
2014-08-07 10:45:32 -05:00
|
|
|
opt = PREDEFINED_OPTIONS.fetch(name) do
|
|
|
|
if Symbol === name
|
|
|
|
opoo "Passing arbitrary symbols to `option` is deprecated: #{name.inspect}"
|
|
|
|
puts "Symbols are reserved for future use, please pass a string instead"
|
|
|
|
name = name.to_s
|
2014-08-07 10:45:32 -05:00
|
|
|
end
|
2016-04-20 02:17:28 -04:00
|
|
|
unless String === name
|
|
|
|
raise ArgumentError, "option name must be string or symbol; got a #{name.class}: #{name}"
|
|
|
|
end
|
2014-08-07 10:45:32 -05:00
|
|
|
raise ArgumentError, "option name is required" if name.empty?
|
2016-04-20 02:17:28 -04:00
|
|
|
raise ArgumentError, "option name must be longer than one character: #{name}" unless name.length > 1
|
|
|
|
raise ArgumentError, "option name must not start with dashes: #{name}" if name.start_with?("-")
|
2014-08-07 10:45:32 -05:00
|
|
|
Option.new(name, description)
|
|
|
|
end
|
|
|
|
options << opt
|
2013-09-21 19:27:24 -05:00
|
|
|
end
|
2013-09-21 19:27:24 -05:00
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def deprecated_option(hash)
|
2014-10-16 13:00:20 +01:00
|
|
|
raise ArgumentError, "deprecated_option hash must not be empty" if hash.empty?
|
|
|
|
hash.each do |old_options, new_options|
|
|
|
|
Array(old_options).each do |old_option|
|
|
|
|
Array(new_options).each do |new_option|
|
|
|
|
deprecated_option = DeprecatedOption.new(old_option, new_option)
|
|
|
|
deprecated_options << deprecated_option
|
|
|
|
|
|
|
|
old_flag = deprecated_option.old_flag
|
|
|
|
new_flag = deprecated_option.current_flag
|
2014-10-16 13:01:05 +01:00
|
|
|
if @flags.include? old_flag
|
|
|
|
@flags -= [old_flag]
|
|
|
|
@flags |= [new_flag]
|
|
|
|
@deprecated_flags << deprecated_option
|
|
|
|
end
|
2014-10-16 13:00:20 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@build = BuildOptions.new(Options.create(@flags), options)
|
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def depends_on(spec)
|
2013-09-21 19:27:24 -05:00
|
|
|
dep = dependency_collector.add(spec)
|
2014-07-31 19:37:39 -05:00
|
|
|
add_dep_option(dep) if dep
|
2013-09-21 19:27:24 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def deps
|
|
|
|
dependency_collector.deps
|
|
|
|
end
|
|
|
|
|
|
|
|
def requirements
|
|
|
|
dependency_collector.requirements
|
|
|
|
end
|
2014-03-13 19:51:23 -05:00
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def patch(strip = :p1, src = nil, &block)
|
2016-03-22 15:19:33 +08:00
|
|
|
p = Patch.create(strip, src, &block)
|
|
|
|
dependency_collector.add(p.resource) if p.is_a? ExternalPatch
|
|
|
|
patches << p
|
2014-03-13 19:51:23 -05:00
|
|
|
end
|
2014-03-13 19:51:23 -05:00
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def fails_with(compiler, &block)
|
2014-08-19 17:14:02 -05:00
|
|
|
compiler_failures << CompilerFailure.create(compiler, &block)
|
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def needs(*standards)
|
2014-08-19 17:14:02 -05:00
|
|
|
standards.each do |standard|
|
|
|
|
compiler_failures.concat CompilerFailure.for_standard(standard)
|
|
|
|
end
|
|
|
|
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
|
2014-07-31 19:37:39 -05:00
|
|
|
|
|
|
|
def add_dep_option(dep)
|
2015-12-14 19:47:19 +00:00
|
|
|
dep.option_names.each do |name|
|
|
|
|
if dep.optional? && !option_defined?("with-#{name}")
|
|
|
|
options << Option.new("with-#{name}", "Build with #{name} support")
|
|
|
|
elsif dep.recommended? && !option_defined?("without-#{name}")
|
|
|
|
options << Option.new("without-#{name}", "Build without #{name} support")
|
|
|
|
end
|
2014-07-31 19:37:39 -05:00
|
|
|
end
|
|
|
|
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
|
2016-07-11 16:09:35 +03:00
|
|
|
@resource.version = Version.create("HEAD")
|
2013-09-14 10:16:52 -05:00
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def verify_download_integrity(_fn)
|
|
|
|
nil
|
2013-09-14 10:16:52 -05:00
|
|
|
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
|
2015-03-17 09:03:13 +00:00
|
|
|
@spec = spec
|
2014-04-01 16:03:08 -05:00
|
|
|
|
2016-04-25 17:57:51 +01:00
|
|
|
checksum, tag = spec.checksum_for(Utils::Bottles.tag)
|
2014-04-01 16:03:08 -05:00
|
|
|
|
2014-07-18 15:14:42 -05:00
|
|
|
filename = Filename.create(formula, tag, spec.revision)
|
2015-01-08 14:18:41 -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?
|
2015-03-17 09:03:13 +00:00
|
|
|
@spec.compatible_cellar?
|
2014-03-10 14:56:02 -05:00
|
|
|
end
|
2014-07-18 15:14:42 -05:00
|
|
|
|
2015-08-12 14:57:54 -04:00
|
|
|
# Does the bottle need to be relocated?
|
2015-07-26 16:49:16 -04:00
|
|
|
def skip_relocation?
|
|
|
|
@spec.skip_relocation?
|
2015-05-25 23:32:55 -04:00
|
|
|
end
|
|
|
|
|
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
|
2015-07-03 22:59:30 +08:00
|
|
|
DEFAULT_DOMAIN = (ENV["HOMEBREW_BOTTLE_DOMAIN"] || "https://homebrew.bintray.com").freeze
|
2014-05-27 21:14:59 -05:00
|
|
|
|
2015-07-03 21:34:22 +08:00
|
|
|
attr_rw :prefix, :cellar, :revision
|
|
|
|
attr_accessor :tap
|
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
|
2016-04-25 17:57:51 +01:00
|
|
|
@collector = Utils::Bottles::Collector.new
|
2013-09-14 10:16:52 -05:00
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def root_url(var = nil)
|
2015-07-03 21:34:22 +08:00
|
|
|
if var.nil?
|
2016-04-25 17:57:51 +01:00
|
|
|
@root_url ||= "#{DEFAULT_DOMAIN}/#{Utils::Bottles::Bintray.repository(tap)}"
|
2015-07-03 21:34:22 +08:00
|
|
|
else
|
|
|
|
@root_url = var
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-17 09:03:13 +00:00
|
|
|
def compatible_cellar?
|
2015-07-26 16:49:16 -04:00
|
|
|
cellar == :any || cellar == :any_skip_relocation || cellar == HOMEBREW_CELLAR.to_s
|
2015-03-17 09:03:13 +00:00
|
|
|
end
|
|
|
|
|
2015-08-12 14:57:54 -04:00
|
|
|
# Does the Bottle this BottleSpecification belongs to need to be relocated?
|
2015-07-26 16:49:16 -04:00
|
|
|
def skip_relocation?
|
|
|
|
cellar == :any_skip_relocation
|
2015-05-25 23:32:55 -04: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
|
2015-08-03 13:09:07 +01:00
|
|
|
os_versions.map! { |osx| MacOS::Version.from_symbol osx rescue nil }.compact!
|
2014-04-01 16:03:07 -05:00
|
|
|
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
|
2016-02-14 19:56:48 +00:00
|
|
|
|
|
|
|
class PourBottleCheck
|
|
|
|
def initialize(formula)
|
|
|
|
@formula = formula
|
|
|
|
end
|
|
|
|
|
|
|
|
def reason(reason)
|
2016-01-09 11:06:17 +00:00
|
|
|
@formula.pour_bottle_check_unsatisfied_reason = reason
|
2016-02-14 19:56:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def satisfy(&block)
|
|
|
|
@formula.send(:define_method, :pour_bottle?, &block)
|
|
|
|
end
|
|
|
|
end
|