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
|
class Relocation
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
|
RELOCATABLE_PATH_REGEX_PREFIX = /(?<![a-zA-Z0-9])/.freeze
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@replacement_map = {}
|
@replacement_map = {}
|
||||||
end
|
end
|
||||||
@ -22,7 +24,7 @@ class Keg
|
|||||||
|
|
||||||
sig { params(key: Symbol, old_value: T.any(String, Regexp), new_value: String).void }
|
sig { params(key: Symbol, old_value: T.any(String, Regexp), new_value: String).void }
|
||||||
def add_replacement_pair(key, old_value, new_value)
|
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
|
end
|
||||||
|
|
||||||
sig { params(key: Symbol).returns(T::Array[T.any(String, Regexp)]) }
|
sig { params(key: Symbol).returns(T::Array[T.any(String, Regexp)]) }
|
||||||
@ -45,6 +47,12 @@ class Keg
|
|||||||
end
|
end
|
||||||
any_changed
|
any_changed
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def fix_dynamic_linkage
|
def fix_dynamic_linkage
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user