remove code using patchelf, remove HOMEBREW_PATCHELF_RB var
This commit is contained in:
parent
0c2d7659cf
commit
043719383b
@ -691,7 +691,7 @@ module Homebrew
|
|||||||
|
|
||||||
# these will result in uncommitted gems.
|
# these will result in uncommitted gems.
|
||||||
if path == HOMEBREW_REPOSITORY
|
if path == HOMEBREW_REPOSITORY
|
||||||
next if ENV["HOMEBREW_SORBET"] || ENV["HOMEBREW_PATCHELF_RB"]
|
next if ENV["HOMEBREW_SORBET"]
|
||||||
end
|
end
|
||||||
|
|
||||||
message ||= ""
|
message ||= ""
|
||||||
|
|||||||
@ -71,41 +71,19 @@ module ELFShim
|
|||||||
def rpath
|
def rpath
|
||||||
return @rpath if defined? @rpath
|
return @rpath if defined? @rpath
|
||||||
|
|
||||||
@rpath = if HOMEBREW_PATCHELF_RB
|
@rpath = rpath_using_patchelf_rb
|
||||||
rpath_using_patchelf_rb
|
|
||||||
else
|
|
||||||
rpath_using_patchelf
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def interpreter
|
def interpreter
|
||||||
return @interpreter if defined? @interpreter
|
return @interpreter if defined? @interpreter
|
||||||
|
|
||||||
@interpreter = if HOMEBREW_PATCHELF_RB
|
@interpreter = patchelf_patcher.interpreter
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def dynamic_elf?
|
def dynamic_elf?
|
||||||
return @dynamic_elf if defined? @dynamic_elf
|
return @dynamic_elf if defined? @dynamic_elf
|
||||||
|
|
||||||
@dynamic_elf = if HOMEBREW_PATCHELF_RB
|
@dynamic_elf = patchelf_patcher.elf.segment_by_type(:DYNAMIC).present?
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Metadata
|
class Metadata
|
||||||
@ -139,81 +117,20 @@ module ELFShim
|
|||||||
def needed_libraries(path)
|
def needed_libraries(path)
|
||||||
return [nil, []] unless path.dynamic_elf?
|
return [nil, []] unless path.dynamic_elf?
|
||||||
|
|
||||||
if HOMEBREW_PATCHELF_RB
|
needed_libraries_using_patchelf_rb path
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def needed_libraries_using_patchelf_rb(path)
|
def needed_libraries_using_patchelf_rb(path)
|
||||||
patcher = path.patchelf_patcher
|
patcher = path.patchelf_patcher
|
||||||
[patcher.soname, patcher.needed]
|
[patcher.soname, patcher.needed]
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def rpath_using_patchelf_rb
|
def rpath_using_patchelf_rb
|
||||||
patchelf_patcher.runpath || patchelf_patcher.rpath
|
patchelf_patcher.runpath || patchelf_patcher.rpath
|
||||||
end
|
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
|
def patchelf_patcher
|
||||||
return unless HOMEBREW_PATCHELF_RB
|
|
||||||
|
|
||||||
Homebrew.install_bundler_gems!
|
Homebrew.install_bundler_gems!
|
||||||
require "patchelf"
|
require "patchelf"
|
||||||
@patchelf_patcher ||= PatchELF::Patcher.new to_s, on_error: :silent
|
@patchelf_patcher ||= PatchELF::Patcher.new to_s, on_error: :silent
|
||||||
|
|||||||
@ -1,8 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# enables experimental readelf.rb, patchelf support.
|
|
||||||
HOMEBREW_PATCHELF_RB = ENV["HOMEBREW_NO_PATCHELF_RB"].blank?.freeze
|
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
DEFAULT_PREFIX ||= if Homebrew::EnvConfig.force_homebrew_on_linux?
|
DEFAULT_PREFIX ||= if Homebrew::EnvConfig.force_homebrew_on_linux?
|
||||||
HOMEBREW_DEFAULT_PREFIX
|
HOMEBREW_DEFAULT_PREFIX
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
require "extend/pathname"
|
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(:elf_dir) { described_class.new "#{TEST_FIXTURE_DIR}/elf" }
|
||||||
let(:sho) { elf_dir/"libhello.so.0" }
|
let(:sho) { elf_dir/"libhello.so.0" }
|
||||||
let(:exec) { elf_dir/"hello" }
|
let(:exec) { elf_dir/"hello" }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user