From bc2c12c7423d0c5414195134817bf02fa28382df Mon Sep 17 00:00:00 2001 From: botantony Date: Tue, 9 Sep 2025 18:13:13 +0200 Subject: [PATCH] os/mac/*: style corrections Signed-off-by: botantony Co-authored-by: Mike McQuaid --- Library/Homebrew/os/mac/keg.rb | 21 ++++++++++++++------- Library/Homebrew/os/mac/mach.rb | 25 ++++++++++++------------- Library/Homebrew/os/mac/sdk.rb | 17 +++++++++-------- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/Library/Homebrew/os/mac/keg.rb b/Library/Homebrew/os/mac/keg.rb index 8c78c3d6d8..30c76420b3 100644 --- a/Library/Homebrew/os/mac/keg.rb +++ b/Library/Homebrew/os/mac/keg.rb @@ -2,13 +2,20 @@ # frozen_string_literal: true class Keg + sig { params(path: Pathname).void } + def initialize(path) + super + + @require_relocation = T.let(nil, T.nilable(T::Boolean)) + end + sig { params(id: String, file: Pathname).returns(T::Boolean) } def change_dylib_id(id, file) return false if file.dylib_id == id - @require_relocation = T.let(true, T.nilable(T::Boolean)) + @require_relocation = true odebug "Changing dylib ID of #{file}\n from #{file.dylib_id}\n to #{id}" - file.change_dylib_id(id, strict: false) + file.change_dylib_id(id) true rescue MachO::MachOError onoe <<~EOS @@ -23,9 +30,9 @@ class Keg def change_install_name(old, new, file) return false if old == new - @require_relocation = T.let(true, T.nilable(T::Boolean)) + @require_relocation = true odebug "Changing install name in #{file}\n from #{old}\n to #{new}" - file.change_install_name(old, new, strict: false) + file.change_install_name(old, new) true rescue MachO::MachOError onoe <<~EOS @@ -40,9 +47,9 @@ class Keg def change_rpath(old, new, file) return false if old == new - @require_relocation = T.let(true, T.nilable(T::Boolean)) + @require_relocation = true odebug "Changing rpath in #{file}\n from #{old}\n to #{new}" - file.change_rpath(old, new, strict: false) + file.change_rpath(old, new) true rescue MachO::MachOError onoe <<~EOS @@ -56,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, strict: false) + file.delete_rpath(rpath) true rescue MachO::MachOError onoe <<~EOS diff --git a/Library/Homebrew/os/mac/mach.rb b/Library/Homebrew/os/mac/mach.rb index 4f29aedcad..b44a13ab98 100644 --- a/Library/Homebrew/os/mac/mach.rb +++ b/Library/Homebrew/os/mac/mach.rb @@ -70,35 +70,34 @@ 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, options: T::Boolean).void } - def delete_rpath(rpath, **options) + sig { params(rpath: String).void } + def delete_rpath(rpath) candidates = rpaths(resolve_variable_references: false).select do |r| resolve_variable_name(r) == resolve_variable_name(rpath) end # Delete the last instance to avoid changing the order in which rpaths are searched. rpath_to_delete = candidates.last - options[:last] = true - macho.delete_rpath(rpath_to_delete, options) + macho.delete_rpath(rpath_to_delete, { last: true }) macho.write! end - sig { params(old: String, new: String, options: T::Boolean).void } - def change_rpath(old, new, **options) - macho.change_rpath(old, new, options) + 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 }) macho.write! end - sig { params(id: String, options: T::Boolean).void } - def change_dylib_id(id, **options) - macho.change_dylib_id(id, options) + sig { params(id: String).void } + def change_dylib_id(id) + macho.change_dylib_id(id) macho.write! end - sig { params(old: String, new: String, options: T::Boolean).void } - def change_install_name(old, new, **options) - macho.change_install_name(old, new, options) + sig { params(old: String, new: String).void } + def change_install_name(old, new) + macho.change_install_name(old, new) macho.write! end diff --git a/Library/Homebrew/os/mac/sdk.rb b/Library/Homebrew/os/mac/sdk.rb index 89a69d42be..e5ea0f2a19 100644 --- a/Library/Homebrew/os/mac/sdk.rb +++ b/Library/Homebrew/os/mac/sdk.rb @@ -22,7 +22,7 @@ module OS sig { params(version: MacOSVersion, path: T.any(String, Pathname), source: Symbol).void } def initialize(version, path, source) @version = version - @path = T.let(Pathname.new(path), Pathname) + @path = T.let(Pathname(path), Pathname) @source = source end end @@ -39,6 +39,7 @@ module OS sig { void } def initialize @all_sdks = T.let([], T::Array[SDK]) + @sdk_prefix = T.let(nil, T.nilable(String)) end sig { params(version: MacOSVersion).returns(SDK) } @@ -150,7 +151,7 @@ module OS sig { override.returns(String) } def sdk_prefix - @sdk_prefix ||= T.let(begin + @sdk_prefix ||= begin # Xcode.prefix is pretty smart, so let's look inside to find the sdk sdk_prefix = "#{Xcode.prefix}/Platforms/MacOSX.platform/Developer/SDKs" # Finally query Xcode itself (this is slow, so check it last) @@ -158,7 +159,7 @@ module OS sdk_prefix = File.join(sdk_platform_path, "Developer", "SDKs") unless File.directory? sdk_prefix sdk_prefix - end, T.nilable(String)) + end end end @@ -180,11 +181,11 @@ module OS # return `nil` SDKs for Xcode 9 and older. sig { override.returns(String) } def sdk_prefix - @sdk_prefix ||= T.let(if CLT.provides_sdk? - "#{CLT::PKG_PATH}/SDKs" - else - "" - end, T.nilable(String)) + @sdk_prefix ||= if CLT.provides_sdk? + "#{CLT::PKG_PATH}/SDKs" + else + "" + end end end end