Teach Mach-O machinery about bundles

c.f. Homebrew/homebrew#12810.

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
Jack Nagel 2012-06-16 11:35:02 -05:00
parent 075a59e3f1
commit 2cca8e1a4f
5 changed files with 64 additions and 15 deletions

View File

@ -52,6 +52,7 @@ module MachO
type = case read(4, offset + 12).unpack("N")[0]
when 0x00000002, 0x02000000 then :executable
when 0x00000006, 0x06000000 then :dylib
when 0x00000008, 0x08000000 then :bundle
else :dunno
end
@ -105,4 +106,8 @@ module MachO
def mach_o_executable?
mach_data.map{ |m| m.fetch :type }.include? :executable
end
def mach_o_bundle?
mach_data.map{ |m| m.fetch :type }.include? :bundle
end
end

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -3,6 +3,10 @@ require 'testing_env'
require 'extend/ARGV' # needs to be after test/unit to avoid conflict with OptionsParser
ARGV.extend(HomebrewArgvExtension)
def file pn
`/usr/bin/file -h '#{pn}'`.chomp
end
class MachOPathnameTests < Test::Unit::TestCase
def test_fat_dylib
pn = Pathname.new("#{TEST_FOLDER}/mach/fat.dylib")
@ -15,8 +19,7 @@ class MachOPathnameTests < Test::Unit::TestCase
assert !pn.mach_o_executable?
assert !pn.text_executable?
assert pn.arch == :universal
assert_match /Mach-O (64-bit )?dynamically linked shared library/,
`/usr/bin/file -h '#{pn}'`.chomp
assert_match /Mach-O (64-bit )?dynamically linked shared library/, file(pn)
end
def test_i386_dylib
@ -29,8 +32,8 @@ class MachOPathnameTests < Test::Unit::TestCase
assert pn.dylib?
assert !pn.mach_o_executable?
assert !pn.text_executable?
assert_match /Mach-O (64-bit )?dynamically linked shared library/,
`/usr/bin/file -h '#{pn}'`.chomp
assert !pn.mach_o_bundle?
assert_match /Mach-O dynamically linked shared library/, file(pn)
end
def test_x86_64_dylib
@ -43,8 +46,8 @@ class MachOPathnameTests < Test::Unit::TestCase
assert pn.dylib?
assert !pn.mach_o_executable?
assert !pn.text_executable?
assert_match /Mach-O (64-bit )?dynamically linked shared library/,
`/usr/bin/file -h '#{pn}'`.chomp
assert !pn.mach_o_bundle?
assert_match /Mach-O 64-bit dynamically linked shared library/, file(pn)
end
def test_mach_o_executable
@ -57,8 +60,50 @@ class MachOPathnameTests < Test::Unit::TestCase
assert !pn.dylib?
assert pn.mach_o_executable?
assert !pn.text_executable?
assert_match /Mach-O (64-bit )?executable/,
`/usr/bin/file -h '#{pn}'`.chomp
assert !pn.mach_o_bundle?
assert_match /Mach-O (64-bit )?executable/, file(pn)
end
def test_fat_bundle
pn = Pathname.new("#{TEST_FOLDER}/mach/fat.bundle")
assert pn.universal?
assert !pn.i386?
assert !pn.x86_64?
assert !pn.ppc7400?
assert !pn.ppc64?
assert !pn.dylib?
assert !pn.mach_o_executable?
assert !pn.text_executable?
assert pn.mach_o_bundle?
assert_match /Mach-O (64-bit )?bundle/, file(pn)
end
def test_i386_bundle
pn = Pathname.new("#{TEST_FOLDER}/mach/i386.bundle")
assert !pn.universal?
assert pn.i386?
assert !pn.x86_64?
assert !pn.ppc7400?
assert !pn.ppc64?
assert !pn.dylib?
assert !pn.mach_o_executable?
assert !pn.text_executable?
assert pn.mach_o_bundle?
assert_match /Mach-O bundle/, file(pn)
end
def test_x86_64_bundle
pn = Pathname.new("#{TEST_FOLDER}/mach/x86_64.bundle")
assert !pn.universal?
assert !pn.i386?
assert pn.x86_64?
assert !pn.ppc7400?
assert !pn.ppc64?
assert !pn.dylib?
assert !pn.mach_o_executable?
assert !pn.text_executable?
assert pn.mach_o_bundle?
assert_match /Mach-O 64-bit bundle/, file(pn)
end
def test_non_mach_o
@ -71,11 +116,10 @@ class MachOPathnameTests < Test::Unit::TestCase
assert !pn.dylib?
assert !pn.mach_o_executable?
assert !pn.text_executable?
assert !pn.mach_o_bundle?
assert pn.arch == :dunno
assert_no_match /Mach-O (64-bit )?dynamically linked shared library/,
`/usr/bin/file -h '#{pn}'`.chomp
assert_no_match /Mach-O [^ ]* ?executable/,
`/usr/bin/file -h '#{pn}'`.chomp
assert_no_match /Mach-O (64-bit )?dynamically linked shared library/, file(pn)
assert_no_match /Mach-O [^ ]* ?executable/, file(pn)
end
def test_architecture_list_extension
@ -114,7 +158,7 @@ class TextExecutableTests < Test::Unit::TestCase
assert pn.text_executable?
assert_equal [], pn.archs
assert pn.arch == :dunno
assert_match /text executable/, `/usr/bin/file -h '#{pn}'`.chomp
assert_match /text executable/, file(pn)
end
def test_shebang_with_options
@ -130,7 +174,7 @@ class TextExecutableTests < Test::Unit::TestCase
assert pn.text_executable?
assert_equal [], pn.archs
assert pn.arch == :dunno
assert_match /text executable/, `/usr/bin/file -h '#{pn}'`.chomp
assert_match /text executable/, file(pn)
end
def test_malformed_shebang
@ -146,7 +190,7 @@ class TextExecutableTests < Test::Unit::TestCase
assert !pn.text_executable?
assert_equal [], pn.archs
assert pn.arch == :dunno
assert_no_match /text executable/, `/usr/bin/file -h '#{pn}'`.chomp
assert_no_match /text executable/, file(pn)
end
def teardown