From 861d7b908725501470a4b613f9619f62aefd5e41 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Sun, 29 Sep 2024 05:15:36 +0800 Subject: [PATCH 1/2] linkage_checker: skip files with incompatible architectures Some formulae include these files, and they can't always be removed. However, they can cause spurious linkage failures, so let's skip them when checking for linkage. See, for example, faust at Homebrew/homebrew-core#191308. --- Library/Homebrew/extend/pathname.rb | 5 +++++ Library/Homebrew/linkage_checker.rb | 1 + Library/Homebrew/os/linux/elf.rb | 6 ++++++ Library/Homebrew/os/mac/mach.rb | 7 +++++++ 4 files changed, 19 insertions(+) diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 0df8d17dd4..1f7a787376 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -469,6 +469,11 @@ class Pathname false end + sig { params(_wanted_arch: Symbol).returns(T::Boolean) } + def arch_compatible?(_wanted_arch) + false + end + sig { returns(T::Array[String]) } def rpaths [] diff --git a/Library/Homebrew/linkage_checker.rb b/Library/Homebrew/linkage_checker.rb index 1f3bb08cc3..7d98610424 100644 --- a/Library/Homebrew/linkage_checker.rb +++ b/Library/Homebrew/linkage_checker.rb @@ -115,6 +115,7 @@ class LinkageChecker @keg.find do |file| next if file.symlink? || file.directory? next if !file.dylib? && !file.binary_executable? && !file.mach_o_bundle? + next unless file.arch_compatible?(Hardware::CPU.arch) # weakly loaded dylibs may not actually exist on disk, so skip them # when checking for broken linkage diff --git a/Library/Homebrew/os/linux/elf.rb b/Library/Homebrew/os/linux/elf.rb index 91c4407670..116c9ea23f 100644 --- a/Library/Homebrew/os/linux/elf.rb +++ b/Library/Homebrew/os/linux/elf.rb @@ -68,6 +68,12 @@ module ELFShim end end + def arch_compatible?(wanted_arch) + return true unless elf? + + wanted_arch == arch + end + def elf_type return :dunno unless elf? diff --git a/Library/Homebrew/os/mac/mach.rb b/Library/Homebrew/os/mac/mach.rb index a632b3d128..fdb4ffd387 100644 --- a/Library/Homebrew/os/mac/mach.rb +++ b/Library/Homebrew/os/mac/mach.rb @@ -155,6 +155,13 @@ module MachOShim arch == :ppc64 end + def arch_compatible?(wanted_arch) + return true unless mach_data.present? + return arch == wanted_arch unless universal? + + archs.include?(wanted_arch) + end + def dylib? mach_data.any? { |m| m.fetch(:type) == :dylib } end From 6329db9065ae670f0f69454b3e58ec81ba7b3ea3 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Mon, 30 Sep 2024 22:29:03 +0800 Subject: [PATCH 2/2] Remove macOS implementation of `#arch_compatible?` We don't really need this. --- Library/Homebrew/extend/pathname.rb | 2 +- Library/Homebrew/os/mac/mach.rb | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 1f7a787376..49f5d0111d 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -471,7 +471,7 @@ class Pathname sig { params(_wanted_arch: Symbol).returns(T::Boolean) } def arch_compatible?(_wanted_arch) - false + true end sig { returns(T::Array[String]) } diff --git a/Library/Homebrew/os/mac/mach.rb b/Library/Homebrew/os/mac/mach.rb index fdb4ffd387..a632b3d128 100644 --- a/Library/Homebrew/os/mac/mach.rb +++ b/Library/Homebrew/os/mac/mach.rb @@ -155,13 +155,6 @@ module MachOShim arch == :ppc64 end - def arch_compatible?(wanted_arch) - return true unless mach_data.present? - return arch == wanted_arch unless universal? - - archs.include?(wanted_arch) - end - def dylib? mach_data.any? { |m| m.fetch(:type) == :dylib } end