Stop stripping binary files

This commit is contained in:
Adam Vandenberg 2012-07-03 07:24:35 -07:00
parent 4ffc06f988
commit 54618074a1

View File

@ -1,4 +1,12 @@
# Cleans a newly installed keg.
# By default:
# * removes info files
# * removes .la files
# * removes empty directories
# * sets permissions on executables
class Cleaner class Cleaner
# Create a cleaner for the given formula name, and clean the keg
def initialize f def initialize f
@f = Formula.factory f @f = Formula.factory f
[f.bin, f.sbin, f.lib].select{ |d| d.exist? }.each{ |d| clean_dir d } [f.bin, f.sbin, f.lib].select{ |d| d.exist? }.each{ |d| clean_dir d }
@ -14,9 +22,8 @@ class Cleaner
f.info.rmtree if f.info.directory? and not f.skip_clean? f.info f.info.rmtree if f.info.directory? and not f.skip_clean? f.info
end end
# Hunt for empty folders and nuke them unless they are protected by # Remove empty folders.
# f.skip_clean? We want post-order traversal, so put the dirs in a stack # We want post-order traversal, so use a stack.
# and then pop them off later.
paths = [] paths = []
f.prefix.find do |path| f.prefix.find do |path|
paths << path if path.directory? paths << path if path.directory?
@ -32,56 +39,36 @@ class Cleaner
private private
def strip path, args='' # Set permissions for executables and non-executables
return if @f.skip_clean? path def clean_file_permissions path
puts "strip #{path}" if ARGV.verbose? perms = if path.mach_o_executable? || path.text_executable?
path.chmod 0644 # so we can strip 0555
unless path.stat.nlink > 1
system "#{MacOS.locate('strip')}", *(args+path)
else else
path = path.to_s.gsub ' ', '\\ ' 0444
# strip unlinks the file and recreates it, thus breaking hard links!
# is this expected behaviour? patch does it too… still, this fixes it
tmp = `/usr/bin/mktemp -t homebrew_strip`.chomp
begin
`#{MacOS.locate('strip')} #{args} -o #{tmp} #{path}`
`/bin/cat #{tmp} > #{path}`
ensure
FileUtils.rm tmp
end
end
end
def clean_file path
perms = 0444
if path.dylib?
# Stripping libraries is causing no end of trouble. Lets just give up,
# and try to do it manually in instances where it makes sense.
#strip path, '-SxX'
elsif path.mach_o_executable?
strip path
perms = 0555
elsif path.text_executable?
perms = 0555
end end
path.chmod perms path.chmod perms
end end
# Clean a single folder (non-recursively)
def clean_dir d def clean_dir d
d.find do |path| d.find do |path|
if path.directory? if path.directory?
# Stop cleaning this subtree if protected
Find.prune if @f.skip_clean? path Find.prune if @f.skip_clean? path
elsif not path.file? elsif not path.file?
# Sanity?
next next
elsif path.extname == '.la' elsif path.extname == '.la'
# *.la files are stupid # *.la files are stupid
path.unlink unless @f.skip_clean? path path.unlink unless @f.skip_clean? path
elsif path == @f.lib+'charset.alias' elsif path == @f.lib+'charset.alias'
# Many formulae symlink this file, but it is not strictly needed
path.unlink unless @f.skip_clean? path path.unlink unless @f.skip_clean? path
elsif not path.symlink? elsif not path.symlink?
clean_file path # Fix permissions
clean_file_permissions path
end end
end end
end end
end end