keg_relocate: only replace matches at the start of a path

This commit is contained in:
Rylan Polster 2021-05-06 00:50:31 -04:00
parent ef000d0c3b
commit db8f54cea1
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64

View File

@ -11,6 +11,8 @@ class Keg
class Relocation
extend T::Sig
RELOCATABLE_PATH_REGEX_PREFIX = /(?<![a-zA-Z0-9])/.freeze
def initialize
@replacement_map = {}
end
@ -22,7 +24,7 @@ class Keg
sig { params(key: Symbol, old_value: T.any(String, Regexp), new_value: String).void }
def add_replacement_pair(key, old_value, new_value)
@replacement_map[key] = [old_value, new_value]
@replacement_map[key] = [path_replacement_regex(old_value), new_value]
end
sig { params(key: Symbol).returns(T::Array[T.any(String, Regexp)]) }
@ -45,6 +47,12 @@ class Keg
end
any_changed
end
sig { params(text: T.any(String, Regexp)).returns(Regexp) }
def self.path_replacement_regex(value)
value = Regexp.escape(value) if value.is_a? String
Regexp.new(RELOCATABLE_PATH_REGEX_PREFIX.source + Regexp.escape(value))
end
end
def fix_dynamic_linkage