Class: Bottle

Inherits:
Object show all
Extended by:
Forwardable
Includes:
Downloadable
Defined in:
bottle.rb,
sorbet/rbi/dsl/bottle.rbi

Defined Under Namespace

Classes: Filename

Instance Attribute Summary collapse

Attributes included from Downloadable

#checksum, #mirrors, #phase

Instance Method Summary collapse

Methods included from Downloadable

#download_queue_message, #download_strategy, #downloaded!, #downloaded?, #downloading!, #extracting!, #fetched_size, #freeze, #initialize_dup, verification_cache, #verified!, #verifying!, #version

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_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Methods included from Context

current, current=, #debug?, #deferred_environment_expansion?, #quiet?, #verbose?, #with_context

Constructor Details

#initialize(formula, spec, tag = nil, name: nil, pkg_version: nil) ⇒ 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.

Parameters:



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'bottle.rb', line 95

def initialize(formula, spec, tag = nil, name: nil, pkg_version: nil)
  super()

  resource_name = T.let(nil, T.nilable(String))
  if formula
    name = formula.name
    pkg_version = formula.pkg_version
  else
    raise ArgumentError, "Bottle name is required" if name.nil?
    raise ArgumentError, "Bottle version is required" if pkg_version.nil?

    resource_name = name
  end

  @name = T.let(name, String)
  @pkg_version = T.let(pkg_version, PkgVersion)
  @resource = T.let(Resource.new(resource_name), Resource)
  @resource.owner = formula if formula
  @spec = spec

  tag_spec = spec.tag_specification_for(Utils::Bottles.tag(tag))

  odie "#{@name} tag specification for tag #{tag} is nil" if tag_spec.nil?

  @tag = T.let(tag_spec.tag, Utils::Bottles::Tag)
  @cellar = T.let(tag_spec.cellar, T.any(String, Symbol))
  @rebuild = T.let(spec.rebuild, Integer)

  @resource.version(@pkg_version.to_s)
  @resource.checksum = tag_spec.checksum

  @fetch_tab_retried = T.let(false, T::Boolean)

  root_url(spec.root_url, spec.root_url_specs)
end

Instance Attribute Details

#cellarString, Symbol (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:



78
79
80
# File 'bottle.rb', line 78

def cellar
  @cellar
end

#nameString (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:



69
70
71
# File 'bottle.rb', line 69

def name
  @name
end

#rebuildInteger (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:



81
82
83
# File 'bottle.rb', line 81

def rebuild
  @rebuild
end

#resourceResource (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:



72
73
74
# File 'bottle.rb', line 72

def resource
  @resource
end

#tagUtils::Bottles::Tag (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:



75
76
77
# File 'bottle.rb', line 75

def tag
  @tag
end

Instance Method Details

#bottle_sizeInteger?

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:



243
244
245
246
247
248
# File 'bottle.rb', line 243

def bottle_size
  resource = github_packages_manifest_resource
  return unless resource&.downloaded?

  resource.bottle_size
end

#cached_download(*args, &block) ⇒ T.untyped

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:

  • args (T.untyped)
  • block (T.untyped)

Returns:

  • (T.untyped)


10
# File 'sorbet/rbi/dsl/bottle.rbi', line 10

def cached_download(*args, &block); end

#clear_cachevoid

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.



195
196
197
198
199
# File 'bottle.rb', line 195

def clear_cache
  @resource.clear_cache
  github_packages_manifest_resource&.clear_cache
  @fetch_tab_retried = false
end

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

Returns:

  • (Boolean)


202
203
204
# File 'bottle.rb', line 202

def compatible_locations?
  @spec.compatible_locations?(tag: @tag)
end

#discard_corrupt_cached_downloadvoid

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.



179
180
181
182
183
184
185
186
187
# File 'bottle.rb', line 179

def discard_corrupt_cached_download
  expected_checksum = resource.checksum
  return if expected_checksum.nil?
  return unless cached_download.file?
  return if cached_download.sha256 == expected_checksum.hexdigest

  opoo "Removing corrupt cached download: #{cached_download.basename}"
  clear_cache
end

#download_queue_nameString

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:



372
# File 'bottle.rb', line 372

def download_queue_name = "#{name} (#{resource.version})"

#download_queue_typeString

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:



369
# File 'bottle.rb', line 369

def download_queue_type = "Bottle"

#downloaded_and_valid?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.

Returns:

  • (Boolean)


148
149
150
151
152
153
154
155
156
157
158
159
# File 'bottle.rb', line 148

