| 
									
										
										
										
											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" | 
					
						
							| 
									
										
										
										
											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 = { | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2018-08-06 17:15:51 +02:00
										 |  |  |   def_delegators :@resource, :download_name, :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 = [] | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-17 15:17:27 +01:00
										 |  |  |   attr_reader :bottle_disable_reason | 
					
						
							| 
									
										
										
										
											2015-09-14 19:51:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:39 -05:00
										 |  |  |     if block_given? | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   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| | 
					
						
							|  |  |  |       begin | 
					
						
							|  |  |  |         deps_f << dep.to_formula | 
					
						
							|  |  |  |         dep | 
					
						
							|  |  |  |       rescue TapFormulaUnavailableError | 
					
						
							|  |  |  |         # Don't complain about missing cross-tap dependencies | 
					
						
							|  |  |  |         next | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     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) | 
					
						
							| 
									
										
										
										
											2019-01-23 21:57:37 +00:00
										 |  |  |     odisabled "fails_with :gcc_4_0" if compiler == :gcc_4_0 | 
					
						
							| 
									
										
										
										
											2019-01-26 17:13:14 +00:00
										 |  |  |     odisabled "fails_with :gcc_4_2" if compiler == :gcc_4_2 | 
					
						
							|  |  |  |     odisabled "fails_with :gcc" if compiler == :gcc && !block_given? | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							| 
									
										
										
										
											2019-01-26 17:13:14 +00:00
										 |  |  |     odisabled "needs :cxx11" if standards.include?(:cxx11) | 
					
						
							|  |  |  |     odisabled "needs :cxx14" if standards.include?(:cxx14) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2016-11-05 16:13:42 -04:00
										 |  |  |       @tag = tag.to_s.gsub(/_or_later$/, "") | 
					
						
							| 
									
										
										
										
											2016-08-18 17:32:35 +01:00
										 |  |  |       @rebuild = rebuild | 
					
						
							| 
									
										
										
										
											2014-07-18 15:14:42 -05:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  |       "#{name}-#{version}#{extname}" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 17:57:51 +01:00
										 |  |  |     checksum, tag = 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 | 
					
						
							|  |  |  |     @cellar = spec.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
										 |  |  | 
 | 
					
						
							|  |  |  |   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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2018-09-06 16:58:17 -07:00
										 |  |  |   DEFAULT_PREFIX = Homebrew::DEFAULT_PREFIX | 
					
						
							| 
									
										
										
										
											2014-05-27 21:14:59 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 17:32:35 +01:00
										 |  |  |   attr_rw :prefix, :cellar, :rebuild | 
					
						
							| 
									
										
										
										
											2015-07-03 21:34:22 +08:00
										 |  |  |   attr_accessor :tap | 
					
						
							| 
									
										
										
										
											2018-03-24 10:53:49 +00:00
										 |  |  |   attr_reader :checksum, :collector, :root_url_specs | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  |     @cellar = Homebrew::DEFAULT_CELLAR | 
					
						
							| 
									
										
										
										
											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? | 
					
						
							| 
									
										
										
										
											2018-06-29 19:51:18 +01:00
										 |  |  |       @root_url ||= "#{HOMEBREW_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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-18 21:42:43 -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) | 
					
						
							| 
									
										
										
										
											2016-09-20 22:24:31 +02:00
										 |  |  |     checksum_for(tag) ? true : false | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2016-11-18 16:45:13 -08:00
										 |  |  |     tags = collector.keys.sort_by do |tag| | 
					
						
							|  |  |  |       # Sort non-MacOS tags below MacOS tags. | 
					
						
							| 
									
										
										
										
											2016-09-17 15:17:27 +01:00
										 |  |  |       begin | 
					
						
							| 
									
										
										
										
											2017-04-25 14:34:27 +01:00
										 |  |  |         OS::Mac::Version.from_symbol tag | 
					
						
							|  |  |  |       rescue ArgumentError | 
					
						
							| 
									
										
										
										
											2016-11-18 16:45:13 -08:00
										 |  |  |         "0.#{tag}" | 
					
						
							| 
									
										
										
										
											2016-09-17 17:01:04 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-11-18 16:45:13 -08:00
										 |  |  |     end | 
					
						
							|  |  |  |     checksums = {} | 
					
						
							|  |  |  |     tags.reverse_each do |tag| | 
					
						
							|  |  |  |       checksum = collector[tag] | 
					
						
							| 
									
										
										
										
											2014-04-01 16:03:07 -05:00
										 |  |  |       checksums[checksum.hash_type] ||= [] | 
					
						
							| 
									
										
										
										
											2016-11-18 16:45:13 -08:00
										 |  |  |       checksums[checksum.hash_type] << { checksum => tag } | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2018-08-15 10:21:42 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | require "extend/os/software_spec" |