In ELFShim, #needed_libraries, #dynamic_elf? and #with_interpreter? check using patchelf gem.
Having HOMEBREW_PATCHELF_RB set in the ENV, will conditionally install patchelf.rb gem, use patchelf.rb in the above mentioned methods. The installed vendored gems are listed in .gitignore to maintain a clean state.
This commit is contained in:
parent
67c843b91e
commit
486114282c
11
.gitignore
vendored
11
.gitignore
vendored
@ -129,9 +129,6 @@
|
|||||||
**/vendor/bundle/ruby/*/gems/simplecov-*/
|
**/vendor/bundle/ruby/*/gems/simplecov-*/
|
||||||
**/vendor/bundle/ruby/*/gems/simplecov-cobertura-*/
|
**/vendor/bundle/ruby/*/gems/simplecov-cobertura-*/
|
||||||
**/vendor/bundle/ruby/*/gems/simplecov-html-*/
|
**/vendor/bundle/ruby/*/gems/simplecov-html-*/
|
||||||
**/vendor/bundle/ruby/*/gems/sorbet-*/
|
|
||||||
**/vendor/bundle/ruby/*/gems/sorbet-runtime-*/
|
|
||||||
**/vendor/bundle/ruby/*/gems/tapioca-*/
|
|
||||||
**/vendor/bundle/ruby/*/gems/term-ansicolor-*/
|
**/vendor/bundle/ruby/*/gems/term-ansicolor-*/
|
||||||
**/vendor/bundle/ruby/*/gems/thor-*/
|
**/vendor/bundle/ruby/*/gems/thor-*/
|
||||||
**/vendor/bundle/ruby/*/gems/tins-*/
|
**/vendor/bundle/ruby/*/gems/tins-*/
|
||||||
@ -140,6 +137,14 @@
|
|||||||
**/vendor/bundle/ruby/*/gems/unicode-display_width-*/
|
**/vendor/bundle/ruby/*/gems/unicode-display_width-*/
|
||||||
**/vendor/bundle/ruby/*/gems/webrobots-*/
|
**/vendor/bundle/ruby/*/gems/webrobots-*/
|
||||||
|
|
||||||
|
# Ignore conditional dependencies we don't wish to vendor
|
||||||
|
**/vendor/bundle/ruby/*/gems/bindata-*/
|
||||||
|
**/vendor/bundle/ruby/*/gems/elftools-*/
|
||||||
|
**/vendor/bundle/ruby/*/gems/patchelf-*/
|
||||||
|
**/vendor/bundle/ruby/*/gems/sorbet-*/
|
||||||
|
**/vendor/bundle/ruby/*/gems/sorbet-runtime-*/
|
||||||
|
**/vendor/bundle/ruby/*/gems/tapioca-*/
|
||||||
|
|
||||||
# Ignore `bin` contents (again).
|
# Ignore `bin` contents (again).
|
||||||
/bin
|
/bin
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,7 @@ end
|
|||||||
gem "activesupport"
|
gem "activesupport"
|
||||||
gem "concurrent-ruby"
|
gem "concurrent-ruby"
|
||||||
gem "mechanize"
|
gem "mechanize"
|
||||||
|
gem "patchelf" if ENV["HOMEBREW_PATCHELF_RB"]
|
||||||
gem "plist"
|
gem "plist"
|
||||||
gem "rubocop-performance"
|
gem "rubocop-performance"
|
||||||
gem "rubocop-rspec"
|
gem "rubocop-rspec"
|
||||||
|
|||||||
@ -74,7 +74,14 @@ module ELFShim
|
|||||||
@with_interpreter = if binary_executable?
|
@with_interpreter = if binary_executable?
|
||||||
true
|
true
|
||||||
elsif dylib?
|
elsif dylib?
|
||||||
if which "readelf"
|
if HOMEBREW_PATCHELF_RB
|
||||||
|
begin
|
||||||
|
patchelf_patcher.interpreter.present?
|
||||||
|
rescue PatchELF::PatchError => e
|
||||||
|
opoo e
|
||||||
|
false
|
||||||
|
end
|
||||||
|
elsif which "readelf"
|
||||||
Utils.popen_read("readelf", "-l", to_path).include?(" INTERP ")
|
Utils.popen_read("readelf", "-l", to_path).include?(" INTERP ")
|
||||||
elsif which "file"
|
elsif which "file"
|
||||||
Utils.popen_read("file", "-L", "-b", to_path).include?(" interpreter ")
|
Utils.popen_read("file", "-L", "-b", to_path).include?(" interpreter ")
|
||||||
@ -89,7 +96,9 @@ module ELFShim
|
|||||||
def dynamic_elf?
|
def dynamic_elf?
|
||||||
return @dynamic_elf if defined? @dynamic_elf
|
return @dynamic_elf if defined? @dynamic_elf
|
||||||
|
|
||||||
@dynamic_elf = if which "readelf"
|
@dynamic_elf = if HOMEBREW_PATCHELF_RB
|
||||||
|
patchelf_patcher.instance_variable_get(:@elf).segment_by_type(:DYNAMIC).present?
|
||||||
|
elsif which "readelf"
|
||||||
Utils.popen_read("readelf", "-l", to_path).include?(" DYNAMIC ")
|
Utils.popen_read("readelf", "-l", to_path).include?(" DYNAMIC ")
|
||||||
elsif which "file"
|
elsif which "file"
|
||||||
!Utils.popen_read("file", "-L", "-b", to_path)[/dynamic|shared/].nil?
|
!Utils.popen_read("file", "-L", "-b", to_path)[/dynamic|shared/].nil?
|
||||||
@ -127,7 +136,9 @@ module ELFShim
|
|||||||
private
|
private
|
||||||
|
|
||||||
def needed_libraries(path)
|
def needed_libraries(path)
|
||||||
if DevelopmentTools.locate "readelf"
|
if HOMEBREW_PATCHELF_RB
|
||||||
|
needed_libraries_using_patchelf_rb path
|
||||||
|
elsif DevelopmentTools.locate "readelf"
|
||||||
needed_libraries_using_readelf path
|
needed_libraries_using_readelf path
|
||||||
elsif DevelopmentTools.locate "patchelf"
|
elsif DevelopmentTools.locate "patchelf"
|
||||||
needed_libraries_using_patchelf path
|
needed_libraries_using_patchelf path
|
||||||
@ -138,6 +149,25 @@ module ELFShim
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def needed_libraries_using_patchelf_rb(path)
|
||||||
|
patcher = path.patchelf_patcher
|
||||||
|
return [nil, []] unless patcher
|
||||||
|
|
||||||
|
soname = begin
|
||||||
|
patcher.soname
|
||||||
|
rescue PatchELF::PatchError => e
|
||||||
|
opoo e unless e.to_s.start_with? "Entry DT_SONAME not found, not a shared library?"
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
needed = begin
|
||||||
|
patcher.needed
|
||||||
|
rescue PatchELF::PatchError => e
|
||||||
|
opoo e
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
[soname, needed]
|
||||||
|
end
|
||||||
|
|
||||||
def needed_libraries_using_patchelf(path)
|
def needed_libraries_using_patchelf(path)
|
||||||
return [nil, []] unless path.dynamic_elf?
|
return [nil, []] unless path.dynamic_elf?
|
||||||
|
|
||||||
@ -172,6 +202,16 @@ module ELFShim
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def patchelf_patcher
|
||||||
|
return unless HOMEBREW_PATCHELF_RB
|
||||||
|
|
||||||
|
@patchelf_patcher ||= begin
|
||||||
|
Homebrew.install_bundler_gems!
|
||||||
|
require "patchelf"
|
||||||
|
PatchELF::Patcher.new to_s, logging: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def metadata
|
def metadata
|
||||||
@metadata ||= Metadata.new(self)
|
@metadata ||= Metadata.new(self)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# enables experimental readelf.rb, patchelf support.
|
||||||
|
HOMEBREW_PATCHELF_RB = ENV["HOMEBREW_PATCHELF_RB"].present?.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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user