diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f587c62959..a21c1edae9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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) diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index f7936128e6..7c591602d8 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -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) diff --git a/Library/Homebrew/utils/bottles.rb b/Library/Homebrew/utils/bottles.rb index 4b13056151..1262b7161a 100644 --- a/Library/Homebrew/utils/bottles.rb +++ b/Library/Homebrew/utils/bottles.rb @@ -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,