| 
									
										
										
										
											2021-09-11 01:00:23 +01:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-28 11:45:18 -08:00
										 |  |  | require "attrable" | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "resource" | 
					
						
							| 
									
										
										
										
											2021-02-26 11:23:33 +00:00
										 |  |  | require "download_strategy" | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "checksum" | 
					
						
							|  |  |  | require "version" | 
					
						
							|  |  |  | require "options" | 
					
						
							|  |  |  | require "build_options" | 
					
						
							|  |  |  | require "dependency_collector" | 
					
						
							| 
									
										
										
										
											2016-04-25 17:57:51 +01:00
										 |  |  | require "utils/bottles" | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "patch" | 
					
						
							|  |  |  | require "compilers" | 
					
						
							| 
									
										
										
										
											2023-05-09 02:15:28 +02:00
										 |  |  | require "macos_version" | 
					
						
							| 
									
										
										
										
											2022-06-23 17:18:58 -04:00
										 |  |  | require "extend/on_system" | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | class SoftwareSpec | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:38 -05:00
										 |  |  |   extend Forwardable | 
					
						
							| 
									
										
										
										
											2022-06-29 17:48:21 -04:00
										 |  |  |   include OnSystem::MacOSAndLinux | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							| 
									
										
										
										
											2023-06-19 06:03:31 +01:00
										 |  |  |               :deprecated_options, :dependency_collector, :bottle_specification, :compiler_failures | 
					
						
							| 
									
										
										
										
											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: []) | 
					
						
							| 
									
										
										
										
											2022-08-24 23:53:35 +01:00
										 |  |  |     # Ensure this is synced with `initialize_dup` and `freeze` (excluding simple objects like integers and booleans) | 
					
						
							| 
									
										
										
										
											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 = [] | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:39 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-24 23:53:35 +01:00
										 |  |  |   def initialize_dup(other) | 
					
						
							| 
									
										
										
										
											2022-08-25 11:04:37 +01:00
										 |  |  |     super | 
					
						
							| 
									
										
										
										
											2022-08-24 23:53:35 +01:00
										 |  |  |     @resource = @resource.dup | 
					
						
							|  |  |  |     @resources = @resources.dup | 
					
						
							| 
									
										
										
										
											2022-08-25 11:04:37 +01:00
										 |  |  |     @dependency_collector = @dependency_collector.dup | 
					
						
							| 
									
										
										
										
											2022-08-24 23:53:35 +01:00
										 |  |  |     @bottle_specification = @bottle_specification.dup | 
					
						
							|  |  |  |     @patches = @patches.dup | 
					
						
							|  |  |  |     @options = @options.dup | 
					
						
							|  |  |  |     @flags = @flags.dup | 
					
						
							|  |  |  |     @deprecated_flags = @deprecated_flags.dup | 
					
						
							|  |  |  |     @deprecated_options = @deprecated_options.dup | 
					
						
							|  |  |  |     @build = @build.dup | 
					
						
							|  |  |  |     @compiler_failures = @compiler_failures.dup | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def freeze | 
					
						
							|  |  |  |     @resource.freeze | 
					
						
							|  |  |  |     @resources.freeze | 
					
						
							|  |  |  |     @dependency_collector.freeze | 
					
						
							|  |  |  |     @bottle_specification.freeze | 
					
						
							|  |  |  |     @patches.freeze | 
					
						
							|  |  |  |     @options.freeze | 
					
						
							|  |  |  |     @flags.freeze | 
					
						
							|  |  |  |     @deprecated_flags.freeze | 
					
						
							|  |  |  |     @deprecated_options.freeze | 
					
						
							|  |  |  |     @build.freeze | 
					
						
							|  |  |  |     @compiler_failures.freeze | 
					
						
							|  |  |  |     super | 
					
						
							| 
									
										
										
										
											2022-08-25 11:04:37 +01: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 | 
					
						
							| 
									
										
										
										
											2023-04-18 00:22:13 +01:00
										 |  |  |       next if r.version | 
					
						
							| 
									
										
										
										
											2017-08-07 10:12:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-18 00:22:13 +01:00
										 |  |  |       raise "#{full_name}: version missing for \"#{r.name}\" resource!" if version.nil? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-06 16:47:09 +01:00
										 |  |  |       r.version(version.head? ? Version.new("HEAD") : version.dup) | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-08 01:08:15 +01:00
										 |  |  |     @resource.url(val, **specs) | 
					
						
							| 
									
										
										
										
											2013-09-28 16:37:05 -05:00
										 |  |  |     dependency_collector.add(@resource) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-01 20:33:24 +08:00
										 |  |  |   def bottle_defined? | 
					
						
							| 
									
										
										
										
											2021-09-16 18:56:47 +01:00
										 |  |  |     !bottle_specification.collector.tags.empty? | 
					
						
							| 
									
										
										
										
											2015-11-01 20:33:24 +08:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-26 14:36:49 -07:00
										 |  |  |   def bottle_tag?(tag = nil) | 
					
						
							|  |  |  |     bottle_specification.tag?(Utils::Bottles.tag(tag)) | 
					
						
							| 
									
										
										
										
											2020-12-09 13:53:10 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-26 14:36:49 -07:00
										 |  |  |   def bottled?(tag = nil) | 
					
						
							| 
									
										
										
										
											2023-04-04 15:37:24 +01:00
										 |  |  |     bottle_tag?(tag) && | 
					
						
							| 
									
										
										
										
											2021-08-26 14:36:49 -07:00
										 |  |  |       (tag.present? || bottle_specification.compatible_locations? || owner.force_bottle) | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-30 14:59:14 +01:00
										 |  |  |   def bottle(&block) | 
					
						
							|  |  |  |     bottle_specification.instance_eval(&block) | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							| 
									
										
										
										
											2024-04-01 09:00:32 -04:00
										 |  |  |     # odeprecated "SoftwareSpec#go_resource", "Go modules" | 
					
						
							| 
									
										
										
										
											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? | 
					
						
							| 
									
										
										
										
											2023-04-18 15:06:50 -07:00
										 |  |  |       raise ArgumentError, "option name must be longer than one character: #{name}" if name.length <= 1
 | 
					
						
							| 
									
										
										
										
											2016-04-20 02:17:28 -04:00
										 |  |  |       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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-12 23:45:03 +01:00
										 |  |  |   sig { | 
					
						
							|  |  |  |     params( | 
					
						
							| 
									
										
										
										
											2024-02-13 00:42:54 +01:00
										 |  |  |       dep:    T.any(String, T::Hash[T.any(String, Symbol), T.any(Symbol, T::Array[Symbol])]), | 
					
						
							|  |  |  |       bounds: T::Hash[Symbol, Symbol], | 
					
						
							| 
									
										
										
										
											2024-02-12 23:45:03 +01:00
										 |  |  |     ).void | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2024-02-13 00:42:54 +01:00
										 |  |  |   def uses_from_macos(dep, bounds = {}) | 
					
						
							|  |  |  |     if dep.is_a?(Hash) | 
					
						
							|  |  |  |       bounds = dep.dup | 
					
						
							| 
									
										
										
										
											2024-02-12 23:45:03 +01:00
										 |  |  |       dep, tags = bounds.shift | 
					
						
							| 
									
										
										
										
											2024-02-13 00:42:54 +01:00
										 |  |  |       dep = T.cast(dep, String) | 
					
						
							| 
									
										
										
										
											2024-02-12 23:45:03 +01:00
										 |  |  |       tags = [*tags] | 
					
						
							| 
									
										
										
										
											2024-02-13 00:42:54 +01:00
										 |  |  |       bounds = T.cast(bounds, T::Hash[Symbol, Symbol]) | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       tags = [] | 
					
						
							| 
									
										
										
										
											2022-07-23 02:47:22 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |     depends_on UsesFromMacOSDependency.new(dep, tags, bounds:) | 
					
						
							| 
									
										
										
										
											2023-06-19 06:03:31 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2021-09-14 04:06:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-19 06:03:31 +01:00
										 |  |  |   # @deprecated | 
					
						
							|  |  |  |   def uses_from_macos_elements | 
					
						
							| 
									
										
										
										
											2024-02-12 23:21:28 +01:00
										 |  |  |     # TODO: Remember to remove the delegate from `Formula`. | 
					
						
							| 
									
										
										
										
											2023-12-07 22:58:54 +00:00
										 |  |  |     odisabled "#uses_from_macos_elements", "#declared_deps" | 
					
						
							| 
									
										
										
										
											2019-05-24 21:36:48 -03:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-19 06:03:31 +01:00
										 |  |  |   # @deprecated | 
					
						
							| 
									
										
										
										
											2021-09-14 09:48:17 +01:00
										 |  |  |   def uses_from_macos_names | 
					
						
							| 
									
										
										
										
											2024-02-12 23:21:28 +01:00
										 |  |  |     # TODO: Remember to remove the delegate from `Formula`. | 
					
						
							| 
									
										
										
										
											2023-12-07 22:58:54 +00:00
										 |  |  |     odisabled "#uses_from_macos_names", "#declared_deps" | 
					
						
							| 
									
										
										
										
											2021-09-14 09:48:17 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  |   def deps | 
					
						
							| 
									
										
										
										
											2023-06-19 06:03:31 +01:00
										 |  |  |     dependency_collector.deps.dup_without_system_deps | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def declared_deps | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  |     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 = [] | 
					
						
							| 
									
										
										
										
											2024-02-22 23:29:55 +00:00
										 |  |  |     recursive_dependencies = deps.filter_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 | 
					
						
							| 
									
										
										
										
											2024-02-22 23:29:55 +00:00
										 |  |  |     end.uniq | 
					
						
							| 
									
										
										
										
											2017-07-02 05:39:02 -07:00
										 |  |  |     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) | 
					
						
							| 
									
										
										
										
											2022-07-15 18:25:57 +02:00
										 |  |  |     return if p.is_a?(ExternalPatch) && p.url.blank? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-22 15:19:33 +08:00
										 |  |  |     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 | 
					
						
							| 
									
										
										
										
											2023-07-06 16:47:09 +01:00
										 |  |  |     @resource.version(Version.new("HEAD")) | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-07 23:48:52 +00:00
										 |  |  |   def verify_download_integrity(_filename) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2016-08-18 17:32:35 +01:00
										 |  |  |     attr_reader :name, :version, :tag, :rebuild | 
					
						
							| 
									
										
										
										
											2014-07-18 15:14:42 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-01 17:46:48 +00:00
										 |  |  |     sig { params(formula: Formula, tag: Utils::Bottles::Tag, rebuild: Integer).returns(T.attached_class) } | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-01 17:46:48 +00:00
										 |  |  |     sig { params(name: String, version: PkgVersion, tag: Utils::Bottles::Tag, rebuild: Integer).void } | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2024-01-01 17:46:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       raise ArgumentError, "Invalid bottle name" unless Utils.safe_filename?(@name) | 
					
						
							|  |  |  |       raise ArgumentError, "Invalid bottle version" unless Utils.safe_filename?(version.to_s) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-18 15:14:42 -05:00
										 |  |  |       @version = version | 
					
						
							| 
									
										
										
										
											2019-11-06 14:31:03 +00:00
										 |  |  |       @tag = tag.to_s | 
					
						
							| 
									
										
										
										
											2016-08-18 17:32:35 +01:00
										 |  |  |       @rebuild = rebuild | 
					
						
							| 
									
										
										
										
											2014-07-18 15:14:42 -05:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2014-07-18 15:14:42 -05:00
										 |  |  |     def to_s | 
					
						
							| 
									
										
										
										
											2018-08-06 15:02:52 +02:00
										 |  |  |       "#{name}--#{version}#{extname}" | 
					
						
							| 
									
										
										
										
											2014-07-18 15:14:42 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-09-23 18:13:48 +02:00
										 |  |  |     alias to_str to_s | 
					
						
							| 
									
										
										
										
											2014-07-18 15:14:42 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2018-08-06 15:02:52 +02:00
										 |  |  |     def json | 
					
						
							|  |  |  |       "#{name}--#{version}.#{tag}.bottle.json" | 
					
						
							| 
									
										
										
										
											2014-07-18 15:14:42 -05:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-12 14:48:58 +01:00
										 |  |  |     def url_encode | 
					
						
							| 
									
										
										
										
											2020-05-10 00:30:32 +01:00
										 |  |  |       ERB::Util.url_encode("#{name}-#{version}#{extname}") | 
					
						
							| 
									
										
										
										
											2018-08-06 15:02:52 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-09 16:31:04 +01:00
										 |  |  |     def github_packages | 
					
						
							|  |  |  |       "#{name}--#{version}#{extname}" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2018-08-06 15:02:52 +02:00
										 |  |  |     def extname | 
					
						
							| 
									
										
										
										
											2017-09-24 20:12:58 +01:00
										 |  |  |       s = rebuild.positive? ? ".#{rebuild}" : "" | 
					
						
							| 
									
										
										
										
											2018-08-06 15:02:52 +02:00
										 |  |  |       ".#{tag}.bottle#{s}.tar.gz" | 
					
						
							| 
									
										
										
										
											2014-07-18 15:14:42 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2014-07-18 15:14:42 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |   extend Forwardable | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-30 03:29:51 +00:00
										 |  |  |   attr_reader :name, :resource, :tag, :cellar, :rebuild | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-26 11:23:33 +00:00
										 |  |  |   def_delegators :resource, :url, :verify_download_integrity | 
					
						
							| 
									
										
										
										
											2021-07-29 21:15:40 +01:00
										 |  |  |   def_delegators :resource, :cached_download | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-10 21:17:33 +02:00
										 |  |  |   def initialize(formula, spec, tag = nil) | 
					
						
							| 
									
										
										
										
											2014-07-17 20:44:56 -05:00
										 |  |  |     @name = formula.name | 
					
						
							| 
									
										
										
										
											2014-03-13 13:13:06 +00:00
										 |  |  |     @resource = Resource.new | 
					
						
							| 
									
										
										
										
											2021-10-04 14:21:03 +01:00
										 |  |  |     @resource.owner = formula | 
					
						
							| 
									
										
										
										
											2015-03-17 09:03:13 +00:00
										 |  |  |     @spec = spec | 
					
						
							| 
									
										
										
										
											2014-04-01 16:03:08 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-16 18:56:47 +01:00
										 |  |  |     tag_spec = spec.tag_specification_for(Utils::Bottles.tag(tag)) | 
					
						
							| 
									
										
										
										
											2014-04-01 16:03:08 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-16 18:56:47 +01:00
										 |  |  |     @tag = tag_spec.tag | 
					
						
							|  |  |  |     @cellar = tag_spec.cellar | 
					
						
							| 
									
										
										
										
											2016-08-18 17:32:35 +01:00
										 |  |  |     @rebuild = spec.rebuild | 
					
						
							| 
									
										
										
										
											2021-04-15 18:06:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-18 00:22:13 +01:00
										 |  |  |     @resource.version(formula.pkg_version.to_s) | 
					
						
							| 
									
										
										
										
											2021-09-16 18:56:47 +01:00
										 |  |  |     @resource.checksum = tag_spec.checksum | 
					
						
							| 
									
										
										
										
											2021-04-15 18:06:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-22 10:41:35 +01:00
										 |  |  |     @fetch_tab_retried = false | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-15 18:06:54 +01:00
										 |  |  |     root_url(spec.root_url, spec.root_url_specs) | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-29 21:15:40 +01:00
										 |  |  |   def fetch(verify_download_integrity: true) | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |     @resource.fetch(verify_download_integrity:) | 
					
						
							| 
									
										
										
										
											2021-07-29 21:15:40 +01:00
										 |  |  |   rescue DownloadError | 
					
						
							|  |  |  |     raise unless fallback_on_error | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     fetch_tab | 
					
						
							|  |  |  |     retry | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-02 12:44:07 +01:00
										 |  |  |   def clear_cache | 
					
						
							|  |  |  |     @resource.clear_cache | 
					
						
							|  |  |  |     github_packages_manifest_resource&.clear_cache | 
					
						
							| 
									
										
										
										
											2021-10-22 10:41:35 +01:00
										 |  |  |     @fetch_tab_retried = false | 
					
						
							| 
									
										
										
										
											2021-04-02 12:44:07 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-09 13:53:10 +00:00
										 |  |  |   def compatible_locations? | 
					
						
							| 
									
										
										
										
											2021-09-16 18:56:47 +01:00
										 |  |  |     @spec.compatible_locations?(tag: @tag) | 
					
						
							| 
									
										
										
										
											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? | 
					
						
							| 
									
										
										
										
											2021-09-16 18:56:47 +01:00
										 |  |  |     @spec.skip_relocation?(tag: @tag) | 
					
						
							| 
									
										
										
										
											2015-05-25 23:32:55 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-22 19:11:09 -05:00
										 |  |  |   def stage | 
					
						
							|  |  |  |     resource.downloader.stage | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-31 20:55:35 +01:00
										 |  |  |   def fetch_tab | 
					
						
							| 
									
										
										
										
											2021-05-19 13:15:33 +01:00
										 |  |  |     return if github_packages_manifest_resource.blank? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-31 20:55:35 +01:00
										 |  |  |     # a checksum is used later identifying the correct tab but we do not have the checksum for the manifest/tab | 
					
						
							| 
									
										
										
										
											2021-05-19 13:15:33 +01:00
										 |  |  |     github_packages_manifest_resource.fetch(verify_download_integrity: false) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     begin | 
					
						
							| 
									
										
										
										
											2021-10-22 10:41:35 +01:00
										 |  |  |       github_packages_manifest_resource_tab(github_packages_manifest_resource) | 
					
						
							|  |  |  |     rescue RuntimeError => e | 
					
						
							|  |  |  |       raise DownloadError.new(github_packages_manifest_resource, e) | 
					
						
							| 
									
										
										
										
											2021-05-19 13:15:33 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2021-04-15 18:06:54 +01:00
										 |  |  |   rescue DownloadError | 
					
						
							|  |  |  |     raise unless fallback_on_error | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-22 10:41:35 +01:00
										 |  |  |     retry | 
					
						
							|  |  |  |   rescue ArgumentError | 
					
						
							|  |  |  |     raise if @fetch_tab_retried | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @fetch_tab_retried = true | 
					
						
							|  |  |  |     github_packages_manifest_resource.clear_cache | 
					
						
							| 
									
										
										
										
											2021-04-15 18:06:54 +01:00
										 |  |  |     retry | 
					
						
							| 
									
										
										
										
											2021-03-31 20:55:35 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def tab_attributes | 
					
						
							|  |  |  |     return {} unless github_packages_manifest_resource&.downloaded? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-22 10:41:35 +01:00
										 |  |  |     github_packages_manifest_resource_tab(github_packages_manifest_resource) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 13:39:13 -04:00
										 |  |  |   sig { returns(Filename) } | 
					
						
							|  |  |  |   def filename | 
					
						
							|  |  |  |     Filename.create(resource.owner, @tag, @spec.rebuild) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-22 10:41:35 +01:00
										 |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def github_packages_manifest_resource_tab(github_packages_manifest_resource) | 
					
						
							| 
									
										
										
										
											2021-03-31 20:55:35 +01:00
										 |  |  |     manifest_json = github_packages_manifest_resource.cached_download.read | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     json = begin | 
					
						
							|  |  |  |       JSON.parse(manifest_json) | 
					
						
							|  |  |  |     rescue JSON::ParserError | 
					
						
							| 
									
										
										
										
											2022-06-28 10:09:59 +01:00
										 |  |  |       raise "The downloaded GitHub Packages manifest was corrupted or modified (it is not valid JSON): " \ | 
					
						
							| 
									
										
										
										
											2021-05-19 13:15:33 +01:00
										 |  |  |             "\n#{github_packages_manifest_resource.cached_download}" | 
					
						
							| 
									
										
										
										
											2021-03-31 20:55:35 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     manifests = json["manifests"] | 
					
						
							|  |  |  |     raise ArgumentError, "Missing 'manifests' section." if manifests.blank? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-22 23:29:55 +00:00
										 |  |  |     manifests_annotations = manifests.filter_map { |m| m["annotations"] } | 
					
						
							| 
									
										
										
										
											2021-03-31 20:55:35 +01:00
										 |  |  |     raise ArgumentError, "Missing 'annotations' section." if manifests_annotations.blank? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-02 10:13:27 +01:00
										 |  |  |     bottle_digest = @resource.checksum.hexdigest | 
					
						
							| 
									
										
										
										
											2021-05-31 16:06:27 +01:00
										 |  |  |     image_ref = GitHubPackages.version_rebuild(@resource.version, rebuild, @tag.to_s) | 
					
						
							| 
									
										
										
										
											2021-03-31 20:55:35 +01:00
										 |  |  |     manifest_annotations = manifests_annotations.find do |m| | 
					
						
							| 
									
										
										
										
											2021-05-31 16:06:27 +01:00
										 |  |  |       next if m["sh.brew.bottle.digest"] != bottle_digest | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       m["org.opencontainers.image.ref.name"] == image_ref | 
					
						
							| 
									
										
										
										
											2021-03-31 20:55:35 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |     raise ArgumentError, "Couldn't find manifest matching bottle checksum." if manifest_annotations.blank? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     tab = manifest_annotations["sh.brew.tab"] | 
					
						
							|  |  |  |     raise ArgumentError, "Couldn't find tab from manifest." if tab.blank? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     begin | 
					
						
							|  |  |  |       JSON.parse(tab) | 
					
						
							|  |  |  |     rescue JSON::ParserError | 
					
						
							|  |  |  |       raise ArgumentError, "Couldn't parse tab JSON." | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def github_packages_manifest_resource | 
					
						
							|  |  |  |     return if @resource.download_strategy != CurlGitHubPackagesDownloadStrategy | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @github_packages_manifest_resource ||= begin | 
					
						
							|  |  |  |       resource = Resource.new("#{name}_bottle_manifest") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       version_rebuild = GitHubPackages.version_rebuild(@resource.version, rebuild) | 
					
						
							|  |  |  |       resource.version(version_rebuild) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-06 19:13:30 +01:00
										 |  |  |       image_name = GitHubPackages.image_formula_name(@name) | 
					
						
							| 
									
										
										
										
											2021-04-07 13:31:41 +01:00
										 |  |  |       image_tag = GitHubPackages.image_version_rebuild(version_rebuild) | 
					
						
							| 
									
										
										
										
											2022-10-08 01:08:15 +01:00
										 |  |  |       resource.url( | 
					
						
							|  |  |  |         "#{root_url}/#{image_name}/manifests/#{image_tag}", | 
					
						
							| 
									
										
										
										
											2021-04-05 14:58:17 +01:00
										 |  |  |         using:   CurlGitHubPackagesDownloadStrategy, | 
					
						
							|  |  |  |         headers: ["Accept: application/vnd.oci.image.index.v1+json"], | 
					
						
							| 
									
										
										
										
											2022-10-08 01:08:15 +01:00
										 |  |  |       ) | 
					
						
							| 
									
										
										
										
											2023-04-18 00:22:13 +01:00
										 |  |  |       T.cast(resource.downloader, CurlGitHubPackagesDownloadStrategy).resolved_basename = | 
					
						
							|  |  |  |         "#{name}-#{version_rebuild}.bottle_manifest.json" | 
					
						
							| 
									
										
										
										
											2021-03-31 20:55:35 +01:00
										 |  |  |       resource | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 10:53:49 +00:00
										 |  |  |   def select_download_strategy(specs) | 
					
						
							| 
									
										
										
										
											2021-04-15 18:06:54 +01:00
										 |  |  |     specs[:using] ||= DownloadStrategyDetector.detect(@root_url) | 
					
						
							| 
									
										
										
										
											2023-04-18 00:22:13 +01:00
										 |  |  |     specs[:bottle] = true | 
					
						
							| 
									
										
										
										
											2018-03-24 10:53:49 +00:00
										 |  |  |     specs | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2021-04-15 18:06:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-29 21:15:40 +01:00
										 |  |  |   def fallback_on_error | 
					
						
							|  |  |  |     # Use the default bottle domain as a fallback mirror | 
					
						
							|  |  |  |     if @resource.url.start_with?(Homebrew::EnvConfig.bottle_domain) && | 
					
						
							|  |  |  |        Homebrew::EnvConfig.bottle_domain != HOMEBREW_BOTTLE_DEFAULT_DOMAIN | 
					
						
							|  |  |  |       opoo "Bottle missing, falling back to the default domain..." | 
					
						
							|  |  |  |       root_url(HOMEBREW_BOTTLE_DEFAULT_DOMAIN) | 
					
						
							|  |  |  |       @github_packages_manifest_resource = nil | 
					
						
							|  |  |  |       true | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       false | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-15 18:06:54 +01:00
										 |  |  |   def root_url(val = nil, specs = {}) | 
					
						
							|  |  |  |     return @root_url if val.nil? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @root_url = val | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     filename = Filename.create(resource.owner, @tag, @spec.rebuild) | 
					
						
							|  |  |  |     path, resolved_basename = Utils::Bottles.path_resolved_basename(val, name, resource.checksum, filename) | 
					
						
							| 
									
										
										
										
											2022-10-08 01:08:15 +01:00
										 |  |  |     @resource.url("#{val}/#{path}", **select_download_strategy(specs)) | 
					
						
							| 
									
										
										
										
											2021-04-15 18:06:54 +01:00
										 |  |  |     @resource.downloader.resolved_basename = resolved_basename if resolved_basename.present? | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BottleSpecification | 
					
						
							| 
									
										
										
										
											2023-12-28 11:45:18 -08:00
										 |  |  |   extend Attrable | 
					
						
							| 
									
										
										
										
											2021-12-06 02:10:55 -08:00
										 |  |  |   RELOCATABLE_CELLARS = [:any, :any_skip_relocation].freeze | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-09 09:30:36 +01:00
										 |  |  |   attr_rw :rebuild | 
					
						
							| 
									
										
										
										
											2015-07-03 21:34:22 +08:00
										 |  |  |   attr_accessor :tap | 
					
						
							| 
									
										
										
										
											2021-09-16 18:56:47 +01:00
										 |  |  |   attr_reader :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
 | 
					
						
							| 
									
										
										
										
											2020-12-09 13:53:10 +00:00
										 |  |  |     @repository = Homebrew::DEFAULT_REPOSITORY | 
					
						
							| 
									
										
										
										
											2016-04-25 17:57:51 +01:00
										 |  |  |     @collector = Utils::Bottles::Collector.new | 
					
						
							| 
									
										
										
										
											2018-03-24 10:53:49 +00:00
										 |  |  |     @root_url_specs = {} | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 10:53:49 +00:00
										 |  |  |   def root_url(var = nil, specs = {}) | 
					
						
							| 
									
										
										
										
											2015-07-03 21:34:22 +08:00
										 |  |  |     if var.nil? | 
					
						
							| 
									
										
										
										
											2021-07-29 21:15:40 +01:00
										 |  |  |       @root_url ||= if (github_packages_url = GitHubPackages.root_url_if_match(Homebrew::EnvConfig.bottle_domain)) | 
					
						
							|  |  |  |         github_packages_url | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         Homebrew::EnvConfig.bottle_domain | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-07-03 21:34:22 +08:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2021-04-08 10:54:28 +01:00
										 |  |  |       @root_url = if (github_packages_url = GitHubPackages.root_url_if_match(var)) | 
					
						
							|  |  |  |         github_packages_url | 
					
						
							| 
									
										
										
										
											2021-04-04 01:04:54 -07:00
										 |  |  |       else | 
					
						
							|  |  |  |         var | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-03-24 10:53:49 +00:00
										 |  |  |       @root_url_specs.merge!(specs) | 
					
						
							| 
									
										
										
										
											2015-07-03 21:34:22 +08:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 16:17:31 +01:00
										 |  |  |   def ==(other) | 
					
						
							|  |  |  |     self.class == other.class && rebuild == other.rebuild && collector == other.collector && | 
					
						
							|  |  |  |       root_url == other.root_url && root_url_specs == other.root_url_specs && tap == other.tap | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  |   alias eql? == | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-05 12:23:42 -08:00
										 |  |  |   sig { params(tag: Utils::Bottles::Tag).returns(T.any(Symbol, String)) } | 
					
						
							| 
									
										
										
										
											2022-03-06 21:55:54 -08:00
										 |  |  |   def tag_to_cellar(tag = Utils::Bottles.tag) | 
					
						
							| 
									
										
										
										
											2021-09-16 18:56:47 +01:00
										 |  |  |     spec = collector.specification_for(tag) | 
					
						
							| 
									
										
										
										
											2022-03-06 21:55:54 -08:00
										 |  |  |     if spec.present? | 
					
						
							| 
									
										
										
										
											2023-11-05 12:23:42 -08:00
										 |  |  |       spec.cellar | 
					
						
							| 
									
										
										
										
											2021-09-16 18:56:47 +01:00
										 |  |  |     else | 
					
						
							|  |  |  |       tag.default_cellar | 
					
						
							| 
									
										
										
										
											2021-04-08 13:45:15 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2022-03-06 21:55:54 -08:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   sig { params(tag: Utils::Bottles::Tag).returns(T::Boolean) } | 
					
						
							|  |  |  |   def compatible_locations?(tag: Utils::Bottles.tag) | 
					
						
							|  |  |  |     cellar = tag_to_cellar(tag) | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-06 02:10:55 -08:00
										 |  |  |     return true if RELOCATABLE_CELLARS.include?(cellar) | 
					
						
							| 
									
										
										
										
											2020-12-09 13:53:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-05 12:23:42 -08:00
										 |  |  |     prefix = Pathname(cellar.to_s).parent.to_s | 
					
						
							| 
									
										
										
										
											2021-09-16 18:56:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-30 04:37:09 +01:00
										 |  |  |     cellar_relocatable = cellar.size >= HOMEBREW_CELLAR.to_s.size && ENV["HOMEBREW_RELOCATE_BUILD_PREFIX"].present? | 
					
						
							|  |  |  |     prefix_relocatable = prefix.size >= HOMEBREW_PREFIX.to_s.size && ENV["HOMEBREW_RELOCATE_BUILD_PREFIX"].present? | 
					
						
							| 
									
										
										
										
											2021-12-06 02:10:55 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     compatible_cellar = cellar == HOMEBREW_CELLAR.to_s || cellar_relocatable | 
					
						
							|  |  |  |     compatible_prefix = prefix == HOMEBREW_PREFIX.to_s || prefix_relocatable | 
					
						
							| 
									
										
										
										
											2020-12-09 13:53:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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? | 
					
						
							| 
									
										
										
										
											2021-09-16 18:56:47 +01:00
										 |  |  |   sig { params(tag: Utils::Bottles::Tag).returns(T::Boolean) } | 
					
						
							|  |  |  |   def skip_relocation?(tag: Utils::Bottles.tag) | 
					
						
							|  |  |  |     spec = collector.specification_for(tag) | 
					
						
							|  |  |  |     spec&.cellar == :any_skip_relocation | 
					
						
							| 
									
										
										
										
											2015-05-25 23:32:55 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-08 14:58:39 +01:00
										 |  |  |   sig { params(tag: T.any(Symbol, Utils::Bottles::Tag), no_older_versions: T::Boolean).returns(T::Boolean) } | 
					
						
							|  |  |  |   def tag?(tag, no_older_versions: false) | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |     collector.tag?(tag, no_older_versions:) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-19 16:36:42 +01:00
										 |  |  |     cellar = hash[:cellar] if digest && tag | 
					
						
							| 
									
										
										
										
											2021-01-28 12:26:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-08 13:45:15 +01:00
										 |  |  |     tag = Utils::Bottles::Tag.from_symbol(tag) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cellar ||= tag.default_cellar | 
					
						
							| 
									
										
										
										
											2021-04-08 01:56:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |     collector.add(tag, checksum: Checksum.new(digest), cellar:) | 
					
						
							| 
									
										
										
										
											2014-04-01 16:03:08 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-08 13:45:15 +01:00
										 |  |  |   sig { | 
					
						
							| 
									
										
										
										
											2021-09-16 18:56:47 +01:00
										 |  |  |     params(tag: Utils::Bottles::Tag, no_older_versions: T::Boolean) | 
					
						
							|  |  |  |       .returns(T.nilable(Utils::Bottles::TagSpecification)) | 
					
						
							| 
									
										
										
										
											2021-04-08 13:45:15 +01:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-09-16 18:56:47 +01:00
										 |  |  |   def tag_specification_for(tag, no_older_versions: false) | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |     collector.specification_for(tag, no_older_versions:) | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-09-21 21:16:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def checksums | 
					
						
							| 
									
										
										
										
											2021-09-16 18:56:47 +01:00
										 |  |  |     tags = collector.tags.sort_by do |tag| | 
					
						
							| 
									
										
										
										
											2021-04-08 13:45:15 +01:00
										 |  |  |       version = tag.to_macos_version | 
					
						
							| 
									
										
										
										
											2021-02-04 13:30:16 -05:00
										 |  |  |       # Give arm64 bottles a higher priority so they are first | 
					
						
							| 
									
										
										
										
											2022-08-10 14:19:33 +01:00
										 |  |  |       priority = (tag.arch == :arm64) ? "2" : "1" | 
					
						
							| 
									
										
										
										
											2021-09-16 18:56:47 +01:00
										 |  |  |       "#{priority}.#{version}_#{tag}" | 
					
						
							| 
									
										
										
										
											2023-05-09 02:15:28 +02:00
										 |  |  |     rescue MacOSVersion::Error | 
					
						
							| 
									
										
										
										
											2020-12-07 15:43:44 +00:00
										 |  |  |       # Sort non-MacOS tags below MacOS tags. | 
					
						
							| 
									
										
										
										
											2021-09-16 18:56:47 +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| | 
					
						
							| 
									
										
										
										
											2021-09-16 18:56:47 +01:00
										 |  |  |       spec = collector.specification_for(tag) | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  |       { | 
					
						
							| 
									
										
										
										
											2021-09-16 18:56:47 +01:00
										 |  |  |         "tag"    => spec.tag.to_sym, | 
					
						
							|  |  |  |         "digest" => spec.checksum, | 
					
						
							|  |  |  |         "cellar" => spec.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 | 
					
						
							| 
									
										
										
										
											2022-06-29 17:48:21 -04:00
										 |  |  |   include OnSystem::MacOSAndLinux | 
					
						
							| 
									
										
										
										
											2020-12-08 08:43:11 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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" |