def downloaded_and_valid?
  return false unless cached_download.file?

  resource_checksum = resource.checksum
  return false if resource_checksum.nil?

  downloader = resource.downloader
  return false unless downloader.is_a?(CurlGitHubPackagesDownloadStrategy)
  return false unless downloader.immutable_bottle_blob?

  downloader.bottle_blob_sha256 == resource_checksum.hexdigest
end

#downloader(*args, &block) ⇒ T.untyped

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:

  • args (T.untyped)
  • block (T.untyped)

Returns:

  • (T.untyped)


13
# File 'sorbet/rbi/dsl/bottle.rbi', line 13

def downloader(*args, &block); end

#fetch(verify_download_integrity: true, timeout: nil, quiet: false) ⇒ Pathname

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:

  • verify_download_integrity (Boolean) (defaults to: true)
  • timeout (Integer, Float, nil) (defaults to: nil)
  • quiet (Boolean) (defaults to: false)

Returns:



138
139
140
141
142
143
144
145
# File 'bottle.rb', line 138

def fetch(verify_download_integrity: true, timeout: nil, quiet: false)
  resource.fetch(verify_download_integrity:, timeout:, quiet:)
rescue DownloadError
  raise unless fallback_on_error?

  fetch_tab
  retry
end

#fetch_tab(timeout: nil, quiet: false) ⇒ 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.

Parameters:

  • timeout (Integer, Float, nil) (defaults to: nil)
  • quiet (Boolean) (defaults to: false)


218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'bottle.rb', line 218

def fetch_tab(timeout: nil, quiet: false)
  return unless (resource = github_packages_manifest_resource)

  begin
    # `$HOMEBREW_BOTTLE_DOMAIN` fallback is configured on the resource below.
    resource.fetch(timeout:, quiet:)
  rescue Resource::BottleManifest::Error
    raise if @fetch_tab_retried

    @fetch_tab_retried = true
    resource.clear_cache
    retry
  end
end

#filenameFilename

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:



275
# File 'bottle.rb', line 275

def filename = Filename.new(@name, @pkg_version, @tag, @spec.rebuild)

#github_packages_manifest_resourceResource::BottleManifest?

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:



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'bottle.rb', line 329

def github_packages_manifest_resource
  # `$HOMEBREW_BOTTLE_DOMAIN` may be a legacy flat-file mirror, so its
  # bottle resource does not necessarily use the GitHub Packages strategy.
  custom_bottle_domain = Homebrew::EnvConfig.bottle_domain_custom? &&
                         root_url == Homebrew::EnvConfig.bottle_domain
  return if @resource.download_strategy != CurlGitHubPackagesDownloadStrategy && !custom_bottle_domain

  @github_packages_manifest_resource ||= T.let(
    begin
      resource = Resource::BottleManifest.new(self)

      resource_version = @resource.version
      odie "resource version is nil" if resource_version.nil?

      version_rebuild = GitHubPackages.version_rebuild(resource_version, rebuild)
      resource.version(version_rebuild)

      image_name = GitHubPackages.image_formula_name(@name)
      image_tag = GitHubPackages.image_version_rebuild(version_rebuild)
      manifest_path = "#{image_name}/manifests/#{image_tag}"
      resource.url(
        "#{root_url}/#{manifest_path}",
        using:   CurlGitHubPackagesDownloadStrategy,
        headers: ["Accept: application/vnd.oci.image.index.v1+json"],
      )
      # Give a legacy mirror the first chance to serve the manifest. Many
      # contain only bottle archives, so retain GHCR as a fallback. By
      # contrast, `$HOMEBREW_ARTIFACT_DOMAIN` must provide an OCI registry
      # proxy for bottle blobs and manifests; the strategy rewrites the GHCR
      # URL for it.
      resource.mirror("#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}/#{manifest_path}") if custom_bottle_domain
      T.cast(resource.downloader, CurlGitHubPackagesDownloadStrategy).resolved_basename =
        "#{name}-#{version_rebuild}.bottle_manifest.json"
      resource
    end,
    T.nilable(Resource::BottleManifest),
  )
end

#installed_sizeInteger?

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:



251
252
253
254
255
256
# File 'bottle.rb', line 251

def installed_size
  resource = github_packages_manifest_resource
  return unless resource&.downloaded?

  resource.installed_size
end

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

Returns:



259
260
261
262
263
264
# File 'bottle.rb', line 259

def path_exec_files
  resource = github_packages_manifest_resource
  return unless resource&.downloaded?

  resource.path_exec_files
end

#sbom_supplementHash{String => Object}?

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:



