os/mac/*: style corrections

Signed-off-by: botantony <antonsm21@gmail.com>
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
botantony 2025-09-09 18:13:13 +02:00
parent 0adf85970d
commit bc2c12c742
No known key found for this signature in database
GPG Key ID: 7FE721557EA6AAD6
3 changed files with 35 additions and 28 deletions

View File

@ -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

View File

@ -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

View File

@ -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