Skip to content

Commit

Permalink
Merge pull request Homebrew#1469 from woodruffw/ruby-macho-revendor
Browse files Browse the repository at this point in the history
vendor: Update ruby-macho to 0.2.6.
  • Loading branch information
MikeMcQuaid authored Nov 10, 2016
2 parents 9889007 + 9267511 commit 42aa098
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 68 deletions.
5 changes: 4 additions & 1 deletion Library/Homebrew/os/mac/linkage_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def check_dylibs
@keg.find do |file|
next if file.symlink? || file.directory?
next unless file.dylib? || file.mach_o_executable? || file.mach_o_bundle?
file.dynamically_linked_libraries.each do |dylib|

# weakly loaded dylibs may not actually exist on disk, so skip them
# when checking for broken linkage
file.dynamically_linked_libraries(except: :LC_LOAD_WEAK_DYLIB).each do |dylib|
@reverse_links[dylib] << file
if dylib.start_with? "@"
@variable_dylibs << dylib
Expand Down
8 changes: 5 additions & 3 deletions Library/Homebrew/os/mac/mach.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "vendor/macho/macho"
require "os/mac/architecture_list"

module MachO
module MachOShim
# @private
def macho
@macho ||= begin
Expand Down Expand Up @@ -51,8 +51,10 @@ def mach_data
end
end

def dynamically_linked_libraries
macho.linked_dylibs
def dynamically_linked_libraries(except: :none)
lcs = macho.dylib_load_commands.reject { |lc| lc.type == except }

lcs.map(&:name).map(&:to_s)
end

def dylib_id
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/os/mac/pathname.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "os/mac/mach"

class Pathname
include MachO
include MachOShim
end
2 changes: 1 addition & 1 deletion Library/Homebrew/vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Vendored Dependencies

* [plist](https://github.com/bleything/plist), version 3.1.0

* [ruby-macho](https://github.com/Homebrew/ruby-macho), version 0.2.5
* [ruby-macho](https://github.com/Homebrew/ruby-macho), version 0.2.6

## Licenses:

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/vendor/macho/macho.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
# The primary namespace for ruby-macho.
module MachO
# release version
VERSION = "0.2.5".freeze
VERSION = "0.2.6".freeze
end
55 changes: 33 additions & 22 deletions Library/Homebrew/vendor/macho/macho/fat_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def initialize(filename)

@filename = filename
@raw_data = File.open(@filename, "rb", &:read)
@header = populate_fat_header
@fat_archs = populate_fat_archs
@machos = populate_machos
populate_fields
end

# Initializes a new FatFile instance from a binary string.
Expand All @@ -45,9 +43,7 @@ def initialize(filename)
def initialize_from_bin(bin)
@filename = nil
@raw_data = bin
@header = populate_fat_header
@fat_archs = populate_fat_archs
@machos = populate_machos
populate_fields
end

# The file's raw fat data.
Expand Down Expand Up @@ -122,6 +118,21 @@ def filetype
machos.first.filetype
end

# Populate the instance's fields with the raw Fat Mach-O data.
# @return [void]
# @note This method is public, but should (almost) never need to be called.
def populate_fields
@header = populate_fat_header
@fat_archs = populate_fat_archs
@machos = populate_machos
end

# All load commands responsible for loading dylibs in the file's Mach-O's.
# @return [Array<MachO::DylibCommand>] an array of DylibCommands
def dylib_load_commands
machos.map(&:dylib_load_commands).flatten
end

# The file's dylib ID. If the file is not a dylib, returns `nil`.
# @example
# file.dylib_id # => 'libBar.dylib'
Expand Down Expand Up @@ -149,7 +160,7 @@ def change_dylib_id(new_id, options = {})
macho.change_dylib_id(new_id, options)
end

synchronize_raw_data
repopulate_raw_machos
end

alias dylib_id= change_dylib_id
Expand Down Expand Up @@ -180,7 +191,7 @@ def change_install_name(old_name, new_name, options = {})
macho.change_install_name(old_name, new_name, options)
end

synchronize_raw_data
repopulate_raw_machos
end

alias change_dylib change_install_name
Expand All @@ -206,7 +217,7 @@ def change_rpath(old_path, new_path, options = {})
macho.change_rpath(old_path, new_path, options)
end

synchronize_raw_data
repopulate_raw_machos
end

# Add the given runtime path to the file's Mach-Os.
Expand All @@ -221,7 +232,7 @@ def add_rpath(path, options = {})
macho.add_rpath(path, options)
end

synchronize_raw_data
repopulate_raw_machos
end

# Delete the given runtime path from the file's Mach-Os.
Expand All @@ -236,7 +247,7 @@ def delete_rpath(path, options = {})
macho.delete_rpath(path, options)
end

synchronize_raw_data
repopulate_raw_machos
end

# Extract a Mach-O with the given CPU type from the file.
Expand Down Expand Up @@ -324,6 +335,17 @@ def populate_machos
machos
end

# Repopulate the raw Mach-O data with each internal Mach-O object.
# @return [void]
# @api private
def repopulate_raw_machos
machos.each_with_index do |macho, i|
arch = fat_archs[i]

@raw_data[arch.offset, arch.size] = macho.serialize
end
end

# Yield each Mach-O object in the file, rescuing and accumulating errors.
# @param options [Hash]
# @option options [Boolean] :strict (true) whether or not to fail loudly
Expand Down Expand Up @@ -351,16 +373,5 @@ def each_macho(options = {})
# Non-strict mode: Raise first error if *all* Mach-O slices failed.
raise errors.first if errors.size == machos.size
end

# Synchronize the raw file data with each internal Mach-O object.
# @return [void]
# @api private
def synchronize_raw_data
machos.each_with_index do |macho, i|
arch = fat_archs[i]

@raw_data[arch.offset, arch.size] = macho.serialize
end
end
end
end
40 changes: 1 addition & 39 deletions Library/Homebrew/vendor/macho/macho/load_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -612,52 +612,14 @@ def initialize(view, cmd, cmdsize, init_address, init_module, reserved1,
# A load command containing the address of the dynamic shared library
# initialization routine and an index into the module table for the module
# that defines the routine. Corresponds to LC_ROUTINES_64.
class RoutinesCommand64 < LoadCommand
# @return [Fixnum] the address of the initialization routine
attr_reader :init_address

# @return [Fixnum] the index into the module table that the init routine is defined in
attr_reader :init_module

# @return [void]
attr_reader :reserved1

# @return [void]
attr_reader :reserved2

# @return [void]
attr_reader :reserved3

# @return [void]
attr_reader :reserved4

# @return [void]
attr_reader :reserved5

# @return [void]
attr_reader :reserved6

class RoutinesCommand64 < RoutinesCommand
# @see MachOStructure::FORMAT
# @api private
FORMAT = "L=2Q=8".freeze

# @see MachOStructure::SIZEOF
# @api private
SIZEOF = 72

# @api private
def initialize(view, cmd, cmdsize, init_address, init_module, reserved1,
reserved2, reserved3, reserved4, reserved5, reserved6)
super(view, cmd, cmdsize)
@init_address = init_address
@init_module = init_module
@reserved1 = reserved1
@reserved2 = reserved2
@reserved3 = reserved3
@reserved4 = reserved4
@reserved5 = reserved5
@reserved6 = reserved6
end
end

# A load command signifying membership of a subframework containing the name
Expand Down

0 comments on commit 42aa098

Please sign in to comment.