Teach Mach-O machinery about bundles
c.f. Homebrew/homebrew#12810. Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
parent
075a59e3f1
commit
2cca8e1a4f
@ -52,6 +52,7 @@ module MachO
|
|||||||
type = case read(4, offset + 12).unpack("N")[0]
|
type = case read(4, offset + 12).unpack("N")[0]
|
||||||
when 0x00000002, 0x02000000 then :executable
|
when 0x00000002, 0x02000000 then :executable
|
||||||
when 0x00000006, 0x06000000 then :dylib
|
when 0x00000006, 0x06000000 then :dylib
|
||||||
|
when 0x00000008, 0x08000000 then :bundle
|
||||||
else :dunno
|
else :dunno
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -105,4 +106,8 @@ module MachO
|
|||||||
def mach_o_executable?
|
def mach_o_executable?
|
||||||
mach_data.map{ |m| m.fetch :type }.include? :executable
|
mach_data.map{ |m| m.fetch :type }.include? :executable
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mach_o_bundle?
|
||||||
|
mach_data.map{ |m| m.fetch :type }.include? :bundle
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
BIN
Library/Homebrew/test/mach/fat.bundle
Normal file
BIN
Library/Homebrew/test/mach/fat.bundle
Normal file
Binary file not shown.
BIN
Library/Homebrew/test/mach/i386.bundle
Normal file
BIN
Library/Homebrew/test/mach/i386.bundle
Normal file
Binary file not shown.
BIN
Library/Homebrew/test/mach/x86_64.bundle
Normal file
BIN
Library/Homebrew/test/mach/x86_64.bundle
Normal file
Binary file not shown.
@ -3,6 +3,10 @@ require 'testing_env'
|
|||||||
require 'extend/ARGV' # needs to be after test/unit to avoid conflict with OptionsParser
|
require 'extend/ARGV' # needs to be after test/unit to avoid conflict with OptionsParser
|
||||||
ARGV.extend(HomebrewArgvExtension)
|
ARGV.extend(HomebrewArgvExtension)
|
||||||
|
|
||||||
|
def file pn
|
||||||
|
`/usr/bin/file -h '#{pn}'`.chomp
|
||||||
|
end
|
||||||
|
|
||||||
class MachOPathnameTests < Test::Unit::TestCase
|
class MachOPathnameTests < Test::Unit::TestCase
|
||||||
def test_fat_dylib
|
def test_fat_dylib
|
||||||
pn = Pathname.new("#{TEST_FOLDER}/mach/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.mach_o_executable?
|
||||||
assert !pn.text_executable?
|
assert !pn.text_executable?
|
||||||
assert pn.arch == :universal
|
assert pn.arch == :universal
|
||||||
assert_match /Mach-O (64-bit )?dynamically linked shared library/,
|
assert_match /Mach-O (64-bit )?dynamically linked shared library/, file(pn)
|
||||||
`/usr/bin/file -h '#{pn}'`.chomp
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_i386_dylib
|
def test_i386_dylib
|
||||||
@ -29,8 +32,8 @@ class MachOPathnameTests < Test::Unit::TestCase
|
|||||||
assert pn.dylib?
|
assert pn.dylib?
|
||||||
assert !pn.mach_o_executable?
|
assert !pn.mach_o_executable?
|
||||||
assert !pn.text_executable?
|
assert !pn.text_executable?
|
||||||
assert_match /Mach-O (64-bit )?dynamically linked shared library/,
|
assert !pn.mach_o_bundle?
|
||||||
`/usr/bin/file -h '#{pn}'`.chomp
|
assert_match /Mach-O dynamically linked shared library/, file(pn)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_x86_64_dylib
|
def test_x86_64_dylib
|
||||||
@ -43,8 +46,8 @@ class MachOPathnameTests < Test::Unit::TestCase
|
|||||||
assert pn.dylib?
|
assert pn.dylib?
|
||||||
assert !pn.mach_o_executable?
|
assert !pn.mach_o_executable?
|
||||||
assert !pn.text_executable?
|
assert !pn.text_executable?
|
||||||
assert_match /Mach-O (64-bit )?dynamically linked shared library/,
|
assert !pn.mach_o_bundle?
|
||||||
`/usr/bin/file -h '#{pn}'`.chomp
|
assert_match /Mach-O 64-bit dynamically linked shared library/, file(pn)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mach_o_executable
|
def test_mach_o_executable
|
||||||
@ -57,8 +60,50 @@ class MachOPathnameTests < Test::Unit::TestCase
|
|||||||
assert !pn.dylib?
|
assert !pn.dylib?
|
||||||
assert pn.mach_o_executable?
|
assert pn.mach_o_executable?
|
||||||
assert !pn.text_executable?
|
assert !pn.text_executable?
|
||||||
assert_match /Mach-O (64-bit )?executable/,
|
assert !pn.mach_o_bundle?
|
||||||
`/usr/bin/file -h '#{pn}'`.chomp
|
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
|
end
|
||||||
|
|
||||||
def test_non_mach_o
|
def test_non_mach_o
|
||||||
@ -71,11 +116,10 @@ class MachOPathnameTests < Test::Unit::TestCase
|
|||||||
assert !pn.dylib?
|
assert !pn.dylib?
|
||||||
assert !pn.mach_o_executable?
|
assert !pn.mach_o_executable?
|
||||||
assert !pn.text_executable?
|
assert !pn.text_executable?
|
||||||
|
assert !pn.mach_o_bundle?
|
||||||
assert pn.arch == :dunno
|
assert pn.arch == :dunno
|
||||||
assert_no_match /Mach-O (64-bit )?dynamically linked shared library/,
|
assert_no_match /Mach-O (64-bit )?dynamically linked shared library/, file(pn)
|
||||||
`/usr/bin/file -h '#{pn}'`.chomp
|
assert_no_match /Mach-O [^ ]* ?executable/, file(pn)
|
||||||
assert_no_match /Mach-O [^ ]* ?executable/,
|
|
||||||
`/usr/bin/file -h '#{pn}'`.chomp
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_architecture_list_extension
|
def test_architecture_list_extension
|
||||||
@ -114,7 +158,7 @@ class TextExecutableTests < Test::Unit::TestCase
|
|||||||
assert pn.text_executable?
|
assert pn.text_executable?
|
||||||
assert_equal [], pn.archs
|
assert_equal [], pn.archs
|
||||||
assert pn.arch == :dunno
|
assert pn.arch == :dunno
|
||||||
assert_match /text executable/, `/usr/bin/file -h '#{pn}'`.chomp
|
assert_match /text executable/, file(pn)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_shebang_with_options
|
def test_shebang_with_options
|
||||||
@ -130,7 +174,7 @@ class TextExecutableTests < Test::Unit::TestCase
|
|||||||
assert pn.text_executable?
|
assert pn.text_executable?
|
||||||
assert_equal [], pn.archs
|
assert_equal [], pn.archs
|
||||||
assert pn.arch == :dunno
|
assert pn.arch == :dunno
|
||||||
assert_match /text executable/, `/usr/bin/file -h '#{pn}'`.chomp
|
assert_match /text executable/, file(pn)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_malformed_shebang
|
def test_malformed_shebang
|
||||||
@ -146,7 +190,7 @@ class TextExecutableTests < Test::Unit::TestCase
|
|||||||
assert !pn.text_executable?
|
assert !pn.text_executable?
|
||||||
assert_equal [], pn.archs
|
assert_equal [], pn.archs
|
||||||
assert pn.arch == :dunno
|
assert pn.arch == :dunno
|
||||||
assert_no_match /text executable/, `/usr/bin/file -h '#{pn}'`.chomp
|
assert_no_match /text executable/, file(pn)
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user