Class: Utils::Bottles

Inherits:
Object
  • Object
show all
Defined in:
brew/Library/Homebrew/utils/bottles.rb,
brew/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

Returns:

  • (Boolean)


13
14
15
16
17
18
# File 'brew/Library/Homebrew/utils/bottles.rb', line 13

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

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
# File 'brew/Library/Homebrew/utils/bottles.rb', line 20

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



62
63
64
65
66
67
68
69
70
# File 'brew/Library/Homebrew/utils/bottles.rb', line 62

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



30
31
32
# File 'brew/Library/Homebrew/utils/bottles.rb', line 30

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

.receipt_path(bottle_file) ⇒ Object



34
35
36
37
38
39
40
41
# File 'brew/Library/Homebrew/utils/bottles.rb', line 34

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



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

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



58
59
60
# File 'brew/Library/Homebrew/utils/bottles.rb', line 58

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

.tagObject



9
10
11
# File 'brew/Library/Homebrew/utils/bottles.rb', line 9

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