Skip to content

Commit 0c2c763

Browse files
authored
Merge pull request #19174 from alebcay/pod2man-shim
Clean pod2man-generated manpages after formula build
2 parents 19332ee + 652f596 commit 0c2c763

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Diff for: Library/Homebrew/build.rb

+7
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ def install
188188
# Find and link metafiles
189189
formula.prefix.install_metafiles formula.buildpath
190190
formula.prefix.install_metafiles formula.libexec if formula.libexec.exist?
191+
192+
normalize_pod2man_outputs!(formula)
191193
end
192194
end
193195
end
@@ -217,6 +219,11 @@ def fixopt(formula)
217219
rescue
218220
raise "#{formula.opt_prefix} not present or broken\nPlease reinstall #{formula.full_name}. Sorry :("
219221
end
222+
223+
def normalize_pod2man_outputs!(formula)
224+
keg = Keg.new(formula.prefix)
225+
keg.normalize_pod2man_outputs!
226+
end
220227
end
221228

222229
begin

Diff for: Library/Homebrew/keg.rb

+25
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,31 @@ def delete_pyc_files!
555555
path.find { |pn| FileUtils.rm_rf pn if pn.basename.to_s == "__pycache__" }
556556
end
557557

558+
def normalize_pod2man_outputs!
559+
manpages = Dir[path/"share/man/*/*"]
560+
generated_regex = /^\.\\"\s*Automatically generated by .*\n/
561+
manpages.each do |f|
562+
manpage = Pathname.new(f)
563+
next unless manpage.file?
564+
565+
content = manpage.read
566+
content = content.gsub(generated_regex, "")
567+
content = content.lines.map do |line|
568+
next line unless line.start_with?(".TH")
569+
570+
# Split the line by spaces, but preserve quoted strings
571+
parts = line.split(/\s(?=(?:[^"]|"[^"]*")*$)/)
572+
next line if parts.length != 6
573+
574+
# pod2man embeds the perl version used into the 5th field of the footer
575+
T.must(parts[4]).gsub!(/^"perl v.*"$/, "\"\"")
576+
"#{parts.join(" ")}\n"
577+
end.join
578+
579+
manpage.atomic_write(content)
580+
end
581+
end
582+
558583
def binary_executable_or_library_files
559584
[]
560585
end

0 commit comments

Comments
 (0)