2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
require "resource"
|
2021-02-26 11:23:33 +00:00
|
|
|
require "download_strategy"
|
2015-08-03 13:09:07 +01:00
|
|
|
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"
|
2017-04-25 14:34:27 +01:00
|
|
|
require "os/mac/version"
|
2020-12-08 08:43:11 -08:00
|
|
|
require "extend/on_os"
|
2013-09-14 10:16:52 -05:00
|
|
|
|
|
|
|
class SoftwareSpec
|
2020-10-20 12:03:48 +02:00
|
|
|
extend T::Sig
|
|
|
|
|
2013-09-17 21:25:38 -05:00
|
|
|
extend Forwardable
|
2020-12-08 08:47:08 -08:00
|
|
|
include OnOS
|
2013-09-14 10:16:52 -05:00
|
|
|
|
2014-08-07 10:45:32 -05:00
|
|
|
PREDEFINED_OPTIONS = {
|
2016-12-20 10:22:30 +00:00
|
|
|
universal: Option.new("universal", "Build a universal binary"),
|
|
|
|
cxx11: Option.new("c++11", "Build using C++11 mode"),
|
2016-09-17 15:17:27 +01:00
|
|
|
}.freeze
|
2014-08-07 10:45:32 -05:00
|
|
|
|
2020-07-07 11:29:33 +01:00
|
|
|
attr_reader :name, :full_name, :owner, :build, :resources, :patches, :options, :deprecated_flags,
|
|
|
|
:deprecated_options, :dependency_collector, :bottle_specification, :compiler_failures,
|
|
|
|
:uses_from_macos_elements, :bottle_disable_reason
|
2013-09-17 21:25:39 -05:00
|
|
|
|
2020-07-07 11:29:33 +01:00
|
|
|
def_delegators :@resource, :stage, :fetch, :verify_download_integrity, :source_modified_time, :download_name,
|
|
|
|
:cached_download, :clear_cache, :checksum, :mirrors, :specs, :using, :version, :mirror,
|
2020-11-24 15:46:47 +01:00
|
|
|
:downloader
|
|
|
|
|
2021-01-07 08:33:57 +01:00
|
|
|
def_delegators :@resource, :sha256
|
2013-09-14 10:16:52 -05:00
|
|
|
|
2020-07-26 07:24:14 +02:00
|
|
|
def initialize(flags: [])
|
2013-09-23 21:39:19 -05:00
|
|
|
@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
|
2020-07-26 07:24:14 +02:00
|
|
|
@flags = flags
|
2014-10-16 13:00:20 +01:00
|
|
|
@deprecated_flags = []
|
|
|
|
@deprecated_options = []
|
|
|
|
@build = BuildOptions.new(Options.create(@flags), options)
|
2014-08-19 17:14:02 -05:00
|
|
|
@compiler_failures = []
|
2018-04-07 20:28:56 +01:00
|
|
|
@bottle_disable_reason = nil
|
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|
|
2017-08-07 10:12:52 +01:00
|
|
|
r.owner = self
|
|
|
|
r.version ||= begin
|
2019-02-19 13:11:32 +00:00
|
|
|
raise "#{full_name}: version missing for \"#{r.name}\" resource!" if version.nil?
|
2017-08-07 10:12:52 +01:00
|
|
|
|
|
|
|
if version.head?
|
|
|
|
Version.create("HEAD")
|
|
|
|
else
|
|
|
|
version.dup
|
|
|
|
end
|
|
|
|
end
|
2013-11-26 18:47:41 -06:00
|
|
|
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?
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2013-09-28 16:37:05 -05:00
|
|
|
@resource.url(val, specs)
|
|
|
|
dependency_collector.add(@resource)
|
|
|
|
end
|
|
|
|
|
2015-09-14 19:51:04 +08:00
|
|
|
def bottle_unneeded?
|
2016-09-20 22:24:31 +02:00
|
|
|
return false unless @bottle_disable_reason
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2016-09-20 22:24:31 +02:00
|
|
|
@bottle_disable_reason.unneeded?
|
2015-09-14 19:51:04 +08:00
|
|
|
end
|
|
|
|
|
2020-10-20 12:03:48 +02:00
|
|
|
sig { returns(T::Boolean) }
|
2015-09-14 19:51:04 +08:00
|
|
|
def bottle_disabled?
|
2016-09-20 22:24:31 +02:00
|
|
|
@bottle_disable_reason ? true : false
|
2015-09-14 19:51:04 +08:00
|
|
|
end
|
|
|
|
|
2015-11-01 20:33:24 +08:00
|
|
|
def bottle_defined?
|
2016-08-05 22:01:32 +08:00
|
|
|
!bottle_specification.collector.keys.empty?
|
2015-11-01 20:33:24 +08:00
|
|
|
end
|
|
|
|
|
2020-12-09 13:53:10 +00:00
|
|
|
def bottle_tag?
|
|
|
|
bottle_specification.tag?(Utils::Bottles.tag)
|
|
|
|
end
|
|
|
|
|
2014-03-10 14:56:02 -05:00
|
|
|
def bottled?
|
2020-12-09 13:53:10 +00:00
|
|
|
bottle_tag? && \
|
|
|
|
(bottle_specification.compatible_locations? || owner.force_bottle)
|
2014-03-10 14:56:02 -05:00
|
|
|
end
|
|
|
|
|
2016-09-17 15:17:27 +01:00
|
|
|
def bottle(disable_type = nil, disable_reason = nil, &block)
|
2015-09-14 19:51:04 +08:00
|
|
|
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)
|
2020-11-16 22:18:56 +01:00
|
|
|
if block
|
2016-09-17 15:17:27 +01:00
|
|
|
raise DuplicateResourceError, name if resource_defined?(name)
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2014-06-02 23:32:42 -07:00
|
|
|
res = klass.new(name, &block)
|
2020-06-25 22:24:46 +02:00
|
|
|
return unless res.url
|
|
|
|
|
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
|
2016-09-20 22:03:08 +02:00
|
|
|
unless name.is_a?(String)
|
2016-04-20 02:17:28 -04:00
|
|
|
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?("-")
|
2018-09-17 02:45:00 +02:00
|
|
|
|
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?
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2014-10-16 13:00:20 +01:00
|
|
|
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
|
2016-09-17 15:17:27 +01:00
|
|
|
next unless @flags.include? old_flag
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2016-09-17 15:17:27 +01:00
|
|
|
@flags -= [old_flag]
|
|
|
|
@flags |= [new_flag]
|
|
|
|
@deprecated_flags << deprecated_option
|
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
|
|
|
|
|
2020-04-28 14:17:54 +01:00
|
|
|
def uses_from_macos(spec, _bounds = {})
|
2021-02-16 09:25:34 +00:00
|
|
|
spec = spec.dup.shift if spec.is_a?(Hash)
|
2019-12-19 14:36:33 +00:00
|
|
|
depends_on(spec)
|
2019-05-24 21:36:48 -03:00
|
|
|
end
|
|
|
|
|
2013-09-21 19:27:24 -05:00
|
|
|
def deps
|
|
|
|
dependency_collector.deps
|
|
|
|
end
|
|
|
|
|
2017-06-25 03:38:21 -07:00
|
|
|
def recursive_dependencies
|
2017-07-02 05:39:02 -07:00
|
|
|
deps_f = []
|
|
|
|
recursive_dependencies = deps.map do |dep|
|
2019-10-13 10:03:26 +01:00
|
|
|
deps_f << dep.to_formula
|
|
|
|
dep
|
|
|
|
rescue TapFormulaUnavailableError
|
|
|
|
# Don't complain about missing cross-tap dependencies
|
|
|
|
next
|
2017-07-02 05:39:02 -07:00
|
|
|
end.compact.uniq
|
|
|
|
deps_f.compact.each do |f|
|
2017-06-25 03:38:21 -07:00
|
|
|
f.recursive_dependencies.each do |dep|
|
|
|
|
recursive_dependencies << dep unless recursive_dependencies.include?(dep)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
recursive_dependencies
|
|
|
|
end
|
|
|
|
|
2013-09-21 19:27:24 -05:00
|
|
|
def requirements
|
|
|
|
dependency_collector.requirements
|
|
|
|
end
|
2014-03-13 19:51:23 -05:00
|
|
|
|
2017-06-25 03:38:21 -07:00
|
|
|
def recursive_requirements
|
|
|
|
Requirement.expand(self)
|
|
|
|
end
|
|
|
|
|
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-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
|
2020-07-26 07:24:14 +02:00
|
|
|
def initialize(flags: [])
|
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
|
|
|
|
|
2020-08-02 14:32:31 +02:00
|
|
|
def verify_download_integrity(_fn)
|
2020-08-02 06:05:53 +02:00
|
|
|
# no-op
|
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
|
2020-10-20 12:03:48 +02:00
|
|
|
extend T::Sig
|
|
|
|
|
2016-08-18 17:32:35 +01:00
|
|
|
attr_reader :name, :version, :tag, :rebuild
|
2014-07-18 15:14:42 -05:00
|
|
|
|
2016-08-18 17:32:35 +01:00
|
|
|
def self.create(formula, tag, rebuild)
|
|
|
|
new(formula.name, formula.pkg_version, tag, rebuild)
|
2014-07-18 15:14:42 -05:00
|
|
|
end
|
|
|
|
|
2016-08-18 17:32:35 +01:00
|
|
|
def initialize(name, version, tag, rebuild)
|
2018-08-08 11:42:32 -07:00
|
|
|
@name = File.basename name
|
2014-07-18 15:14:42 -05:00
|
|
|
@version = version
|
2019-11-06 14:31:03 +00:00
|
|
|
@tag = tag.to_s
|
2016-08-18 17:32:35 +01:00
|
|
|
@rebuild = rebuild
|
2014-07-18 15:14:42 -05:00
|
|
|
end
|
|
|
|
|
2020-10-20 12:03:48 +02:00
|
|
|
sig { returns(String) }
|
2014-07-18 15:14:42 -05:00
|
|
|
def to_s
|
2018-08-06 15:02:52 +02:00
|
|
|
"#{name}--#{version}#{extname}"
|
2014-07-18 15:14:42 -05:00
|
|
|
end
|
2016-09-23 18:13:48 +02:00
|
|
|
alias to_str to_s
|
2014-07-18 15:14:42 -05:00
|
|
|
|
2020-10-20 12:03:48 +02:00
|
|
|
sig { returns(String) }
|
2018-08-06 15:02:52 +02:00
|
|
|
def json
|
|
|
|
"#{name}--#{version}.#{tag}.bottle.json"
|
2014-07-18 15:14:42 -05:00
|
|
|
end
|
|
|
|
|
2021-04-12 14:48:58 +01:00
|
|
|
def url_encode
|
2020-05-10 00:30:32 +01:00
|
|
|
ERB::Util.url_encode("#{name}-#{version}#{extname}")
|
2018-08-06 15:02:52 +02:00
|
|
|
end
|
|
|
|
|
2021-04-09 16:31:04 +01:00
|
|
|
def github_packages
|
|
|
|
"#{name}--#{version}#{extname}"
|
|
|
|
end
|
|
|
|
|
2020-10-20 12:03:48 +02:00
|
|
|
sig { returns(String) }
|
2018-08-06 15:02:52 +02:00
|
|
|
def extname
|
2017-09-24 20:12:58 +01:00
|
|
|
s = rebuild.positive? ? ".#{rebuild}" : ""
|
2018-08-06 15:02:52 +02:00
|
|
|
".#{tag}.bottle#{s}.tar.gz"
|
2014-07-18 15:14:42 -05:00
|
|
|
end
|
2014-07-18 15:14:42 -05:00
|
|
|
end
|
|
|
|
|
2014-03-10 14:56:02 -05:00
|
|
|
extend Forwardable
|
|
|
|
|
2016-08-18 17:32:35 +01:00
|
|
|
attr_reader :name, :resource, :prefix, :cellar, :rebuild
|
2014-03-10 14:56:02 -05:00
|
|
|
|
2021-02-26 11:23:33 +00:00
|
|
|
def_delegators :resource, :url, :verify_download_integrity
|
2021-04-02 12:44:07 +01:00
|
|
|
def_delegators :resource, :cached_download
|
2013-09-14 10:16:52 -05:00
|
|
|
|
2021-07-10 21:17:33 +02:00
|
|
|
def initialize(formula, spec, tag = nil)
|
2014-07-17 20:44:56 -05:00
|
|
|
@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
|
2018-03-24 10:53:49 +00:00
|
|
|
@resource.specs[:bottle] = true
|
2015-03-17 09:03:13 +00:00
|
|
|
@spec = spec
|
2014-04-01 16:03:08 -05:00
|
|
|
|
2021-07-10 21:17:33 +02:00
|
|
|
bottle_tag = if tag.present?
|
|
|
|
Utils::Bottles::Tag.from_symbol(tag)
|
|
|
|
else
|
|
|
|
Utils::Bottles.tag
|
|
|
|
end
|
|
|
|
checksum, tag, cellar = spec.checksum_for(bottle_tag)
|
2014-04-01 16:03:08 -05:00
|
|
|
|
2014-03-10 14:56:02 -05:00
|
|
|
@prefix = spec.prefix
|
2021-04-15 18:06:54 +01:00
|
|
|
@tag = tag
|
2020-11-29 17:51:47 +01:00
|
|
|
@cellar = cellar
|
2016-08-18 17:32:35 +01:00
|
|
|
@rebuild = spec.rebuild
|
2021-04-15 18:06:54 +01:00
|
|
|
|
|
|
|
@resource.version = formula.pkg_version
|
|
|
|
@resource.checksum = checksum
|
|
|
|
|
|
|
|
root_url(spec.root_url, spec.root_url_specs)
|
2014-03-10 14:56:02 -05:00
|
|
|
end
|
2014-03-10 14:56:02 -05:00
|
|
|
|
2021-02-26 11:23:33 +00:00
|
|
|
def fetch(verify_download_integrity: true)
|
|
|
|
@resource.fetch(verify_download_integrity: verify_download_integrity)
|
2021-04-15 18:06:54 +01:00
|
|
|
rescue DownloadError
|
|
|
|
raise unless fallback_on_error
|
|
|
|
|
|
|
|
fetch_tab
|
|
|
|
retry
|
2021-02-26 11:23:33 +00:00
|
|
|
end
|
|
|
|
|
2021-04-02 12:44:07 +01:00
|
|
|
def clear_cache
|
|
|
|
@resource.clear_cache
|
|
|
|
github_packages_manifest_resource&.clear_cache
|
|
|
|
end
|
|
|
|
|
2020-12-09 13:53:10 +00:00
|
|
|
def compatible_locations?
|
|
|
|
@spec.compatible_locations?
|
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
|
|
|
|
|
2021-03-31 20:55:35 +01:00
|
|
|
def fetch_tab
|
2021-05-19 13:15:33 +01:00
|
|
|
return if github_packages_manifest_resource.blank?
|
|
|
|
|
2021-03-31 20:55:35 +01:00
|
|
|
# a checksum is used later identifying the correct tab but we do not have the checksum for the manifest/tab
|
2021-05-19 13:15:33 +01:00
|
|
|
github_packages_manifest_resource.fetch(verify_download_integrity: false)
|
|
|
|
|
|
|
|
begin
|
|
|
|
JSON.parse(github_packages_manifest_resource.cached_download.read)
|
|
|
|
rescue JSON::ParserError
|
|
|
|
raise DownloadError.new(
|
|
|
|
github_packages_manifest_resource,
|
|
|
|
RuntimeError.new("The downloaded GitHub Packages manifest was corrupted or modified (it is not valid JSON):"\
|
|
|
|
"\n#{github_packages_manifest_resource.cached_download}"),
|
|
|
|
)
|
|
|
|
end
|
2021-04-15 18:06:54 +01:00
|
|
|
rescue DownloadError
|
|
|
|
raise unless fallback_on_error
|
|
|
|
|
|
|
|
retry
|
2021-03-31 20:55:35 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def tab_attributes
|
|
|
|
return {} unless github_packages_manifest_resource&.downloaded?
|
|
|
|
|
|
|
|
manifest_json = github_packages_manifest_resource.cached_download.read
|
|
|
|
|
|
|
|
json = begin
|
|
|
|
JSON.parse(manifest_json)
|
|
|
|
rescue JSON::ParserError
|
2021-05-19 13:15:33 +01:00
|
|
|
raise "The downloaded GitHub Packages manifest was corrupted or modified (it is not valid JSON): "\
|
|
|
|
"\n#{github_packages_manifest_resource.cached_download}"
|
2021-03-31 20:55:35 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
manifests = json["manifests"]
|
|
|
|
raise ArgumentError, "Missing 'manifests' section." if manifests.blank?
|
|
|
|
|
|
|
|
manifests_annotations = manifests.map { |m| m["annotations"] }
|
|
|
|
raise ArgumentError, "Missing 'annotations' section." if manifests_annotations.blank?
|
|
|
|
|
2021-04-02 10:13:27 +01:00
|
|
|
bottle_digest = @resource.checksum.hexdigest
|
2021-05-31 16:06:27 +01:00
|
|
|
image_ref = GitHubPackages.version_rebuild(@resource.version, rebuild, @tag.to_s)
|
2021-03-31 20:55:35 +01:00
|
|
|
manifest_annotations = manifests_annotations.find do |m|
|
2021-05-31 16:06:27 +01:00
|
|
|
next if m["sh.brew.bottle.digest"] != bottle_digest
|
|
|
|
|
|
|
|
m["org.opencontainers.image.ref.name"] == image_ref
|
2021-03-31 20:55:35 +01:00
|
|
|
end
|
|
|
|
raise ArgumentError, "Couldn't find manifest matching bottle checksum." if manifest_annotations.blank?
|
|
|
|
|
|
|
|
tab = manifest_annotations["sh.brew.tab"]
|
|
|
|
raise ArgumentError, "Couldn't find tab from manifest." if tab.blank?
|
|
|
|
|
|
|
|
begin
|
|
|
|
JSON.parse(tab)
|
|
|
|
rescue JSON::ParserError
|
|
|
|
raise ArgumentError, "Couldn't parse tab JSON."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-18 15:14:42 -05:00
|
|
|
private
|
|
|
|
|
2021-03-31 20:55:35 +01:00
|
|
|
def github_packages_manifest_resource
|
|
|
|
return if @resource.download_strategy != CurlGitHubPackagesDownloadStrategy
|
|
|
|
|
|
|
|
@github_packages_manifest_resource ||= begin
|
|
|
|
resource = Resource.new("#{name}_bottle_manifest")
|
|
|
|
|
|
|
|
version_rebuild = GitHubPackages.version_rebuild(@resource.version, rebuild)
|
|
|
|
resource.version(version_rebuild)
|
|
|
|
|
2021-04-06 19:13:30 +01:00
|
|
|
image_name = GitHubPackages.image_formula_name(@name)
|
2021-04-07 13:31:41 +01:00
|
|
|
image_tag = GitHubPackages.image_version_rebuild(version_rebuild)
|
2021-04-15 18:06:54 +01:00
|
|
|
resource.url("#{root_url}/#{image_name}/manifests/#{image_tag}", {
|
2021-04-05 14:58:17 +01:00
|
|
|
using: CurlGitHubPackagesDownloadStrategy,
|
|
|
|
headers: ["Accept: application/vnd.oci.image.index.v1+json"],
|
|
|
|
})
|
2021-03-31 20:55:35 +01:00
|
|
|
resource.downloader.resolved_basename = "#{name}-#{version_rebuild}.bottle_manifest.json"
|
|
|
|
resource
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-24 10:53:49 +00:00
|
|
|
def select_download_strategy(specs)
|
2021-04-15 18:06:54 +01:00
|
|
|
specs[:using] ||= DownloadStrategyDetector.detect(@root_url)
|
2018-03-24 10:53:49 +00:00
|
|
|
specs
|
|
|
|
end
|
2021-04-15 18:06:54 +01:00
|
|
|
|
|
|
|
def fallback_on_error
|
|
|
|
# Use the default bottle domain as a fallback mirror
|
|
|
|
if @resource.url.start_with?(Homebrew::EnvConfig.bottle_domain) &&
|
|
|
|
Homebrew::EnvConfig.bottle_domain != HOMEBREW_BOTTLE_DEFAULT_DOMAIN
|
|
|
|
opoo "Bottle missing, falling back to the default domain..."
|
|
|
|
root_url(HOMEBREW_BOTTLE_DEFAULT_DOMAIN)
|
|
|
|
@github_packages_manifest_resource = nil
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def root_url(val = nil, specs = {})
|
|
|
|
return @root_url if val.nil?
|
|
|
|
|
|
|
|
@root_url = val
|
|
|
|
|
|
|
|
filename = Filename.create(resource.owner, @tag, @spec.rebuild)
|
|
|
|
path, resolved_basename = Utils::Bottles.path_resolved_basename(val, name, resource.checksum, filename)
|
|
|
|
@resource.url("#{val}/#{path}", select_download_strategy(specs))
|
|
|
|
@resource.downloader.resolved_basename = resolved_basename if resolved_basename.present?
|
|
|
|
end
|
2014-03-10 14:56:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class BottleSpecification
|
2020-10-20 12:03:48 +02:00
|
|
|
extend T::Sig
|
|
|
|
|
2021-04-09 09:30:36 +01:00
|
|
|
attr_rw :rebuild
|
2015-07-03 21:34:22 +08:00
|
|
|
attr_accessor :tap
|
2021-04-09 14:06:21 +01:00
|
|
|
attr_reader :all_tags_cellar, :collector, :root_url_specs, :repository, :prefix
|
2013-09-17 21:25:38 -05:00
|
|
|
|
2020-10-20 12:03:48 +02:00
|
|
|
sig { void }
|
2013-09-14 10:16:52 -05:00
|
|
|
def initialize
|
2016-08-18 17:32:35 +01:00
|
|
|
@rebuild = 0
|
2018-09-11 14:16:27 -07:00
|
|
|
@prefix = Homebrew::DEFAULT_PREFIX
|
2020-12-09 13:53:10 +00:00
|
|
|
@repository = Homebrew::DEFAULT_REPOSITORY
|
2016-04-25 17:57:51 +01:00
|
|
|
@collector = Utils::Bottles::Collector.new
|
2018-03-24 10:53:49 +00:00
|
|
|
@root_url_specs = {}
|
2013-09-14 10:16:52 -05:00
|
|
|
end
|
|
|
|
|
2018-03-24 10:53:49 +00:00
|
|
|
def root_url(var = nil, specs = {})
|
2015-07-03 21:34:22 +08:00
|
|
|
if var.nil?
|
2021-04-08 10:54:28 +01:00
|
|
|
@root_url ||= if (github_packages_url = GitHubPackages.root_url_if_match(Homebrew::EnvConfig.bottle_domain))
|
|
|
|
github_packages_url
|
2021-04-12 14:48:58 +01:00
|
|
|
else
|
|
|
|
Homebrew::EnvConfig.bottle_domain
|
2021-03-16 15:17:42 +00:00
|
|
|
end
|
2015-07-03 21:34:22 +08:00
|
|
|
else
|
2021-04-08 10:54:28 +01:00
|
|
|
@root_url = if (github_packages_url = GitHubPackages.root_url_if_match(var))
|
|
|
|
github_packages_url
|
2021-04-04 01:04:54 -07:00
|
|
|
else
|
|
|
|
var
|
|
|
|
end
|
2018-03-24 10:53:49 +00:00
|
|
|
@root_url_specs.merge!(specs)
|
2015-07-03 21:34:22 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-29 17:51:47 +01:00
|
|
|
def cellar(val = nil)
|
2021-04-09 09:30:36 +01:00
|
|
|
if val.present?
|
2021-06-17 11:34:31 +01:00
|
|
|
odisabled(
|
2021-04-09 09:30:36 +01:00
|
|
|
"`cellar` in a bottle block",
|
|
|
|
"`brew style --fix` on the formula to update the style or use `sha256` with a `cellar:` argument",
|
|
|
|
)
|
|
|
|
end
|
2021-02-06 14:27:03 -05:00
|
|
|
|
2021-04-08 13:45:15 +01:00
|
|
|
if val.nil?
|
|
|
|
return collector.dig(Utils::Bottles.tag.to_sym, :cellar) || @all_tags_cellar || Homebrew::DEFAULT_CELLAR
|
|
|
|
end
|
2020-11-29 17:51:47 +01:00
|
|
|
|
|
|
|
@all_tags_cellar = val
|
|
|
|
end
|
|
|
|
|
2020-12-09 13:53:10 +00:00
|
|
|
def compatible_locations?
|
2020-12-15 11:32:10 +00:00
|
|
|
# this looks like it should check prefix and repository too but to be
|
|
|
|
# `cellar :any` actually requires no references to the cellar, prefix or
|
|
|
|
# repository.
|
|
|
|
return true if [:any, :any_skip_relocation].include?(cellar)
|
2020-12-09 13:53:10 +00:00
|
|
|
|
2020-12-15 11:32:10 +00:00
|
|
|
compatible_cellar = cellar == HOMEBREW_CELLAR.to_s
|
2020-12-09 13:53:10 +00:00
|
|
|
compatible_prefix = prefix == HOMEBREW_PREFIX.to_s
|
|
|
|
|
2021-01-27 00:29:43 +09:00
|
|
|
compatible_cellar && compatible_prefix
|
2015-03-17 09:03:13 +00:00
|
|
|
end
|
|
|
|
|
2020-11-05 17:17:03 -05:00
|
|
|
# Does the {Bottle} this {BottleSpecification} belongs to need to be relocated?
|
2020-10-20 12:03:48 +02:00
|
|
|
sig { returns(T::Boolean) }
|
2015-07-26 16:49:16 -04:00
|
|
|
def skip_relocation?
|
|
|
|
cellar == :any_skip_relocation
|
2015-05-25 23:32:55 -04:00
|
|
|
end
|
|
|
|
|
2021-04-08 14:58:39 +01:00
|
|
|
sig { params(tag: T.any(Symbol, Utils::Bottles::Tag), no_older_versions: T::Boolean).returns(T::Boolean) }
|
|
|
|
def tag?(tag, no_older_versions: false)
|
|
|
|
checksum_for(tag, no_older_versions: no_older_versions) ? true : false
|
2014-03-10 14:56:02 -05:00
|
|
|
end
|
|
|
|
|
2020-11-29 17:51:47 +01:00
|
|
|
# Checksum methods in the DSL's bottle block take
|
2013-09-14 10:16:52 -05:00
|
|
|
# a Hash, which indicates the platform the checksum applies on.
|
2020-11-29 17:51:47 +01:00
|
|
|
# Example bottle block syntax:
|
|
|
|
# bottle do
|
2021-01-28 12:26:57 +00:00
|
|
|
# sha256 cellar: :any_skip_relocation, big_sur: "69489ae397e4645..."
|
|
|
|
# sha256 cellar: :any, catalina: "449de5ea35d0e94..."
|
2020-11-29 17:51:47 +01:00
|
|
|
# end
|
|
|
|
def sha256(hash)
|
|
|
|
sha256_regex = /^[a-f0-9]{64}$/i
|
2021-01-28 12:26:57 +00:00
|
|
|
|
|
|
|
# find new `sha256 big_sur: "69489ae397e4645..."` format
|
|
|
|
tag, digest = hash.find do |key, value|
|
|
|
|
key.is_a?(Symbol) && value.is_a?(String) && value.match?(sha256_regex)
|
|
|
|
end
|
|
|
|
|
|
|
|
if digest && tag
|
|
|
|
# the cellar hash key only exists on the new format
|
|
|
|
cellar = hash[:cellar]
|
|
|
|
else
|
|
|
|
# otherwise, find old `sha256 "69489ae397e4645..." => :big_sur` format
|
|
|
|
digest, tag = hash.find do |key, value|
|
|
|
|
key.is_a?(String) && value.is_a?(Symbol) && key.match?(sha256_regex)
|
|
|
|
end
|
2021-02-06 14:27:03 -05:00
|
|
|
|
2021-04-09 09:30:36 +01:00
|
|
|
if digest && tag
|
2021-06-17 11:34:31 +01:00
|
|
|
odisabled(
|
2021-04-09 09:30:36 +01:00
|
|
|
'`sha256 "digest" => :tag` in a bottle block',
|
|
|
|
'`brew style --fix` on the formula to update the style or use `sha256 tag: "digest"`',
|
|
|
|
)
|
|
|
|
end
|
2020-11-29 17:51:47 +01:00
|
|
|
end
|
2021-01-28 12:26:57 +00:00
|
|
|
|
2021-04-08 13:45:15 +01:00
|
|
|
tag = Utils::Bottles::Tag.from_symbol(tag)
|
|
|
|
|
2021-01-28 12:26:57 +00:00
|
|
|
cellar ||= all_tags_cellar
|
2021-04-08 13:45:15 +01:00
|
|
|
cellar ||= tag.default_cellar
|
2021-04-08 01:56:05 +01:00
|
|
|
|
2021-04-08 13:45:15 +01:00
|
|
|
collector[tag.to_sym] = { checksum: Checksum.new(digest), cellar: cellar }
|
2014-04-01 16:03:08 -05:00
|
|
|
end
|
|
|
|
|
2021-04-08 13:45:15 +01:00
|
|
|
sig {
|
|
|
|
params(
|
2021-04-08 14:58:39 +01:00
|
|
|
tag: T.any(Symbol, Utils::Bottles::Tag),
|
|
|
|
no_older_versions: T::Boolean,
|
2021-04-08 13:45:15 +01:00
|
|
|
).returns(
|
|
|
|
T.nilable([Checksum, Symbol, T.any(Symbol, String)]),
|
|
|
|
)
|
|
|
|
}
|
2021-04-08 14:58:39 +01:00
|
|
|
def checksum_for(tag, no_older_versions: false)
|
|
|
|
collector.fetch_checksum_for(tag, no_older_versions: no_older_versions)
|
2013-09-14 10:16:52 -05:00
|
|
|
end
|
2013-09-21 21:16:18 +01:00
|
|
|
|
|
|
|
def checksums
|
2021-04-08 13:45:15 +01:00
|
|
|
tags = collector.keys.sort_by do |sym|
|
|
|
|
tag = Utils::Bottles::Tag.from_symbol(sym)
|
|
|
|
version = tag.to_macos_version
|
2021-02-04 13:30:16 -05:00
|
|
|
# Give arm64 bottles a higher priority so they are first
|
2021-04-08 13:45:15 +01:00
|
|
|
priority = tag.arch == :arm64 ? "2" : "1"
|
|
|
|
"#{priority}.#{version}_#{sym}"
|
2020-06-10 10:06:46 +01:00
|
|
|
rescue MacOSVersionError
|
2020-12-07 15:43:44 +00:00
|
|
|
# Sort non-MacOS tags below MacOS tags.
|
2021-04-08 13:45:15 +01:00
|
|
|
"0.#{sym}"
|
2016-11-18 16:45:13 -08:00
|
|
|
end
|
2021-01-21 22:52:26 -08:00
|
|
|
tags.reverse.map do |tag|
|
2020-11-29 17:51:47 +01:00
|
|
|
{
|
2021-01-20 23:26:41 +01:00
|
|
|
"tag" => tag,
|
|
|
|
"digest" => collector[tag][:checksum],
|
|
|
|
"cellar" => collector[tag][:cellar],
|
2020-11-29 17:51:47 +01:00
|
|
|
}
|
2013-09-21 21:16:18 +01:00
|
|
|
end
|
|
|
|
end
|
2013-09-14 10:16:52 -05:00
|
|
|
end
|
2016-02-14 19:56:48 +00:00
|
|
|
|
|
|
|
class PourBottleCheck
|
2020-12-08 08:43:11 -08:00
|
|
|
include OnOS
|
|
|
|
|
2016-02-14 19:56:48 +00:00
|
|
|
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
|
2018-08-15 10:21:42 -07:00
|
|
|
|
|
|
|
require "extend/os/software_spec"
|