Class: Utils::Bottles

Inherits:
Object
  • Object
show all
Defined in:
Library/Homebrew/utils/bottles.rb,
Library/Homebrew/extend/os/mac/utils/bottles.rb

Defined Under Namespace

Classes: Bintray, Collector

Class Method Summary collapse

Class Method Details

.built_as?(f) ⇒ Boolean



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

def built_as?(f)
  return false unless f.installed?
  tab = Tab.for_keg(f.installed_prefix)
  tab.built_as_bottle
end

.file_outdated?(f, file) ⇒ Boolean



17
18
19
20
21
22
23
24
25
# File 'Library/Homebrew/utils/bottles.rb', line 17

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



58
59
60
61
62
63
64
65
# File 'Library/Homebrew/utils/bottles.rb', line 58

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



27
28
29
# File 'Library/Homebrew/utils/bottles.rb', line 27

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

.receipt_path(bottle_file) ⇒ Object



31
32
33
34
35
36
37
# File 'Library/Homebrew/utils/bottles.rb', line 31

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



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'Library/Homebrew/utils/bottles.rb', line 39

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

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

  [name, full_name]
end

.resolve_version(bottle_file) ⇒ Object



54
55
56
# File 'Library/Homebrew/utils/bottles.rb', line 54

def resolve_version(bottle_file)
  PkgVersion.parse receipt_path(bottle_file).split("/")[1]
end

.tagObject



7
8
9
# File 'Library/Homebrew/utils/bottles.rb', line 7

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