From ebda92f908af192d3143aad22784ec9d4e85ee06 Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Mon, 21 Mar 2022 18:22:36 +0000 Subject: [PATCH] Revert "Binary patching of build prefixes " --- Library/Homebrew/formula_installer.rb | 8 ---- Library/Homebrew/keg.rb | 2 - Library/Homebrew/keg_relocate.rb | 39 ---------------- Library/Homebrew/software_spec.rb | 11 ++--- .../keg_relocate/binary_relocation_spec.rb | 44 ------------------- 5 files changed, 3 insertions(+), 101 deletions(-) delete mode 100644 Library/Homebrew/test/keg_relocate/binary_relocation_spec.rb diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 6e5848c372..288fc09eff 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -1228,14 +1228,6 @@ class FormulaInstaller keg = Keg.new(formula.prefix) skip_linkage = formula.bottle_specification.skip_relocation? keg.replace_placeholders_with_locations tab.changed_files, skip_linkage: skip_linkage - - cellar = formula.bottle_specification.tag_to_cellar(Utils::Bottles.tag) - return if [:any, :any_skip_relocation].include?(cellar) - - prefix = Pathname(cellar).parent.to_s - return if cellar == HOMEBREW_CELLAR.to_s && prefix == HOMEBREW_PREFIX.to_s - - keg.relocate_build_prefix(keg, prefix, HOMEBREW_PREFIX) end sig { params(output: T.nilable(String)).void } diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index 18e5d1ac23..6287d60708 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -529,8 +529,6 @@ class Keg elf_files end - def codesign_patched_binary(_binary_file); end - private def resolve_any_conflicts(dst, dry_run: false, verbose: false, overwrite: false) diff --git a/Library/Homebrew/keg_relocate.rb b/Library/Homebrew/keg_relocate.rb index e97b255967..197b01a942 100644 --- a/Library/Homebrew/keg_relocate.rb +++ b/Library/Homebrew/keg_relocate.rb @@ -165,45 +165,6 @@ class Keg changed_files end - def relocate_build_prefix(keg, old_prefix, new_prefix) - each_unique_file_matching(old_prefix) do |file| - # Skip files which are not binary, as they do not need null padding. - next unless keg.binary_file?(file) - - # Skip sharballs, which appear to break if patched. - next if file.text_executable? - - # Split binary by null characters into array and substitute new prefix for old prefix. - # Null padding is added if the new string is too short. - file.ensure_writable do - binary = File.binread file - odebug "Replacing build prefix in: #{file}" - binary_strings = binary.split(/#{NULL_BYTE}/o, -1) - match_indices = binary_strings.each_index.select { |i| binary_strings[i].include?(old_prefix) } - - # Only perform substitution on strings which match prefix regex. - match_indices.each do |i| - s = binary_strings[i] - binary_strings[i] = s.gsub(old_prefix, new_prefix) - .ljust(s.size, NULL_BYTE) - end - - # Rejoin strings by null bytes. - patched_binary = binary_strings.join(NULL_BYTE) - if patched_binary.size != binary.size - raise <<~EOS - Patching failed! Original and patched binary sizes do not match. - Original size: #{binary.size} - Patched size: #{patched_binary.size} - EOS - end - - file.atomic_write patched_binary - end - codesign_patched_binary(file) - end - end - def detect_cxx_stdlibs(_options = {}) [] end diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index e3e549fa23..f6eb79b225 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -473,8 +473,6 @@ class Bottle end class BottleSpecification - RELOCATABLE_CELLARS = [:any, :any_skip_relocation].freeze - extend T::Sig attr_rw :rebuild @@ -520,15 +518,12 @@ class BottleSpecification def compatible_locations?(tag: Utils::Bottles.tag) cellar = tag_to_cellar(tag) - return true if RELOCATABLE_CELLARS.include?(cellar) + return true if [:any, :any_skip_relocation].include?(cellar) prefix = Pathname(cellar).parent.to_s - cellar_relocatable = cellar.size >= HOMEBREW_CELLAR.to_s.size && ENV["HOMEBREW_RELOCATE_BUILD_PREFIX"] - prefix_relocatable = prefix.size >= HOMEBREW_PREFIX.to_s.size && ENV["HOMEBREW_RELOCATE_BUILD_PREFIX"] - - compatible_cellar = cellar == HOMEBREW_CELLAR.to_s || cellar_relocatable - compatible_prefix = prefix == HOMEBREW_PREFIX.to_s || prefix_relocatable + compatible_cellar = cellar == HOMEBREW_CELLAR.to_s + compatible_prefix = prefix == HOMEBREW_PREFIX.to_s compatible_cellar && compatible_prefix end diff --git a/Library/Homebrew/test/keg_relocate/binary_relocation_spec.rb b/Library/Homebrew/test/keg_relocate/binary_relocation_spec.rb deleted file mode 100644 index 29bf25703a..0000000000 --- a/Library/Homebrew/test/keg_relocate/binary_relocation_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -# typed: false -# frozen_string_literal: true - -require "keg_relocate" - -describe Keg do - subject(:keg) { described_class.new(HOMEBREW_CELLAR/"foo/1.0.0") } - - let(:dir) { HOMEBREW_CELLAR/"foo/1.0.0" } - let(:newdir) { HOMEBREW_CELLAR/"foo" } - let(:binary_file) { dir/"file.bin" } - - before do - dir.mkpath - end - - def setup_binary_file - binary_file.atomic_write <<~EOS - \x00#{dir}\x00 - EOS - end - - describe "#relocate_build_prefix" do - specify "replace prefix in binary files" do - setup_binary_file - - keg.relocate_build_prefix(keg, dir, newdir) - - old_prefix_matches = Set.new - keg.each_unique_file_matching(dir) do |file| - old_prefix_matches << file - end - - expect(old_prefix_matches.size).to eq 0 - - new_prefix_matches = Set.new - keg.each_unique_file_matching(newdir) do |file| - new_prefix_matches << file - end - - expect(new_prefix_matches.size).to eq 1 - end - end -end