From 79b124b78d04bc57ac5d0df67a0dcca8dbbcb922 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Mon, 7 Nov 2016 19:37:52 -0500 Subject: [PATCH 1/2] os/mac: Allow MachO.dynamically_linked_libraries to be filtered by dylib type. This allows us to filter out weak linkages during audits, preventing a false error from occurring when the dylib cannot be found. --- Library/Homebrew/os/mac/linkage_checker.rb | 5 ++++- Library/Homebrew/os/mac/mach.rb | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/os/mac/linkage_checker.rb b/Library/Homebrew/os/mac/linkage_checker.rb index e014e38169..e72227fc48 100644 --- a/Library/Homebrew/os/mac/linkage_checker.rb +++ b/Library/Homebrew/os/mac/linkage_checker.rb @@ -23,7 +23,10 @@ class LinkageChecker @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 diff --git a/Library/Homebrew/os/mac/mach.rb b/Library/Homebrew/os/mac/mach.rb index 07598a23dd..44c5ee50ad 100644 --- a/Library/Homebrew/os/mac/mach.rb +++ b/Library/Homebrew/os/mac/mach.rb @@ -51,8 +51,10 @@ module MachO 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 From 126c15d9ae7459bea801ef9d33f344e799c0f512 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Tue, 8 Nov 2016 16:16:34 -0500 Subject: [PATCH 2/2] os/mac: Rename MachO -> MachOShim Prevents namespace conflict with vendored ruby-macho. --- Library/Homebrew/os/mac/mach.rb | 2 +- Library/Homebrew/os/mac/pathname.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/os/mac/mach.rb b/Library/Homebrew/os/mac/mach.rb index 44c5ee50ad..4113a06018 100644 --- a/Library/Homebrew/os/mac/mach.rb +++ b/Library/Homebrew/os/mac/mach.rb @@ -1,7 +1,7 @@ require "vendor/macho/macho" require "os/mac/architecture_list" -module MachO +module MachOShim # @private def macho @macho ||= begin diff --git a/Library/Homebrew/os/mac/pathname.rb b/Library/Homebrew/os/mac/pathname.rb index 9b65d7ac02..5fd59e1e79 100644 --- a/Library/Homebrew/os/mac/pathname.rb +++ b/Library/Homebrew/os/mac/pathname.rb @@ -1,5 +1,5 @@ require "os/mac/mach" class Pathname - include MachO + include MachOShim end