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