Skip to content

Commit

Permalink
cleaner: use new Mach-O pathname methods in clean_file
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
  • Loading branch information
jacknagel committed May 31, 2012
1 parent 0dc6ed0 commit 7ae740d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Library/Homebrew/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ def strip path, args=''

def clean_file path
perms = 0444
case `/usr/bin/file -h '#{path}'`
when /Mach-O dynamically linked shared library/
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'
when /Mach-O [^ ]* ?executable/
elsif path.mach_o_executable?
strip path
perms = 0555
when /text executable/
elsif path.text_executable?
perms = 0555
end
path.chmod perms
Expand Down
38 changes: 38 additions & 0 deletions Library/Homebrew/test/test_cleaner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'testing_env'

require 'extend/ARGV' # needs to be after test/unit to avoid conflict with OptionsParser
ARGV.extend(HomebrewArgvExtension)

require 'cleaner'

class CleanerTestBall < Formula
def initialize name=nil
@url="file:///#{TEST_FOLDER}/tarballs/testball-0.1.tbz"
@homepage = 'http://example.com/'
super "cleanertestball"
end

def install
TEST_FOLDER.cd do
bin.mkpath
lib.mkpath
cp 'mach/a.out', bin
cp 'mach/fat.dylib', lib
cp 'mach/x86_64.dylib', lib
cp 'mach/i386.dylib', lib
end
end
end

class CleanerTests < Test::Unit::TestCase
def test_clean_file
f = CleanerTestBall.new
nostdout { f.brew { f.install } }

assert_nothing_raised { Cleaner.new f }
assert_equal 0100555, (f.bin/'a.out').stat.mode
assert_equal 0100444, (f.lib/'fat.dylib').stat.mode
assert_equal 0100444, (f.lib/'x86_64.dylib').stat.mode
assert_equal 0100444, (f.lib/'i386.dylib').stat.mode
end
end

0 comments on commit 7ae740d

Please sign in to comment.