2010-08-21 11:06:02 -07:00
|
|
|
class Cleaner
|
|
|
|
def initialize f
|
2010-11-09 13:00:33 +00:00
|
|
|
@f = Formula.factory f
|
|
|
|
[f.bin, f.sbin, f.lib].select{ |d| d.exist? }.each{ |d| clean_dir d }
|
2010-08-21 11:23:54 -07:00
|
|
|
|
2012-01-21 00:51:20 +01:00
|
|
|
if ENV['HOMEBREW_KEEP_INFO']
|
|
|
|
# Get rid of the directory file, so it no longer bother us at link stage.
|
|
|
|
info_dir_file = f.info + 'dir'
|
|
|
|
if info_dir_file.file? and not f.skip_clean? info_dir_file
|
|
|
|
puts "rm #{info_dir_file}" if ARGV.verbose?
|
|
|
|
info_dir_file.unlink
|
|
|
|
end
|
|
|
|
else
|
2010-08-21 11:23:54 -07:00
|
|
|
f.info.rmtree if f.info.directory? and not f.skip_clean? f.info
|
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
|
|
|
|
# Hunt for empty folders and nuke them unless they are protected by
|
|
|
|
# f.skip_clean? We want post-order traversal, so put the dirs in a stack
|
|
|
|
# and then pop them off later.
|
|
|
|
paths = []
|
|
|
|
f.prefix.find do |path|
|
|
|
|
paths << path if path.directory?
|
|
|
|
end
|
|
|
|
|
|
|
|
paths.each do |d|
|
|
|
|
if d.children.empty? and not f.skip_clean? d
|
|
|
|
puts "rmdir: #{d} (empty)" if ARGV.verbose?
|
|
|
|
d.rmdir
|
|
|
|
end
|
|
|
|
end
|
2010-08-21 11:06:02 -07:00
|
|
|
end
|
|
|
|
|
2010-11-09 13:00:33 +00:00
|
|
|
private
|
|
|
|
|
2010-08-21 11:06:02 -07:00
|
|
|
def strip path, args=''
|
|
|
|
return if @f.skip_clean? path
|
|
|
|
puts "strip #{path}" if ARGV.verbose?
|
|
|
|
path.chmod 0644 # so we can strip
|
|
|
|
unless path.stat.nlink > 1
|
Core change: XCode only install, with CLT or both
Allow XCode without the Command Line Tools to
work with homebrew, so it's not necessary
to register an Apple Dev ID and/or go to the
XCode prefs and download the CLT. Yay!
Further, this commit allows to use the CLT
solely (without the need for XCode).
Saves quite some megs.
(Some furmulae require xcodebuild)
Of course XCode together with the CLT is still
fine and has been tested on 10.7 and 10.6
with Xcode 4 and Xcode 3.
Only on Lion or above, tell the user about the options,
which are
- Xcode without CLT
- CLT without Xcode
- both (ok, it's not directly stated, but implicit)
So if no Xcode is found and we are on Lion or above,
we don't fail but check for the CLTs now.
For older Macs, the old message that Xcode is needed
and the installer should be run is still displayed.
If the CLT are not found but Xcode is, then we
print out about the experimental status of this setup.
Closes Homebrew/homebrew#10510.
Signed-off-by: Adam Vandenberg <flangy@gmail.com>
2012-02-26 21:04:15 +01:00
|
|
|
system "#{MacOS.locate('strip')}", *(args+path)
|
2010-08-21 11:06:02 -07:00
|
|
|
else
|
|
|
|
path = path.to_s.gsub ' ', '\\ '
|
|
|
|
|
|
|
|
# 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
|
Core change: XCode only install, with CLT or both
Allow XCode without the Command Line Tools to
work with homebrew, so it's not necessary
to register an Apple Dev ID and/or go to the
XCode prefs and download the CLT. Yay!
Further, this commit allows to use the CLT
solely (without the need for XCode).
Saves quite some megs.
(Some furmulae require xcodebuild)
Of course XCode together with the CLT is still
fine and has been tested on 10.7 and 10.6
with Xcode 4 and Xcode 3.
Only on Lion or above, tell the user about the options,
which are
- Xcode without CLT
- CLT without Xcode
- both (ok, it's not directly stated, but implicit)
So if no Xcode is found and we are on Lion or above,
we don't fail but check for the CLTs now.
For older Macs, the old message that Xcode is needed
and the installer should be run is still displayed.
If the CLT are not found but Xcode is, then we
print out about the experimental status of this setup.
Closes Homebrew/homebrew#10510.
Signed-off-by: Adam Vandenberg <flangy@gmail.com>
2012-02-26 21:04:15 +01:00
|
|
|
`#{MacOS.locate('strip')} #{args} -o #{tmp} #{path}`
|
2010-08-21 11:06:02 -07:00
|
|
|
`/bin/cat #{tmp} > #{path}`
|
|
|
|
ensure
|
|
|
|
FileUtils.rm tmp
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def clean_file path
|
2010-11-09 13:00:33 +00:00
|
|
|
perms = 0444
|
2012-05-28 20:43:32 -05:00
|
|
|
if path.dylib?
|
2010-11-09 13:00:33 +00:00
|
|
|
# Stripping libraries is causing no end of trouble. Lets just give up,
|
|
|
|
# and try to do it manually in instances where it makes sense.
|
2010-08-21 11:06:02 -07:00
|
|
|
#strip path, '-SxX'
|
2012-05-28 20:43:32 -05:00
|
|
|
elsif path.mach_o_executable?
|
2010-08-21 11:06:02 -07:00
|
|
|
strip path
|
2010-11-09 13:00:33 +00:00
|
|
|
perms = 0555
|
2012-05-28 20:43:32 -05:00
|
|
|
elsif path.text_executable?
|
2010-11-09 13:00:33 +00:00
|
|
|
perms = 0555
|
2010-08-21 11:06:02 -07:00
|
|
|
end
|
|
|
|
path.chmod perms
|
|
|
|
end
|
|
|
|
|
|
|
|
def clean_dir d
|
|
|
|
d.find do |path|
|
|
|
|
if path.directory?
|
|
|
|
Find.prune if @f.skip_clean? path
|
|
|
|
elsif not path.file?
|
|
|
|
next
|
2010-11-09 13:00:33 +00:00
|
|
|
elsif path.extname == '.la'
|
2010-08-21 11:06:02 -07:00
|
|
|
# *.la files are stupid
|
2010-11-09 13:00:33 +00:00
|
|
|
path.unlink unless @f.skip_clean? path
|
2012-03-09 12:37:23 -06:00
|
|
|
elsif path == @f.lib+'charset.alias'
|
|
|
|
path.unlink unless @f.skip_clean? path
|
2010-08-21 11:06:02 -07:00
|
|
|
elsif not path.symlink?
|
|
|
|
clean_file path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|