Skip to content

Commit 652f596

Browse files
committed
Clean pod2man-generated manpages after formula build
1 parent c5e2aa6 commit 652f596

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
@@ -185,6 +185,8 @@ def install
185185
# Find and link metafiles
186186
formula.prefix.install_metafiles formula.buildpath
187187
formula.prefix.install_metafiles formula.libexec if formula.libexec.exist?
188+
189+
normalize_pod2man_outputs!(formula)
188190
end
189191
end
190192
end
@@ -214,6 +216,11 @@ def fixopt(formula)
214216
rescue
215217
raise "#{formula.opt_prefix} not present or broken\nPlease reinstall #{formula.full_name}. Sorry :("
216218
end
219+
220+
def normalize_pod2man_outputs!(formula)
221+
keg = Keg.new(formula.prefix)
222+
keg.normalize_pod2man_outputs!
223+
end
217224
end
218225

219226
begin

Diff for: Library/Homebrew/keg.rb

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

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

0 commit comments

Comments
 (0)