mirror of
https://github.com/chromebrew/chromebrew.git
synced 2026-01-07 22:54:11 -05:00
AutoBuild: fixup_patchelf started at 2025-05-13-14UTC (#11903)
* Adjust fixup and fix_interpreter_path to not break custom rpaths in packages. Signed-off-by: Satadru Pramanik <satadru@gmail.com> * Add more documentation Signed-off-by: Satadru Pramanik <satadru@gmail.com> --------- Signed-off-by: Satadru Pramanik <satadru@gmail.com> Co-authored-by: Satadru Pramanik <satadru@gmail.com>
This commit is contained in:
committed by
GitHub
parent
1622b34370
commit
def2a6c281
39
bin/crew
39
bin/crew
@@ -12,6 +12,7 @@ require_gem('ptools')
|
||||
require 'digest/sha2'
|
||||
require 'fileutils'
|
||||
require 'mkmf'
|
||||
require 'open3'
|
||||
require 'tmpdir'
|
||||
require 'uri'
|
||||
begin
|
||||
@@ -895,18 +896,38 @@ def fix_interpreter_path(dir)
|
||||
puts 'Running upx to uncompress binaries and patchelf to patch binary interpreter paths.'.lightblue
|
||||
abort('No Patchelf found!').lightred unless File.file?("#{CREW_PREFIX}/bin/patchelf")
|
||||
abort('No Upx found!').lightred unless File.file?("#{CREW_PREFIX}/bin/upx")
|
||||
execfiles = `find . -executable -type f ! \\( -name '*.a' \\) | xargs -P#{CREW_NPROC} -n1 sh -c '[ "$(head -c4 ${1})" = "\x7FELF" ] && echo ${1}' --`.chomp
|
||||
# Look for installed binaries and libraries in the package install
|
||||
# directory tree.
|
||||
execfiles = `find #{Dir.pwd} -executable -type f ! \\( -name '*.a' \\) | xargs -P#{CREW_NPROC} -n1 sh -c '[ "$(head -c4 ${1})" = "\x7FELF" ] && echo ${1}' -- 2> /dev/null`.split
|
||||
return if execfiles.empty?
|
||||
|
||||
execfiles.each_line(chomp: true) do |execfiletopatch|
|
||||
execfiletopatch = Dir.pwd + execfiletopatch.delete_prefix('.')
|
||||
@localdir = File.expand_path('../../.')
|
||||
execfiles.each do |execfiletopatch|
|
||||
next unless File.file?(execfiletopatch)
|
||||
|
||||
system "upx -qq -d #{execfiletopatch} 2> /dev/null"
|
||||
puts "Running patchelf on #{execfiletopatch}".orange if CREW_DEBUG
|
||||
system "patchelf --set-interpreter #{CREW_GLIBC_INTERPRETER} #{execfiletopatch} > /dev/null 2> /dev/null"
|
||||
@exec_rpath = `patchelf --print-rpath #{execfiletopatch}`.chomp
|
||||
puts "#{execfiletopatch} has an existing rpath of #{@exec_rpath}".orange unless @exec_rpath.empty?
|
||||
# system "patchelf --remove-rpath #{execfiletopatch} > /dev/null 2> /dev/null"
|
||||
# Decompress the binary if compressed.
|
||||
system "upx -qq -d #{execfiletopatch}", %i[err] => File::NULL
|
||||
# Check for existing interpreter.
|
||||
@interpreter, _read_interpreter_stderr_s, @read_interpreter_status = Open3.capture3("patchelf --print-interpreter #{execfiletopatch}")
|
||||
# Set interpreter unless the interpreter read failed or is already
|
||||
# set appropriately.
|
||||
unless @read_interpreter_status && @interpreter == CREW_GLIBC_INTERPRETER
|
||||
puts "Running patchelf on #{execfiletopatch} to set interpreter".orange if CREW_VERBOSE
|
||||
_set_interpreter_stdout, @set_interpreter_stderr = Open3.capture3("patchelf --set-interpreter #{CREW_GLIBC_INTERPRETER} #{execfiletopatch}")
|
||||
puts "#{execfiletopatch}: @set_interpreter_stderr: #{@set_interpreter_stderr.chomp}".lightpurple if !@set_interpreter_stderr.blank? && CREW_VERBOSE
|
||||
end
|
||||
# Try to read any existing rpath.
|
||||
@read_rpath_stdout_s, @read_rpath_stderr_s, @read_rpath_status = Open3.capture3("patchelf --print-rpath #{execfiletopatch}")
|
||||
@exec_rpath = @read_rpath_stdout_s.chomp
|
||||
@rpath_status = @read_rpath_status
|
||||
puts "#{execfiletopatch}: @read_rpath_stderr_s: #{@read_rpath_stderr_s}".lightpurple if !@read_rpath_stderr_s.blank? && CREW_VERBOSE
|
||||
# Set rpath if rpath read didn't fail, an rpath exists, and does not
|
||||
# already contain CREW_GLIBC_PREFIX.
|
||||
next if !@read_rpath_rpath_status || @exec_rpath.blank? || @exec_rpath.include?(CREW_GLIBC_PREFIX)
|
||||
puts "#{execfiletopatch.gsub(@localdir, '')} has an existing rpath of #{@exec_rpath}".lightpurple if CREW_VERBOSE
|
||||
puts "Prefixing #{CREW_GLIBC_PREFIX} to #{@exec_rpath} rpath for #{execfiletopatch.gsub(@localdir, '')}.".lightblue
|
||||
@set_rpath_stdout_s, @set_rpath_stderr_s, @set_rpath_status = Open3.capture3("patchelf --set-rpath #{CREW_GLIBC_PREFIX}:#{@exec_rpath} #{execfiletopatch}")
|
||||
puts "#{execfiletopatch}: @set_rpath_stderr_s: #{@set_rpath_stderr_s}".lightpurple if !@set_rpath_stderr_s.blank? && CREW_VERBOSE
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user