aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMartin Afanasjew2016-05-27 23:13:51 +0200
committerMartin Afanasjew2016-05-27 23:13:51 +0200
commit9cf2710dc95f1c81e8c5111e22681836225e32e2 (patch)
tree038167b4e81d8300741034d44eb4dceb64eef474 /Library
parent78f8c60343b514ee7129cf3c86f216460a4ed3ab (diff)
downloadbrew-9cf2710dc95f1c81e8c5111e22681836225e32e2.tar.bz2
os/mac/*_mach: move shared code into 'SharedMachO' (#282)
Both the `CctoolsMachO` and `RubyMachO` module implement a common set of methods that simplify querying `mach_data`. Move these into a shared module, that gets included after either of these implementations is loaded and included in `Pathname`.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/os/mac/cctools_mach.rb49
-rw-r--r--Library/Homebrew/os/mac/pathname.rb4
-rw-r--r--Library/Homebrew/os/mac/ruby_mach.rb48
-rw-r--r--Library/Homebrew/os/mac/shared_mach.rb50
4 files changed, 54 insertions, 97 deletions
diff --git a/Library/Homebrew/os/mac/cctools_mach.rb b/Library/Homebrew/os/mac/cctools_mach.rb
index 60f12a7ee..36f508d28 100644
--- a/Library/Homebrew/os/mac/cctools_mach.rb
+++ b/Library/Homebrew/os/mac/cctools_mach.rb
@@ -1,5 +1,3 @@
-require "os/mac/architecture_list"
-
module CctoolsMachO
# @private
OTOOL_RX = /\t(.*) \(compatibility version (?:\d+\.)*\d+, current version (?:\d+\.)*\d+\)/
@@ -54,53 +52,6 @@ module CctoolsMachO
end
end
- def archs
- mach_data.map { |m| m.fetch :arch }.extend(ArchitectureListExtension)
- end
-
- def arch
- case archs.length
- when 0 then :dunno
- when 1 then archs.first
- else :universal
- end
- end
-
- def universal?
- arch == :universal
- end
-
- def i386?
- arch == :i386
- end
-
- def x86_64?
- arch == :x86_64
- end
-
- def ppc7400?
- arch == :ppc7400
- end
-
- def ppc64?
- arch == :ppc64
- end
-
- # @private
- def dylib?
- mach_data.any? { |m| m.fetch(:type) == :dylib }
- end
-
- # @private
- def mach_o_executable?
- mach_data.any? { |m| m.fetch(:type) == :executable }
- end
-
- # @private
- def mach_o_bundle?
- mach_data.any? { |m| m.fetch(:type) == :bundle }
- end
-
# @private
class Metadata
attr_reader :path, :dylib_id, :dylibs
diff --git a/Library/Homebrew/os/mac/pathname.rb b/Library/Homebrew/os/mac/pathname.rb
index fbe4ad5ec..87fc72936 100644
--- a/Library/Homebrew/os/mac/pathname.rb
+++ b/Library/Homebrew/os/mac/pathname.rb
@@ -1,3 +1,5 @@
+require "os/mac/shared_mach"
+
class Pathname
if ENV["HOMEBREW_RUBY_MACHO"]
require "os/mac/ruby_mach"
@@ -6,4 +8,6 @@ class Pathname
require "os/mac/cctools_mach"
include CctoolsMachO
end
+
+ include SharedMachO
end
diff --git a/Library/Homebrew/os/mac/ruby_mach.rb b/Library/Homebrew/os/mac/ruby_mach.rb
index adef7b661..07761e7fc 100644
--- a/Library/Homebrew/os/mac/ruby_mach.rb
+++ b/Library/Homebrew/os/mac/ruby_mach.rb
@@ -1,5 +1,4 @@
require "vendor/macho/macho"
-require "os/mac/architecture_list"
module RubyMachO
# @private
@@ -54,53 +53,6 @@ module RubyMachO
end
end
- def archs
- mach_data.map { |m| m.fetch :arch }.extend(ArchitectureListExtension)
- end
-
- def arch
- case archs.length
- when 0 then :dunno
- when 1 then archs.first
- else :universal
- end
- end
-
- def universal?
- arch == :universal
- end
-
- def i386?
- arch == :i386
- end
-
- def x86_64?
- arch == :x86_64
- end
-
- def ppc7400?
- arch == :ppc7400
- end
-
- def ppc64?
- arch == :ppc64
- end
-
- # @private
- def dylib?
- mach_data.any? { |m| m.fetch(:type) == :dylib }
- end
-
- # @private
- def mach_o_executable?
- mach_data.any? { |m| m.fetch(:type) == :executable }
- end
-
- # @private
- def mach_o_bundle?
- mach_data.any? { |m| m.fetch(:type) == :bundle }
- end
-
def dynamically_linked_libraries
macho.linked_dylibs
end
diff --git a/Library/Homebrew/os/mac/shared_mach.rb b/Library/Homebrew/os/mac/shared_mach.rb
new file mode 100644
index 000000000..aa8baa92e
--- /dev/null
+++ b/Library/Homebrew/os/mac/shared_mach.rb
@@ -0,0 +1,50 @@
+require "os/mac/architecture_list"
+
+module SharedMachO
+ def archs
+ mach_data.map { |m| m.fetch :arch }.extend(ArchitectureListExtension)
+ end
+
+ def arch
+ case archs.length
+ when 0 then :dunno
+ when 1 then archs.first
+ else :universal
+ end
+ end
+
+ def universal?
+ arch == :universal
+ end
+
+ def i386?
+ arch == :i386
+ end
+
+ def x86_64?
+ arch == :x86_64
+ end
+
+ def ppc7400?
+ arch == :ppc7400
+ end
+
+ def ppc64?
+ arch == :ppc64
+ end
+
+ # @private
+ def dylib?
+ mach_data.any? { |m| m.fetch(:type) == :dylib }
+ end
+
+ # @private
+ def mach_o_executable?
+ mach_data.any? { |m| m.fetch(:type) == :executable }
+ end
+
+ # @private
+ def mach_o_bundle?
+ mach_data.any? { |m| m.fetch(:type) == :bundle }
+ end
+end