mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-15 19:56:59 +08:00
archs_for_command: use new Mach-O Pathname methods
- Reimplement archs_for_command on top of the new Mach-O methods - Move ArchitectureListExtension to mach.rb - Add a test for the ArchitectureListExtension Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
parent
7bb1894df5
commit
53ce9dba53
@ -1,3 +1,18 @@
|
|||||||
|
module ArchitectureListExtension
|
||||||
|
def universal?
|
||||||
|
self.include? :i386 and self.include? :x86_64
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_ppc!
|
||||||
|
self.delete :ppc7400
|
||||||
|
self.delete :ppc64
|
||||||
|
end
|
||||||
|
|
||||||
|
def as_arch_flags
|
||||||
|
self.collect{ |a| "-arch #{a}" }.join(' ')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
module MachO
|
module MachO
|
||||||
# Mach-O binary methods, see:
|
# Mach-O binary methods, see:
|
||||||
# /usr/include/mach-o/loader.h
|
# /usr/include/mach-o/loader.h
|
||||||
@ -52,7 +67,7 @@ module MachO
|
|||||||
end
|
end
|
||||||
|
|
||||||
def archs
|
def archs
|
||||||
mach_data.map{ |m| m.fetch :arch }
|
mach_data.map{ |m| m.fetch :arch }.extend(ArchitectureListExtension)
|
||||||
end
|
end
|
||||||
|
|
||||||
def arch
|
def arch
|
||||||
|
@ -77,6 +77,21 @@ class MachOPathnameTests < Test::Unit::TestCase
|
|||||||
assert_no_match /Mach-O [^ ]* ?executable/,
|
assert_no_match /Mach-O [^ ]* ?executable/,
|
||||||
`/usr/bin/file -h '#{pn}'`.chomp
|
`/usr/bin/file -h '#{pn}'`.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_architecture_list_extension
|
||||||
|
archs = [:i386, :x86_64, :ppc7400, :ppc64]
|
||||||
|
archs.extend(ArchitectureListExtension)
|
||||||
|
assert archs.universal?
|
||||||
|
archs.remove_ppc!
|
||||||
|
assert_equal 2, archs.length
|
||||||
|
assert_match /-arch i386/, archs.as_arch_flags
|
||||||
|
assert_match /-arch x86_64/, archs.as_arch_flags
|
||||||
|
|
||||||
|
pn = Pathname.new("#{TEST_FOLDER}/mach/fat.dylib")
|
||||||
|
assert pn.archs.universal?
|
||||||
|
assert_match /-arch i386/, pn.archs.as_arch_flags
|
||||||
|
assert_match /-arch x86_64/, pn.archs.as_arch_flags
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class TextExecutableTests < Test::Unit::TestCase
|
class TextExecutableTests < Test::Unit::TestCase
|
||||||
|
@ -16,19 +16,19 @@ class UtilTests < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_arch_for_command
|
def test_arch_for_command
|
||||||
arches=archs_for_command '/usr/bin/svn'
|
archs = archs_for_command '/usr/bin/svn'
|
||||||
if `sw_vers -productVersion` =~ /10\.(\d+)/ and $1.to_i >= 7
|
if `sw_vers -productVersion` =~ /10\.(\d+)/ and $1.to_i >= 7
|
||||||
assert_equal 2, arches.length
|
assert_equal 2, archs.length
|
||||||
assert arches.include?(:x86_64)
|
assert archs.include?(:x86_64)
|
||||||
elsif `sw_vers -productVersion` =~ /10\.(\d+)/ and $1.to_i == 6
|
elsif `sw_vers -productVersion` =~ /10\.(\d+)/ and $1.to_i == 6
|
||||||
assert_equal 3, arches.length
|
assert_equal 3, archs.length
|
||||||
assert arches.include?(:x86_64)
|
assert archs.include?(:x86_64)
|
||||||
assert arches.include?(:ppc7400)
|
assert archs.include?(:ppc7400)
|
||||||
else
|
else
|
||||||
assert_equal 2, arches.length
|
assert_equal 2, archs.length
|
||||||
assert arches.include?(:ppc7400)
|
assert archs.include?(:ppc7400)
|
||||||
end
|
end
|
||||||
assert arches.include?(:i386)
|
assert archs.include?(:i386)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -186,43 +186,10 @@ def gzip *paths
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module ArchitectureListExtension
|
|
||||||
def universal?
|
|
||||||
self.include? :i386 and self.include? :x86_64
|
|
||||||
end
|
|
||||||
|
|
||||||
def remove_ppc!
|
|
||||||
self.delete :ppc7400
|
|
||||||
self.delete :ppc64
|
|
||||||
end
|
|
||||||
|
|
||||||
def as_arch_flags
|
|
||||||
self.collect{ |a| "-arch #{a}" }.join(' ')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns array of architectures that the given command or library is built for.
|
# Returns array of architectures that the given command or library is built for.
|
||||||
def archs_for_command cmd
|
def archs_for_command cmd
|
||||||
cmd = cmd.to_s # If we were passed a Pathname, turn it into a string.
|
cmd = which(cmd) unless Pathname.new(cmd).absolute?
|
||||||
cmd = `/usr/bin/which #{cmd}` unless Pathname.new(cmd).absolute?
|
Pathname.new(cmd).archs
|
||||||
cmd.gsub! ' ', '\\ ' # Escape spaces in the filename.
|
|
||||||
|
|
||||||
lines = `/usr/bin/file -L #{cmd}`
|
|
||||||
archs = lines.to_a.inject([]) do |archs, line|
|
|
||||||
case line
|
|
||||||
when /Mach-O (executable|dynamically linked shared library) ppc/
|
|
||||||
archs << :ppc7400
|
|
||||||
when /Mach-O 64-bit (executable|dynamically linked shared library) ppc64/
|
|
||||||
archs << :ppc64
|
|
||||||
when /Mach-O (executable|dynamically linked shared library) i386/
|
|
||||||
archs << :i386
|
|
||||||
when /Mach-O 64-bit (executable|dynamically linked shared library) x86_64/
|
|
||||||
archs << :x86_64
|
|
||||||
else
|
|
||||||
archs
|
|
||||||
end
|
|
||||||
end
|
|
||||||
archs.extend(ArchitectureListExtension)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def inreplace path, before=nil, after=nil
|
def inreplace path, before=nil, after=nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user