Class: BottleSpecification Private

Inherits:
Object show all
Includes:
OS::Linux::BottleSpecification, Utils::Output::Mixin
Defined in:
bottle_specification.rb

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Constant Summary collapse

RELOCATABLE_CELLARS =

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.

[:any, :any_skip_relocation].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_outdated, #pretty_uninstalled, #pretty_upgradable

Constructor Details

#initializevoid

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
25
26
27
28
# File 'bottle_specification.rb', line 22

def initialize
  @rebuild = T.let(0, Integer)
  @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

#collectorUtils::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.



13
14
15
# File 'bottle_specification.rb', line 13

def collector
  @collector
end

#repositoryString (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.

Returns:



19
20
21
# File 'bottle_specification.rb', line 19

def repository
  @repository
end

#root_url_specsHash{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.

Returns:



16
17
18
# File 'bottle_specification.rb', line 16

def root_url_specs
  @root_url_specs
end

#tapTap?

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.

Returns:



10
11
12
# File 'bottle_specification.rb', line 10

def tap
  @tap
end

Instance Method Details

#checksumsArray<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.

Returns:



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'bottle_specification.rb', line 146

def checksums
  tags = collector.tags.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
  tags.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) ⇒ 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.

Parameters:

Returns:

  • (Boolean)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'bottle_specification.rb', line 76

def compatible_locations?(tag: Utils::Bottles.tag)
  cellar = tag_to_cellar(tag)

  return true if RELOCATABLE_CELLARS.include?(cellar)

  prefix = Pathname(cellar.to_s).parent.to_s

  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?

  compatible_cellar = cellar == HOMEBREW_CELLAR.to_s || cellar_relocatable
  compatible_prefix = prefix == HOMEBREW_PREFIX.to_s || prefix_relocatable

  compatible_cellar && compatible_prefix
end

#rebuild(val = T.unsafe(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.

Parameters:

  • val (Integer) (defaults to: T.unsafe(nil))

Returns:



31
32
33
# File 'bottle_specification.rb', line 31

def rebuild(val = T.unsafe(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.

Parameters:

  • var (String, nil) (defaults to: nil)
  • specs (Hash{Symbol => T.untyped}) (defaults to: {})

Returns:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'bottle_specification.rb', line 36

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, catalina: "449de5ea35d0e94..." end

Parameters:



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'bottle_specification.rb', line 116

def sha256(hash)
  sha256_regex = /^[a-f0-9]{64}$/i

  # find new `sha256 big_sur: "69489ae397e4645..."` format
  tag, digest = hash.find do |key, value|
    # 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

  collector.add(tag, checksum: Checksum.new(digest.to_s), cellar:)
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.

Parameters:

Returns:

  • (Boolean)


98
99
100
101
# File 'bottle_specification.rb', line 98

def skip_relocation?(tag: Utils::Bottles.tag, tab: nil)
  spec = collector.specification_for(tag)
  spec&.cellar == :any_skip_relocation
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.

Parameters:

Returns:

  • (Boolean)


104
105
106
# File 'bottle_specification.rb', line 104

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.

Parameters:

Returns:



141
142
143
# File 'bottle_specification.rb', line 141

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.

Parameters:

Returns:



66
67
68
69
70
71
72
73
# File 'bottle_specification.rb', line 66

def tag_to_cellar(tag = Utils::Bottles.tag)
  spec = collector.specification_for(tag)
  if spec.present?
    spec.cellar
  else
    tag.default_cellar
  end
end