| 
									
										
										
										
											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" | 
					
						
							|  |  |  | 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" | 
					
						
							| 
									
										
										
										
											2018-09-06 16:58:17 -07:00
										 |  |  | require "global" | 
					
						
							| 
									
										
										
										
											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 = {}) | 
					
						
							|  |  |  |     spec = Hash[*spec.first] 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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-06 15:02:52 +02:00
										 |  |  |     def bintray | 
					
						
							| 
									
										
										
										
											2020-05-10 00:30:32 +01:00
										 |  |  |       ERB::Util.url_encode("#{name}-#{version}#{extname}") | 
					
						
							| 
									
										
										
										
											2018-08-06 15:02:52 +02:00
										 |  |  |     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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  |     checksum, tag, cellar = spec.checksum_for(Utils::Bottles.tag) | 
					
						
							| 
									
										
										
										
											2014-04-01 16:03:08 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 17:32:35 +01:00
										 |  |  |     filename = Filename.create(formula, tag, spec.rebuild) | 
					
						
							| 
									
										
										
										
											2018-08-08 07:33:54 +02:00
										 |  |  |     @resource.url("#{spec.root_url}/#{filename.bintray}", | 
					
						
							| 
									
										
										
										
											2018-03-24 10:53:49 +00:00
										 |  |  |                   select_download_strategy(spec.root_url_specs)) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  |     @cellar = cellar | 
					
						
							| 
									
										
										
										
											2016-08-18 17:32:35 +01:00
										 |  |  |     @rebuild = spec.rebuild | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-18 15:14:42 -05:00
										 |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 10:53:49 +00:00
										 |  |  |   def select_download_strategy(specs) | 
					
						
							| 
									
										
										
										
											2018-03-25 13:45:58 -04:00
										 |  |  |     specs[:using] ||= DownloadStrategyDetector.detect(@spec.root_url) | 
					
						
							| 
									
										
										
										
											2018-03-24 10:53:49 +00:00
										 |  |  |     specs | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BottleSpecification | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  |   attr_rw :prefix, :rebuild | 
					
						
							| 
									
										
										
										
											2015-07-03 21:34:22 +08:00
										 |  |  |   attr_accessor :tap | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  |   attr_reader :all_tags_cellar, :checksum, :collector, :root_url_specs, :repository | 
					
						
							| 
									
										
										
										
											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-11-29 17:51:47 +01:00
										 |  |  |     @all_tags_cellar = Homebrew::DEFAULT_CELLAR | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-09 12:51:00 +00:00
										 |  |  |   def prefix=(prefix) | 
					
						
							|  |  |  |     if [HOMEBREW_DEFAULT_PREFIX, | 
					
						
							|  |  |  |         HOMEBREW_MACOS_ARM_DEFAULT_PREFIX, | 
					
						
							|  |  |  |         HOMEBREW_LINUX_DEFAULT_PREFIX].exclude?(prefix) | 
					
						
							| 
									
										
										
										
											2021-01-25 09:18:10 +00:00
										 |  |  |       odisabled "setting 'prefix' for bottles" | 
					
						
							| 
									
										
										
										
											2020-12-09 12:51:00 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |     @prefix = prefix | 
					
						
							|  |  |  |   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? | 
					
						
							| 
									
										
										
										
											2020-04-05 15:44:50 +01:00
										 |  |  |       @root_url ||= "#{Homebrew::EnvConfig.bottle_domain}/#{Utils::Bottles::Bintray.repository(tap)}" | 
					
						
							| 
									
										
										
										
											2015-07-03 21:34:22 +08:00
										 |  |  |     else | 
					
						
							|  |  |  |       @root_url = var | 
					
						
							| 
									
										
										
										
											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-02-06 14:27:03 -05:00
										 |  |  |     # TODO: (3.1) uncomment to deprecate the old bottle syntax | 
					
						
							|  |  |  |     # if val.present? | 
					
						
							|  |  |  |     #   odeprecated( | 
					
						
							|  |  |  |     #     "`cellar` in a bottle block", | 
					
						
							|  |  |  |     #     "`brew style --fix` on the formula to update the style or use `sha256` with a `cellar:` argument", | 
					
						
							|  |  |  |     #   ) | 
					
						
							|  |  |  |     # end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  |     return collector.dig(Utils::Bottles.tag, :cellar) || @all_tags_cellar if val.nil? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  |   sig { params(tag: Symbol).returns(T::Boolean) } | 
					
						
							| 
									
										
										
										
											2014-04-01 16:03:08 -05:00
										 |  |  |   def tag?(tag) | 
					
						
							| 
									
										
										
										
											2016-09-20 22:24:31 +02:00
										 |  |  |     checksum_for(tag) ? 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
										 |  |  | 
 | 
					
						
							|  |  |  |       # TODO: (3.1) uncomment to deprecate the old bottle syntax | 
					
						
							|  |  |  |       # if digest && tag | 
					
						
							|  |  |  |       #   odeprecated( | 
					
						
							|  |  |  |       #     '`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
										 |  |  | 
 | 
					
						
							|  |  |  |     cellar ||= all_tags_cellar | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  |     collector[tag] = { checksum: Checksum.new(digest), cellar: cellar } | 
					
						
							| 
									
										
										
										
											2014-04-01 16:03:08 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  |   sig { params(tag: Symbol).returns(T.nilable([Checksum, Symbol, T.any(Symbol, String)])) } | 
					
						
							| 
									
										
										
										
											2014-04-01 16:03:08 -05:00
										 |  |  |   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 | 
					
						
							| 
									
										
										
										
											2016-11-18 16:45:13 -08:00
										 |  |  |     tags = collector.keys.sort_by do |tag| | 
					
						
							| 
									
										
										
										
											2021-02-04 13:30:16 -05:00
										 |  |  |       version = OS::Mac::Version.from_symbol(tag) | 
					
						
							|  |  |  |       # Give arm64 bottles a higher priority so they are first | 
					
						
							|  |  |  |       priority = version.arch == :arm64 ? "2" : "1" | 
					
						
							|  |  |  |       "#{priority}.#{version}_#{tag}" | 
					
						
							| 
									
										
										
										
											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. | 
					
						
							| 
									
										
										
										
											2019-10-13 10:03:26 +01:00
										 |  |  |       "0.#{tag}" | 
					
						
							| 
									
										
										
										
											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" |