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

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)


19
20
21
22
23
24
# File 'utils/bottles.rb', line 19

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.



39
40
41
# File 'utils/bottles.rb', line 39

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.



49
50
51
# File 'utils/bottles.rb', line 49

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)


26
27
28
29
30
31
32
33
34
35
36
37
# File 'utils/bottles.rb', line 26

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.



76
77
78
79
80
81
82
83
84
# File 'utils/bottles.rb', line 76

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.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'utils/bottles.rb', line 95

def load_tab(formula)
  keg = Keg.new(formula.prefix)
  tabfile = keg/Tab::FILENAME
  bottle_json_path = formula.local_bottle_path&.sub(/\.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.



86
87
88
89
90
91
92
93
# File 'utils/bottles.rb', line 86

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.



43
44
45
46
47
# File 'utils/bottles.rb', line 43

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.



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

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(/\.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.



71
72
73
74
# File 'utils/bottles.rb', line 71

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

.tagObject

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.



9
10
11
# File 'extend/os/mac/utils/bottles.rb', line 9

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