Module: Homebrew::API::Bottle Private

Extended by:
T::Sig
Defined in:
api/bottle.rb,
extend/os/linux/api/bottle.rb

Overview

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

Helper functions for using the bottle JSON API.

Constant Summary collapse

GITHUB_PACKAGES_SHA256_REGEX =

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.

%r{#{GitHubPackages::URL_REGEX}.*/blobs/sha256:(?<sha256>\h{64})$}.freeze

Class Method Summary collapse

Class Method Details

.available?(name) ⇒ 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)


29
30
31
32
33
34
# File 'api/bottle.rb', line 29

def available?(name)
  fetch name
  true
rescue ArgumentError
  false
end

.bottle_api_pathString Also known as: generic_bottle_api_path

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
19
20
21
22
# File 'api/bottle.rb', line 16

def bottle_api_path
  return generic_bottle_api_path if
    Homebrew::EnvConfig.force_homebrew_on_linux? ||
    Homebrew::EnvConfig.force_homebrew_core_repo_on_linux?

  "bottle-linux"
end

.checksum_from_url(url) ⇒ 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:



62
63
64
65
66
67
# File 'api/bottle.rb', line 62

def checksum_from_url(url)
  match = url.match GITHUB_PACKAGES_SHA256_REGEX
  return if match.blank?

  match[:sha256]
end

.download_bottle(hash, tag) ⇒ 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:



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'api/bottle.rb', line 70

def download_bottle(hash, tag)
  bottle = hash["bottles"][tag]
  bottle ||= hash["bottles"]["all"]
  return if bottle.blank?

  sha256 = bottle["sha256"] || checksum_from_url(bottle["url"])
  bottle_filename = ::Bottle::Filename.new(hash["name"], hash["pkg_version"], tag, hash["rebuild"])

  resource = Resource.new hash["name"]
  resource.url bottle["url"]
  resource.sha256 sha256
  resource.version hash["pkg_version"]
  resource.downloader.resolved_basename = bottle_filename

  resource.fetch

  # Map the name of this formula to the local bottle path to allow the
  # formula to be loaded by passing just the name to `Formulary::factory`.
  Formulary.map_formula_name_to_local_bottle_path hash["name"], resource.downloader.cached_location
end

.fetch(name) ⇒ 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.

Parameters:

Returns:

  • (Hash)


24
25
26
# File 'api/bottle.rb', line 24

def fetch(name)
  Homebrew::API.fetch "#{bottle_api_path}/#{name}.json"
end

.fetch_bottles(name) ⇒ 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:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'api/bottle.rb', line 37

def fetch_bottles(name)
  hash = fetch(name)
  bottle_tag = Utils::Bottles.tag.to_s

  if !hash["bottles"].key?(bottle_tag) && !hash["bottles"].key?("all")
    odie "No bottle available for #{name} on the current OS"
  end

  download_bottle(hash, bottle_tag)

  hash["dependencies"].each do |dep_hash|
    existing_formula = begin
      Formulary.factory dep_hash["name"]
    rescue FormulaUnavailableError
      # The formula might not exist if it's not installed and homebrew/core isn't tapped
      nil
    end

    next if existing_formula.present? && existing_formula.latest_version_installed?

    download_bottle(dep_hash, bottle_tag)
  end
end