From 33e1255f6572e7e6159a0e9ead5e0e738ff04c0d Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Tue, 11 May 2021 03:08:59 +0100 Subject: [PATCH] formula_installer: write tab when pouring local --only-json-tab bottles --- Library/Homebrew/formula_installer.rb | 22 +++++++++------------- Library/Homebrew/utils/bottles.rb | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 6fb7332e80..c013e1fbb1 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -1142,21 +1142,9 @@ class FormulaInstaller downloader.stage end - keg = Keg.new(formula.prefix) Tab.clear_cache - tab = if (tab_attributes = formula.bottle_tab_attributes.presence) - Tab.from_file_content(tab_attributes.to_json, keg/Tab::FILENAME) - else - Tab.for_keg(keg) - end - - skip_linkage = formula.bottle_specification.skip_relocation? - # TODO: Remove `with_env` when bottles are built with RPATH relocation enabled - # https://github.com/Homebrew/brew/issues/11329 - with_env(HOMEBREW_RELOCATE_RPATHS: "1") do - keg.replace_placeholders_with_locations tab.changed_files, skip_linkage: skip_linkage - end + tab = Utils::Bottles.load_tab(formula) # fill in missing/outdated parts of the tab # keep in sync with Tab#to_bottle_json @@ -1175,6 +1163,14 @@ class FormulaInstaller tab.source["tap_git_head"] = formula.tap&.git_head tab.tap = formula.tap tab.write + + keg = Keg.new(formula.prefix) + skip_linkage = formula.bottle_specification.skip_relocation? + # TODO: Remove `with_env` when bottles are built with RPATH relocation enabled + # https://github.com/Homebrew/brew/issues/11329 + with_env(HOMEBREW_RELOCATE_RPATHS: "1") do + keg.replace_placeholders_with_locations tab.changed_files, skip_linkage: skip_linkage + end end sig { params(output: T.nilable(String)).void } diff --git a/Library/Homebrew/utils/bottles.rb b/Library/Homebrew/utils/bottles.rb index 4e809b1bec..43c89e27cd 100644 --- a/Library/Homebrew/utils/bottles.rb +++ b/Library/Homebrew/utils/bottles.rb @@ -92,6 +92,23 @@ module Utils end end + def load_tab(formula) + keg = Keg.new(formula.prefix) + tabfile = keg/Tab::FILENAME + bottle_json_path = formula.local_bottle_path&.sub(/\.tar\.gz$/, ".json") + + if (tab_attributes = formula.bottle_tab_attributes.presence) + Tab.from_file_content(tab_attributes.to_json, tabfile) + elsif !tabfile.exist? && bottle_json_path&.exist? + _, tag, = Utils::Bottles.extname_tag_rebuild(formula.local_bottle_path) + bottle_hash = JSON.parse(File.read(bottle_json_path)) + tab_json = bottle_hash[formula.full_name]["bottle"]["tags"][tag]["tab"].to_json + Tab.from_file_content(tab_json, tabfile) + else + Tab.for_keg(keg) + end + end + private def bottle_file_list(bottle_file)