diff --git a/Library/Homebrew/os/mac/keg.rb b/Library/Homebrew/os/mac/keg.rb index 30c76420b3..ebe0f17d7f 100644 --- a/Library/Homebrew/os/mac/keg.rb +++ b/Library/Homebrew/os/mac/keg.rb @@ -6,7 +6,7 @@ class Keg def initialize(path) super - @require_relocation = T.let(nil, T.nilable(T::Boolean)) + @require_relocation = T.let(false, T::Boolean) end sig { params(id: String, file: Pathname).returns(T::Boolean) } @@ -15,7 +15,7 @@ class Keg @require_relocation = true odebug "Changing dylib ID of #{file}\n from #{file.dylib_id}\n to #{id}" - file.change_dylib_id(id) + file.change_dylib_id(id, strict: false) true rescue MachO::MachOError onoe <<~EOS @@ -32,7 +32,7 @@ class Keg @require_relocation = true odebug "Changing install name in #{file}\n from #{old}\n to #{new}" - file.change_install_name(old, new) + file.change_install_name(old, new, strict: false) true rescue MachO::MachOError onoe <<~EOS @@ -49,7 +49,7 @@ class Keg @require_relocation = true odebug "Changing rpath in #{file}\n from #{old}\n to #{new}" - file.change_rpath(old, new) + file.change_rpath(old, new, strict: false) true rescue MachO::MachOError onoe <<~EOS @@ -63,7 +63,7 @@ class Keg sig { params(rpath: String, file: MachOShim).returns(T::Boolean) } def delete_rpath(rpath, file) odebug "Deleting rpath #{rpath} in #{file}" - file.delete_rpath(rpath) + file.delete_rpath(rpath, strict: false) true rescue MachO::MachOError onoe <<~EOS diff --git a/Library/Homebrew/os/mac/mach.rb b/Library/Homebrew/os/mac/mach.rb index b44a13ab98..5a0a27566a 100644 --- a/Library/Homebrew/os/mac/mach.rb +++ b/Library/Homebrew/os/mac/mach.rb @@ -32,8 +32,9 @@ module MachOShim machos = [] mach_data = [] - if macho.is_a?(MachO::FatFile) - machos = T.cast(macho, MachO::FatFile).machos + case (macho = self.macho) + when MachO::FatFile + machos = macho.machos else machos << macho end @@ -70,8 +71,8 @@ module MachOShim # TODO: See if the `#write!` call can be delayed until # we know we're not making any changes to the rpaths. - sig { params(rpath: String).void } - def delete_rpath(rpath) + sig { params(rpath: String, strict: T::Boolean).void } + def delete_rpath(rpath, strict: true) candidates = rpaths(resolve_variable_references: false).select do |r| resolve_variable_name(r) == resolve_variable_name(rpath) end @@ -79,25 +80,25 @@ module MachOShim # Delete the last instance to avoid changing the order in which rpaths are searched. rpath_to_delete = candidates.last - macho.delete_rpath(rpath_to_delete, { last: true }) + macho.delete_rpath(rpath_to_delete, { last: true, strict: }) macho.write! end - sig { params(old: String, new: String, uniq: T::Boolean, last: T::Boolean).void } - def change_rpath(old, new, uniq: false, last: false) - macho.change_rpath(old, new, { uniq: uniq, last: last }) + sig { params(old: String, new: String, uniq: T::Boolean, last: T::Boolean, strict: T::Boolean).void } + def change_rpath(old, new, uniq: false, last: false, strict: true) + macho.change_rpath(old, new, { uniq:, last:, strict: }) macho.write! end - sig { params(id: String).void } - def change_dylib_id(id) - macho.change_dylib_id(id) + sig { params(id: String, strict: T::Boolean).void } + def change_dylib_id(id, strict: true) + macho.change_dylib_id(id, { strict: }) macho.write! end - sig { params(old: String, new: String).void } - def change_install_name(old, new) - macho.change_install_name(old, new) + sig { params(old: String, new: String, strict: T::Boolean).void } + def change_install_name(old, new, strict: true) + macho.change_install_name(old, new, { strict: }) macho.write! end diff --git a/Library/Homebrew/os/mac/sdk.rb b/Library/Homebrew/os/mac/sdk.rb index e5ea0f2a19..498fd8e3bb 100644 --- a/Library/Homebrew/os/mac/sdk.rb +++ b/Library/Homebrew/os/mac/sdk.rb @@ -38,7 +38,7 @@ module OS sig { void } def initialize - @all_sdks = T.let([], T::Array[SDK]) + @all_sdks = T.let(nil, T.nilable(T::Array[SDK])) @sdk_prefix = T.let(nil, T.nilable(String)) end @@ -52,7 +52,9 @@ module OS sig { returns(T::Array[SDK]) } def all_sdks - return @all_sdks unless @all_sdks.empty? + return @all_sdks if @all_sdks + + @all_sdks = [] # Bail out if there is no SDK prefix at all return @all_sdks unless File.directory? sdk_prefix