Module: Utils::Bottles Private

Defined in:
Library/Homebrew/utils/bottles.rb,
Library/Homebrew/extend/os/mac/utils/bottles.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Helper functions for bottles.

Defined Under Namespace

Modules: Bintray Classes: Collector

Class Method Summary collapse

Class Method Details

.built_as?(f) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

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

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

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

.file_outdated?(f, file) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

22
23
24
25
26
27
28
29
30
# File 'Library/Homebrew/utils/bottles.rb', line 22

def file_outdated?(f, file)
  filename = file.basename.to_s
  return unless f.bottle && filename.match(Pathname::BOTTLE_EXTNAME_RX)

  bottle_ext = filename[native_regex, 1]
  bottle_url_ext = f.bottle.url[native_regex, 1]

  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. You should avoid using this method if possible, as it may be removed or be changed in the future.


64
65
66
67
68
69
70
71
72
# File 'Library/Homebrew/utils/bottles.rb', line 64

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 = Utils.popen_read "tar", "-xOzf", bottle_file, formula_path
  raise BottleFormulaUnavailableError.new(bottle_file, formula_path) unless $CHILD_STATUS.success?

  contents
end

.native_regexObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


32
33
34
# File 'Library/Homebrew/utils/bottles.rb', line 32

def native_regex
  /(\.#{Regexp.escape(tag.to_s)}\.bottle\.(\d+\.)?tar\.gz)$/o
end

.receipt_path(bottle_file) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


36
37
38
39
40
41
42
43
# File 'Library/Homebrew/utils/bottles.rb', line 36

def receipt_path(bottle_file)
  path = Utils.popen_read("tar", "-tzf", bottle_file).lines.map(&:chomp).find do |line|
    line =~ %r{.+/.+/INSTALL_RECEIPT.json}
  end
  raise "This bottle does not contain the file INSTALL_RECEIPT.json: #{bottle_file}" unless path

  path
end

.resolve_formula_names(bottle_file) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'Library/Homebrew/utils/bottles.rb', line 45

def resolve_formula_names(bottle_file)
  receipt_file_path = receipt_path bottle_file
  receipt_file = Utils.popen_read("tar", "-xOzf", bottle_file, receipt_file_path)
  name = receipt_file_path.split("/").first
  tap = Tab.from_file_content(receipt_file, "#{bottle_file}/#{receipt_file_path}").tap

  full_name = if tap.nil? || tap.core_tap?
    name
  else
    "#{tap}/#{name}"
  end

  [name, full_name]
end

.resolve_version(bottle_file) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


60
61
62
# File 'Library/Homebrew/utils/bottles.rb', line 60

def resolve_version(bottle_file)
  PkgVersion.parse receipt_path(bottle_file).split("/").second
end

.tagObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


11
12
13
# File 'Library/Homebrew/utils/bottles.rb', line 11

def tag
  @tag ||= "#{ENV["HOMEBREW_PROCESSOR"]}_#{ENV["HOMEBREW_SYSTEM"]}".downcase.to_sym
end