267
268
269
270
271
272
# File 'bottle.rb', line 267

def sbom_supplement
  resource = github_packages_manifest_resource
  return unless resource&.downloaded_and_valid?

  resource.sbom_supplement
end

#skip_relocation?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 need to be relocated?

Returns:

  • (Boolean)


208
209
210
211
212
# File 'bottle.rb', line 208

def skip_relocation?
  attrs = tab_attributes
  tab = Tab.new(**attrs.transform_keys(&:to_sym)) unless attrs.empty?
  @spec.skip_relocation?(tag: @tag, tab:)
end

#stagevoid

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.



215
# File 'bottle.rb', line 215

def stage = with_corrupt_download_retry { downloader.stage }

#stage_from_download_queue(download, pour:) ⇒ 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.

Parameters:



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'bottle.rb', line 294

def stage_from_download_queue(download, pour:)
  return unless pour

  bottle_tmp_keg = staged_path_from_download_queue
  bottle_poured_file = staged_path_from_download_queue_marker

  # Stay quiet on the retry: the download queue is redrawing its own
  # progress lines while this runs in a worker thread.
  with_corrupt_download_retry(quiet: true) do
    HOMEBREW_TEMP_CELLAR.mkpath

    next if bottle_poured_file.exist?

    FileUtils.rm(bottle_poured_file) if bottle_poured_file.symlink?
    FileUtils.rm_r(bottle_tmp_keg) if bottle_tmp_keg.directory?

    UnpackStrategy.detect(download, prioritize_extension: true)
                  .extract_nestedly(to: HOMEBREW_TEMP_CELLAR)

    # Create a separate file to mark a completed extraction. This avoids
    # a potential race condition if a user interrupts the install.
    # We use a symlink to easily check that both this extra status file
    # and the real extracted directory exist via `Pathname#exist?`.
    FileUtils.ln_s(bottle_tmp_keg, bottle_poured_file)
  # Catch any exception type here to clean up partial queued extractions.
  rescue Exception # rubocop:disable Lint/RescueException
    ignore_interrupts do
      FileUtils.rm_r(bottle_tmp_keg) if bottle_tmp_keg.directory?
      bottle_tmp_keg.parent.rmdir_if_possible
    end
    raise
  end
end

#stage_from_download_queue?(_download, pour:) ⇒ 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)


289
290
291
# File 'bottle.rb', line 289

def stage_from_download_queue?(_download, pour:)
  pour
end

#staged_path_from_download_queuePathname

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:



278
279
280
281
# File 'bottle.rb', line 278

def staged_path_from_download_queue
  bottle_filename = filename
  HOMEBREW_TEMP_CELLAR/bottle_filename.name/bottle_filename.version.to_s
end

#staged_path_from_download_queue_markerPathname

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:



284
285
286
# File 'bottle.rb', line 284

def staged_path_from_download_queue_marker
  Pathname("#{staged_path_from_download_queue}.poured")
end

#tab_attributesHash{String => T.untyped}

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:



234
235
236
237
238
239
240
# File 'bottle.rb', line 234

def tab_attributes
  if (resource = github_packages_manifest_resource) && resource.downloaded?
    return resource.tab
  end

  {}
end

#total_sizeInteger?

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:



190
191
192
# File 'bottle.rb', line 190

def total_size
  bottle_size || super
end

#url(*args, &block) ⇒ T.untyped

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:

  • args (T.untyped)
  • block (T.untyped)

Returns:

  • (T.untyped)


16
# File 'sorbet/rbi/dsl/bottle.rbi', line 16

def url(*args, &block); end

#verify_download_integrity(*args, &block) ⇒ T.untyped

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:

  • args (T.untyped)
  • block (T.untyped)

Returns:

  • (T.untyped)


19
# File 'sorbet/rbi/dsl/bottle.rbi', line 19

def verify_download_integrity(*args, &block); end

#with_corrupt_download_retry(quiet: false, &_block) ⇒ 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.

A cached immutable blob is trusted without rehashing it (see downloaded_and_valid?), so a locally corrupted bottle would fail to extract on every run: verify it after a failed extraction and, when it was indeed corrupt, discard it and retry with a freshly downloaded one.

Parameters:

  • quiet (Boolean) (defaults to: false)
  • _block (T.proc.void)


166
167
168
169
170
171
172
173
174
175
176
# File 'bottle.rb', line 166

def with_corrupt_download_retry(quiet: false, &_block)
  yield
rescue
  discard_corrupt_cached_download
  raise if cached_download.exist?

  downloading!
  fetch(quiet:)
  extracting!
  yield
end