keg_relocate: only replace matches at the start of a path
This commit is contained in:
parent
ef000d0c3b
commit
db8f54cea1
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user