Class: BottleSpecification
- Defined in:
- bottle_specification.rb
Direct Known Subclasses
Constant Summary collapse
- ANY_CELLAR =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
Relocatable cellar using placeholders, e.g.
@@HOMEBREW_PREFIX@@. Requires relocating text files and binaries. :any- ANY_SKIP_RELOCATION_CELLAR =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
Relocatable cellar using placeholders, e.g.
@@HOMEBREW_PREFIX@@. Does not need to relocate binaries but still relocates text files. :any_skip_relocation- RELOCATABLE_CELLARS =
T.let([ANY_CELLAR, ANY_SKIP_RELOCATION_CELLAR].freeze, T::Array[Symbol])
- SHA256_REGEX =
/\A[a-f0-9]{64}\z/i
Instance Attribute Summary collapse
- #collector ⇒ Utils::Bottles::Collector readonly private
- #repository ⇒ String readonly private
- #root_url_specs ⇒ Hash{Symbol => T.untyped} readonly private
- #tap ⇒ Tap? private
Class Method Summary collapse
-
.compatible_locations? ⇒ Boolean
private
Whether bottles built in the default prefix can be installed here.
Instance Method Summary collapse
- #checksums ⇒ Array<Hash> private
- #compatible_locations?(tag: Utils::Bottles.tag, built_prefix: nil, padded_prefix: false) ⇒ Boolean private
- #initialize ⇒ void constructor private
-
#manifest_sha256(val = nil) ⇒ String?
private
The SHA-256 of the GitHub Packages image index that lists every bottle in this block.
- #rebuild(val = nil) ⇒ Integer private
- #root_url(var = nil, specs = {}) ⇒ String private
-
#sha256(hash) ⇒ void
private
Checksum methods in the DSL's bottle block take a Hash, which indicates the platform the checksum applies on.
-
#skip_relocation?(tag: Utils::Bottles.tag, tab: nil) ⇒ Boolean
private
Does the Bottle this BottleSpecification belongs to need to be relocated?.
- #tag?(tag, no_older_versions: false) ⇒ Boolean private
- #tag_specification_for(tag, no_older_versions: false) ⇒ Utils::Bottles::TagSpecification? private
- #tag_to_cellar(tag = Utils::Bottles.tag) ⇒ Symbol, String private
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Constructor Details
#initialize ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
34 35 36 37 38 39 40 41 |
# File 'bottle_specification.rb', line 34 def initialize @rebuild = T.let(0, Integer) @manifest_sha256 = T.let(nil, T.nilable(String)) @repository = T.let(Homebrew::DEFAULT_REPOSITORY, String) @collector = T.let(Utils::Bottles::Collector.new, Utils::Bottles::Collector) @root_url_specs = T.let({}, T::Hash[Symbol, T.untyped]) @root_url = T.let(nil, T.nilable(String)) end |
Instance Attribute Details
#collector ⇒ Utils::Bottles::Collector (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
25 26 27 |
# File 'bottle_specification.rb', line 25 def collector @collector end |
#repository ⇒ String (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
31 32 33 |
# File 'bottle_specification.rb', line 31 def repository @repository end |
#root_url_specs ⇒ Hash{Symbol => T.untyped} (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
28 29 30 |
# File 'bottle_specification.rb', line 28 def root_url_specs @root_url_specs end |
#tap ⇒ Tap?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
22 23 24 |
# File 'bottle_specification.rb', line 22 def tap @tap end |
Class Method Details
.compatible_locations? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Whether bottles built in the default prefix can be installed here.
102 |
# File 'bottle_specification.rb', line 102 def self.compatible_locations? = new.compatible_locations? |
Instance Method Details
#checksums ⇒ Array<Hash>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'bottle_specification.rb', line 191 def checksums = collector..sort_by do |tag| version = tag.to_macos_version # Give `arm64` bottles a higher priority so they are first. priority = (tag.arch == :arm64) ? 3 : 2 "#{priority}.#{version}_#{tag}" rescue MacOSVersion::Error # Sort non-macOS tags below macOS tags, and arm64 tags before other tags. priority = (tag.arch == :arm64) ? 1 : 0 "#{priority}.#{tag}" end .reverse.map do |tag| spec = collector.specification_for(tag) odie "Specification for tag #{tag} is nil" if spec.nil? { "tag" => spec.tag.to_sym, "digest" => spec.checksum, "cellar" => spec.cellar, } end end |
#compatible_locations?(tag: Utils::Bottles.tag, built_prefix: nil, padded_prefix: false) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'bottle_specification.rb', line 108 def compatible_locations?(tag: Utils::Bottles.tag, built_prefix: nil, padded_prefix: false) return false if padded_prefix && built_prefix.nil? cellar = padded_prefix ? "#{built_prefix}/Cellar" : tag_to_cellar(tag) return true if RELOCATABLE_CELLARS.include?(cellar) prefix = Pathname(cellar.to_s).parent.to_s # Raw prefix strings are patched in place, so the byte length decides. relocatable = !Homebrew::EnvConfig.no_relocate_build_prefix? cellar_relocatable = relocatable && cellar.to_s.bytesize >= HOMEBREW_CELLAR.to_s.bytesize prefix_relocatable = relocatable && prefix.bytesize >= HOMEBREW_PREFIX.to_s.bytesize compatible_cellar = cellar == HOMEBREW_CELLAR.to_s || cellar_relocatable compatible_prefix = prefix == HOMEBREW_PREFIX.to_s || prefix_relocatable compatible_cellar && compatible_prefix end |
#manifest_sha256(val = nil) ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
The SHA-256 of the GitHub Packages image index that lists every bottle in this block. The index is fetched by this digest, not by its mutable tag, and checked against it.
52 53 54 55 56 57 58 |
# File 'bottle_specification.rb', line 52 def manifest_sha256(val = nil) return @manifest_sha256 if val.nil? odie "Invalid manifest_sha256: #{val}" unless val.match?(SHA256_REGEX) @manifest_sha256 = val.downcase end |
#rebuild(val = nil) ⇒ Integer
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
44 45 46 |
# File 'bottle_specification.rb', line 44 def rebuild(val = nil) val.nil? ? @rebuild : @rebuild = val end |
#root_url(var = nil, specs = {}) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'bottle_specification.rb', line 61 def root_url(var = nil, specs = {}) if var.nil? @root_url ||= if (github_packages_url = GitHubPackages.root_url_if_match(Homebrew::EnvConfig.bottle_domain)) github_packages_url else Homebrew::EnvConfig.bottle_domain end else @root_url = if (github_packages_url = GitHubPackages.root_url_if_match(var)) github_packages_url else var end @root_url_specs.merge!(specs) @root_url end end |
#sha256(hash) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
Checksum methods in the DSL's bottle block take
a Hash, which indicates the platform the checksum applies on.
Example bottle block syntax:
bottle do
sha256 cellar: :any_skip_relocation, big_sur: "69489ae397e4645..."
sha256 cellar: :any, monterey: "449de5ea35d0e94..."
end
The JSON API also passes manifest_sha256:, the SHA-256 of that bottle's
own GitHub Packages manifest, which is then fetched in place of the index.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'bottle_specification.rb', line 154 def sha256(hash) manifest_sha256 = hash[:manifest_sha256] # find new `sha256 big_sur: "69489ae397e4645..."` format tag, digest = hash.find do |key, value| next if key == :manifest_sha256 # Don't use `odie` in this case. We want to be able to catch this exception # in runtime when getting committed version info in formula auditor raise LegacyDSLError.new(:sha256, hash) if key.is_a?(String) && key.match?(SHA256_REGEX) && value.is_a?(Symbol) key.is_a?(Symbol) && value.is_a?(String) && value.match?(SHA256_REGEX) end odie "Invalid sha256 hash: #{digest}" if !tag || !digest tag = Utils::Bottles::Tag.from_symbol(T.cast(tag, Symbol)) cellar = hash[:cellar] || tag.default_cellar if manifest_sha256 odie "Invalid manifest_sha256: #{manifest_sha256}" unless manifest_sha256.match?(SHA256_REGEX) manifest_checksum = Checksum.new(manifest_sha256.to_s) end collector.add(tag, checksum: Checksum.new(digest.to_s), cellar:, manifest_checksum:) end |
#skip_relocation?(tag: Utils::Bottles.tag, tab: nil) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Does the Bottle this BottleSpecification belongs to need to be relocated?
This will always return false on Linux unless a tab is provided that
reports the bottle was built with Homebrew 5.1.15 or newer. The caller must
make sure that the provided tab is for the requested tag.
134 135 136 137 |
# File 'bottle_specification.rb', line 134 def skip_relocation?(tag: Utils::Bottles.tag, tab: nil) spec = collector.specification_for(tag) spec&.cellar == ANY_SKIP_RELOCATION_CELLAR end |
#tag?(tag, no_older_versions: false) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
140 141 142 |
# File 'bottle_specification.rb', line 140 def tag?(tag, no_older_versions: false) collector.tag?(tag, no_older_versions:) end |
#tag_specification_for(tag, no_older_versions: false) ⇒ Utils::Bottles::TagSpecification?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
186 187 188 |
# File 'bottle_specification.rb', line 186 def tag_specification_for(tag, no_older_versions: false) collector.specification_for(tag, no_older_versions:) end |
#tag_to_cellar(tag = Utils::Bottles.tag) ⇒ Symbol, String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
91 92 93 94 95 96 97 98 |
# File 'bottle_specification.rb', line 91 def tag_to_cellar(tag = Utils::Bottles.tag) spec = collector.specification_for(tag) if spec.present? spec.cellar else tag.default_cellar end end |