Module: Utils::Bottles Private

Extended by:
T::Sig
Defined in:
utils/bottles.rb,
extend/os/mac/utils/bottles.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 bottles.

Defined Under Namespace

Classes: Collector, Tag, TagSpecification

Class Method Summary collapse

Class Method Details

.built_as?(f) ⇒ 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)


22
23
24
25
26
27
# File 'utils/bottles.rb', line 22

def built_as?(f)
  return false unless f.latest_version_installed?

  tab = Tab.for_keg(f.latest_installed_prefix)
  tab.built_as_bottle
end

.extname_tag_rebuild(filename) ⇒ 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.



42
43
44
# File 'utils/bottles.rb', line 42

def extname_tag_rebuild(filename)
  HOMEBREW_BOTTLES_EXTNAME_REGEX.match(filename).to_a
end

.file_from_bottle(bottle_file, file_path) ⇒ 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.



52
53
54
# File 'utils/bottles.rb', line 52

def file_from_bottle(bottle_file, file_path)
  Utils.popen_read("tar", "--extract", "--to-stdout", "--file", bottle_file, file_path)
end

.file_outdated?(f, file) ⇒ 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)


29
30
31
32
33
34
35
36
37
38
39
40
# File 'utils/bottles.rb', line 29

def file_outdated?(f, file)
  filename = file.basename.to_s
  return false if f.bottle.blank?

  bottle_ext, bottle_tag, = extname_tag_rebuild(filename)
  return false if bottle_ext.blank?
  return false if bottle_tag != tag.to_s

  bottle_url_ext, = extname_tag_rebuild(f.bottle.url)

  bottle_ext && bottle_url_ext && bottle_ext != bottle_url_ext
end

.formula_contents(bottle_file, name: resolve_formula_names(bottle_file)[0]) ⇒ 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.



79
80
81
82
83
84
85
86
87
# File 'utils/bottles.rb', line 79

def formula_contents(bottle_file,
                     name: resolve_formula_names(bottle_file)[0])
  bottle_version = resolve_version bottle_file
  formula_path = "#{name}/#{bottle_version}/.brew/#{name}.rb"
  contents = file_from_bottle(bottle_file, formula_path)
  raise BottleFormulaUnavailableError.new(bottle_file, formula_path) unless $CHILD_STATUS.success?

  contents
end

.load_tab(formula) ⇒ 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.



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'utils/bottles.rb', line 98

def load_tab(formula)
  keg = Keg.new(formula.prefix)
  tabfile = keg/Tab::FILENAME
  bottle_json_path = formula.local_bottle_path&.sub(/\.(\d+\.)?tar\.gz$/, ".json")

  if (tab_attributes = formula.bottle_tab_attributes.presence)
    Tab.from_file_content(tab_attributes.to_json, tabfile)
  elsif !tabfile.exist? && bottle_json_path&.exist?
    _, tag, = Utils::Bottles.extname_tag_rebuild(formula.local_bottle_path)
    bottle_hash = JSON.parse(File.read(bottle_json_path))
    tab_json = bottle_hash[formula.full_name]["bottle"]["tags"][tag]["tab"].to_json
    Tab.from_file_content(tab_json, tabfile)
  else
    Tab.for_keg(keg)
  end
end

.path_resolved_basename(root_url, name, checksum, filename) ⇒ 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.



89
90
91
92
93
94
95
96
# File 'utils/bottles.rb', line 89

def path_resolved_basename(root_url, name, checksum, filename)
  if root_url.match?(GitHubPackages::URL_REGEX)
    image_name = GitHubPackages.image_formula_name(name)
    ["#{image_name}/blobs/sha256:#{checksum}", filename&.github_packages]
  else
    filename&.url_encode
  end
end

.receipt_path(bottle_file) ⇒ 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.



46
47
48
49
50
# File 'utils/bottles.rb', line 46

def receipt_path(bottle_file)
  bottle_file_list(bottle_file).find do |line|
    line =~ %r{.+/.+/INSTALL_RECEIPT.json}
  end
end

.resolve_formula_names(bottle_file) ⇒ 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.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'utils/bottles.rb', line 56

def resolve_formula_names(bottle_file)
  name = bottle_file_list(bottle_file).first.to_s.split("/").first
  full_name = if (receipt_file_path = receipt_path(bottle_file))
    receipt_file = file_from_bottle(bottle_file, receipt_file_path)
    tap = Tab.from_file_content(receipt_file, "#{bottle_file}/#{receipt_file_path}").tap
    "#{tap}/#{name}" if tap.present? && !tap.core_tap?
  elsif (bottle_json_path = Pathname(bottle_file.sub(/\.(\d+\.)?tar\.gz$/, ".json"))) &&
        bottle_json_path.exist? &&
        (bottle_json_path_contents = bottle_json_path.read.presence) &&
        (bottle_json = JSON.parse(bottle_json_path_contents).presence) &&
        bottle_json.is_a?(Hash)
    bottle_json.keys.first.presence
  end
  full_name ||= name

  [name, full_name]
end

.resolve_version(bottle_file) ⇒ 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.



74
75
76
77
# File 'utils/bottles.rb', line 74

def resolve_version(bottle_file)
  version = bottle_file_list(bottle_file).first.to_s.split("/").second
  PkgVersion.parse(version)
end

.tag(symbol = nil) ⇒ 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.

Gets the tag for the running OS.



15
16
17
18
19
# File 'utils/bottles.rb', line 15

def tag(symbol = nil)
  return Utils::Bottles::Tag.from_symbol(symbol) if symbol.present?

  Utils::Bottles::Tag.new(system: MacOS.version.to_sym, arch: Hardware::CPU.arch)
end