@@ -195,6 +195,13 @@ def openjdk_dep_name_if_applicable
195
195
dep_names . find { |d | d . match? Version . formula_optionally_versioned_regex ( :openjdk ) }
196
196
end
197
197
198
+ sig { params ( file : Pathname ) . returns ( T ::Boolean ) }
199
+ def homebrew_created_file? ( file )
200
+ return false unless file . basename . to_s . start_with? ( "homebrew." )
201
+
202
+ %w[ .plist .service .timer ] . include? ( file . extname )
203
+ end
204
+
198
205
sig { params ( relocation : Relocation , files : T . nilable ( T ::Array [ Pathname ] ) ) . returns ( T ::Array [ Pathname ] ) }
199
206
def replace_text_in_files ( relocation , files : nil )
200
207
files ||= text_files | libtool_files
@@ -203,7 +210,22 @@ def replace_text_in_files(relocation, files: nil)
203
210
files . map { path . join ( _1 ) } . group_by { |f | f . stat . ino } . each_value do |first , *rest |
204
211
s = first . open ( "rb" , &:read )
205
212
206
- next unless relocation . replace_text! ( s )
213
+ # Use full prefix replacement for Homebrew-created files when using selective relocation
214
+ current_relocation = if new_usr_local_relocation? && homebrew_created_file? ( first )
215
+ full_relocation = Relocation . new
216
+ full_relocation . add_replacement_pair ( :prefix , HOMEBREW_PREFIX . to_s , PREFIX_PLACEHOLDER , path : true )
217
+ full_relocation . add_replacement_pair ( :cellar , HOMEBREW_CELLAR . to_s , CELLAR_PLACEHOLDER , path : true )
218
+ if HOMEBREW_PREFIX != HOMEBREW_REPOSITORY
219
+ full_relocation . add_replacement_pair ( :repository , HOMEBREW_REPOSITORY . to_s , REPOSITORY_PLACEHOLDER ,
220
+ path : true )
221
+ end
222
+ full_relocation . add_replacement_pair ( :library , HOMEBREW_LIBRARY . to_s , LIBRARY_PLACEHOLDER , path : true )
223
+ full_relocation
224
+ else
225
+ relocation
226
+ end
227
+
228
+ next unless current_relocation . replace_text! ( s )
207
229
208
230
changed_files += [ first , *rest ] . map { |file | file . relative_path_from ( path ) }
209
231
0 commit comments