Better handle brew bottle --only-json-tab bottles

- test them in `brew test-bot` (before we do so in homebrew/core)
- don't fail if we cannot find the tab/install receipt in a bottle
- cache listing the files in a bottle so we don't do it more times than
  necessary
- fix resolution of version and formula names from a bottle if we're
  getting them from a bottle without a tab/install receipt

This will need to be in a tagged release before we can ship tab-less
bottles to users.
This commit is contained in:
Mike McQuaid 2021-04-13 14:26:31 +01:00
parent 632e4d6579
commit 75592cbebc
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
3 changed files with 25 additions and 15 deletions

View File

@ -234,7 +234,7 @@ jobs:
- run: brew test-bot --only-cleanup-before
- run: brew test-bot --only-formulae --test-default-formula
- run: brew test-bot --only-formulae --only-json-tab --test-default-formula
test-everything:
name: test everything (macOS)

View File

@ -326,6 +326,8 @@ module Homebrew
local_filename = bottle_path.basename.to_s
tab_path = Utils::Bottles.receipt_path(f.local_bottle_path)
raise "This bottle does not contain the file INSTALL_RECEIPT.json: #{bottle_path}" unless tab_path
tab_json = Utils.safe_popen_read("tar", "xfO", f.local_bottle_path, tab_path)
tab = Tab.from_file_content(tab_json, tab_path)

View File

@ -40,32 +40,40 @@ module Utils
HOMEBREW_BOTTLES_EXTNAME_REGEX.match(filename).to_a
end
def bottle_file_list(bottle_file)
@bottle_file_list ||= {}
@bottle_file_list[bottle_file] ||= Utils.popen_read("tar", "-tzf", bottle_file)
.lines
.map(&:chomp)
end
def receipt_path(bottle_file)
path = Utils.popen_read("tar", "-tzf", bottle_file).lines.map(&:chomp).find do |line|
bottle_file_list(bottle_file).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
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}"
name = bottle_file_list(bottle_file).first.to_s.split("/").first
full_name = if (receipt_file_path = receipt_path(bottle_file))
receipt_file = Utils.popen_read("tar", "-xOzf", 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
def resolve_version(bottle_file)
PkgVersion.parse receipt_path(bottle_file).split("/").second
version = bottle_file_list(bottle_file).first.to_s.split("/").second
PkgVersion.parse(version)
end
def formula_contents(bottle_file,