@@ -59,6 +59,8 @@ def clean
59
59
observe_file_removal info_dir_file
60
60
end
61
61
62
+ # TODO: rewrite_config_scripts
63
+ rewrite_pkgconfig
62
64
rewrite_shebangs
63
65
clean_python_metadata
64
66
@@ -153,6 +155,40 @@ def clean_dir(directory)
153
155
end
154
156
end
155
157
158
+ sig { void }
159
+ def rewrite_pkgconfig
160
+ pc_files = [ @formula . lib . realpath , @formula . share . realpath ] . flat_map do |d |
161
+ next [ ] if @formula . skip_clean? ( d ) || @formula . skip_clean? ( d /"pkgconfig" )
162
+
163
+ d . glob ( "pkgconfig/*" )
164
+ end
165
+ return if pc_files . empty?
166
+
167
+ keg_only_pc_files = @formula . deps
168
+ . reject { |d | d . build? || d . test? }
169
+ . map ( &:to_formula )
170
+ . select ( &:keg_only? )
171
+ . flat_map { |f | f . prefix . glob ( "{lib,share}/pkgconfig/*.pc" ) }
172
+ . to_h { |pc_file | [ pc_file . basename ( ".pc" ) . to_s , pc_file . to_s ] }
173
+ keg_only_modules_pattern = keg_only_pc_files . keys . map { |mod | Regexp . escape ( mod ) } . join ( "|" )
174
+
175
+ pc_files . each do |pc_file |
176
+ any_modification = T . let ( false , T ::Boolean )
177
+ lines = pc_file . each_line . map do |line |
178
+ any_modification ||= line . gsub! ( @formula . prefix . realpath . to_s , @formula . opt_prefix . to_s ) . present?
179
+ next line if keg_only_pc_files . empty? || !line . start_with? ( /Requires(?:\. private)?:/ )
180
+
181
+ line . gsub ( /(?<=[:,\s ])(#{ keg_only_modules_pattern } )(?=[<=>!,\s ])/ ) do |match |
182
+ any_modification ||= keg_only_pc_files . include? ( match )
183
+ keg_only_pc_files [ match ] || match
184
+ end
185
+ end
186
+ next unless any_modification
187
+
188
+ pc_file . atomic_write ( lines . join )
189
+ end
190
+ end
191
+
156
192
sig { void }
157
193
def rewrite_shebangs
158
194
require "language/node"
0 commit comments