From 043719383b87930532c8c47cb37c11b337aca797 Mon Sep 17 00:00:00 2001 From: rmnull Date: Sat, 8 Aug 2020 06:41:51 +0530 Subject: [PATCH] remove code using patchelf, remove HOMEBREW_PATCHELF_RB var --- Library/Homebrew/diagnostic.rb | 2 +- Library/Homebrew/os/linux/elf.rb | 91 +------------------ Library/Homebrew/os/linux/global.rb | 3 - .../Homebrew/test/os/linux/pathname_spec.rb | 2 +- 4 files changed, 6 insertions(+), 92 deletions(-) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 63780d4fab30f..82a511d193054 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -691,7 +691,7 @@ def check_git_status # these will result in uncommitted gems. if path == HOMEBREW_REPOSITORY - next if ENV["HOMEBREW_SORBET"] || ENV["HOMEBREW_PATCHELF_RB"] + next if ENV["HOMEBREW_SORBET"] end message ||= "" diff --git a/Library/Homebrew/os/linux/elf.rb b/Library/Homebrew/os/linux/elf.rb index 0d6794d25256c..620c4e197aa9a 100644 --- a/Library/Homebrew/os/linux/elf.rb +++ b/Library/Homebrew/os/linux/elf.rb @@ -71,41 +71,19 @@ def binary_executable? def rpath return @rpath if defined? @rpath - @rpath = if HOMEBREW_PATCHELF_RB - rpath_using_patchelf_rb - else - rpath_using_patchelf - end + @rpath = rpath_using_patchelf_rb end def interpreter return @interpreter if defined? @interpreter - @interpreter = if HOMEBREW_PATCHELF_RB - patchelf_patcher.interpreter - elsif (patchelf = DevelopmentTools.locate "patchelf") - interp = Utils.popen_read(patchelf, "--print-interpreter", to_s, err: :out).strip - $CHILD_STATUS.success? ? interp : nil - elsif (file = DevelopmentTools.locate("file")) - output = Utils.popen_read(file, "-L", "-b", to_s, err: :out).strip - output[/^ELF.*, interpreter (.+?), /, 1] - else - raise "Please install either patchelf or file." - end + @interpreter = patchelf_patcher.interpreter end def dynamic_elf? return @dynamic_elf if defined? @dynamic_elf - @dynamic_elf = if HOMEBREW_PATCHELF_RB - patchelf_patcher.elf.segment_by_type(:DYNAMIC).present? - elsif which "readelf" - Utils.popen_read("readelf", "-l", to_path).include?(" DYNAMIC ") - elsif which "file" - !Utils.popen_read("file", "-L", "-b", to_path)[/dynamic|shared/].nil? - else - raise "Please install either readelf (from binutils) or file." - end + @dynamic_elf = patchelf_patcher.elf.segment_by_type(:DYNAMIC).present? end class Metadata @@ -139,81 +117,20 @@ def initialize(path) def needed_libraries(path) return [nil, []] unless path.dynamic_elf? - if HOMEBREW_PATCHELF_RB - needed_libraries_using_patchelf_rb path - elsif DevelopmentTools.locate "readelf" - needed_libraries_using_readelf path - elsif DevelopmentTools.locate "patchelf" - needed_libraries_using_patchelf path - else - return [nil, []] if path.basename.to_s == "patchelf" - - raise "patchelf must be installed: brew install patchelf" - end + needed_libraries_using_patchelf_rb path end def needed_libraries_using_patchelf_rb(path) patcher = path.patchelf_patcher [patcher.soname, patcher.needed] end - - def needed_libraries_using_patchelf(path) - patchelf = DevelopmentTools.locate "patchelf" - if path.dylib? - command = [patchelf, "--print-soname", path.expand_path.to_s] - soname = Utils.safe_popen_read(*command).chomp - end - command = [patchelf, "--print-needed", path.expand_path.to_s] - needed = Utils.safe_popen_read(*command).split("\n") - [soname, needed] - end - - def needed_libraries_using_readelf(path) - soname = nil - needed = [] - command = ["readelf", "-d", path.expand_path.to_s] - lines = Utils.popen_read(*command, err: :out).split("\n") - lines.each do |s| - next if s.start_with?("readelf: Warning: possibly corrupt ELF header") - - filename = s[/\[(.*)\]/, 1] - next if filename.nil? - - if s.include? "(SONAME)" - soname = filename - elsif s.include? "(NEEDED)" - needed << filename - end - end - [soname, needed] - end end def rpath_using_patchelf_rb patchelf_patcher.runpath || patchelf_patcher.rpath end - def rpath_using_patchelf - patchelf = DevelopmentTools.locate "patchelf" - odie "Could not locate patchelf, please: brew install patchelf." if patchelf.nil? - - cmd_rpath = [patchelf, "--print-rpath", to_s] - rpath = Utils.popen_read(*cmd_rpath, err: :out).strip - - # patchelf requires that the ELF file have a .dynstr section. - # Skip ELF files that do not have a .dynstr section. - return if ["cannot find section .dynstr", "strange: no string table"].include?(rpath) - - unless $CHILD_STATUS.success? - raise ErrorDuringExecution.new(cmd_rpath, status: $CHILD_STATUS, output: [[:stderr, rpath]]) - end - - rpath unless rpath.blank? - end - def patchelf_patcher - return unless HOMEBREW_PATCHELF_RB - Homebrew.install_bundler_gems! require "patchelf" @patchelf_patcher ||= PatchELF::Patcher.new to_s, on_error: :silent diff --git a/Library/Homebrew/os/linux/global.rb b/Library/Homebrew/os/linux/global.rb index f564db2c2a4d8..e0b8724930041 100644 --- a/Library/Homebrew/os/linux/global.rb +++ b/Library/Homebrew/os/linux/global.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -# enables experimental readelf.rb, patchelf support. -HOMEBREW_PATCHELF_RB = ENV["HOMEBREW_NO_PATCHELF_RB"].blank?.freeze - module Homebrew DEFAULT_PREFIX ||= if Homebrew::EnvConfig.force_homebrew_on_linux? HOMEBREW_DEFAULT_PREFIX diff --git a/Library/Homebrew/test/os/linux/pathname_spec.rb b/Library/Homebrew/test/os/linux/pathname_spec.rb index d614b98204eb5..d0281ddcddad5 100644 --- a/Library/Homebrew/test/os/linux/pathname_spec.rb +++ b/Library/Homebrew/test/os/linux/pathname_spec.rb @@ -2,7 +2,7 @@ require "extend/pathname" -describe Pathname, skip: HOMEBREW_PATCHELF_RB.blank? do +describe Pathname do let(:elf_dir) { described_class.new "#{TEST_FIXTURE_DIR}/elf" } let(:sho) { elf_dir/"libhello.so.0" } let(:exec) { elf_dir/"hello" }