Merge pull request #18638 from Homebrew/keg_relocate-type-fix

keg_relocate: fix error when dylib_id doesn't need changing
This commit is contained in:
Bo Anderson 2024-10-26 06:45:57 +01:00 committed by GitHub
commit b34e6ee20e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 4 deletions

View File

@ -28,7 +28,7 @@ module OS
if file.dylib? if file.dylib?
id = relocated_name_for(file.dylib_id, relocation) id = relocated_name_for(file.dylib_id, relocation)
modified = change_dylib_id(id, file) modified = change_dylib_id(id, file) if id
needs_codesigning ||= modified needs_codesigning ||= modified
end end
@ -151,6 +151,7 @@ module OS
(opt_record/relative_dirname/basename).to_s (opt_record/relative_dirname/basename).to_s
end end
sig { params(old_name: String, relocation: ::Keg::Relocation).returns(T.nilable(String)) }
def relocated_name_for(old_name, relocation) def relocated_name_for(old_name, relocation)
old_prefix, new_prefix = relocation.replacement_pair_for(:prefix) old_prefix, new_prefix = relocation.replacement_pair_for(:prefix)
old_cellar, new_cellar = relocation.replacement_pair_for(:cellar) old_cellar, new_cellar = relocation.replacement_pair_for(:cellar)

View File

@ -15,7 +15,7 @@ class Keg
RELOCATABLE_PATH_REGEX_PREFIX = /(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))/ RELOCATABLE_PATH_REGEX_PREFIX = /(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))/
def initialize def initialize
@replacement_map = {} @replacement_map = T.let({}, T::Hash[Symbol, [T.any(String, Regexp), String]])
end end
def freeze def freeze
@ -29,7 +29,7 @@ class Keg
@replacement_map[key] = [old_value, new_value] @replacement_map[key] = [old_value, new_value]
end end
sig { params(key: Symbol).returns(T::Array[T.any(String, Regexp)]) } sig { params(key: Symbol).returns([T.any(String, Regexp), String]) }
def replacement_pair_for(key) def replacement_pair_for(key)
@replacement_map.fetch(key) @replacement_map.fetch(key)
end end
@ -44,7 +44,7 @@ class Keg
any_changed = T.let(nil, T.nilable(String)) any_changed = T.let(nil, T.nilable(String))
sorted_keys.each do |key| sorted_keys.each do |key|
changed = text.gsub!(key, replacements[key]) changed = text.gsub!(key, replacements.fetch(key))
any_changed ||= changed any_changed ||= changed
end end
!any_changed.nil? !any_changed.nil?