Merge pull request #19174 from alebcay/pod2man-shim

Clean pod2man-generated manpages after formula build
This commit is contained in:
Caleb Xu 2025-02-26 13:55:34 +00:00 committed by GitHub
commit 0c2c76351c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 0 deletions

View File

@ -188,6 +188,8 @@ class Build
# Find and link metafiles # Find and link metafiles
formula.prefix.install_metafiles formula.buildpath formula.prefix.install_metafiles formula.buildpath
formula.prefix.install_metafiles formula.libexec if formula.libexec.exist? formula.prefix.install_metafiles formula.libexec if formula.libexec.exist?
normalize_pod2man_outputs!(formula)
end end
end end
end end
@ -217,6 +219,11 @@ class Build
rescue rescue
raise "#{formula.opt_prefix} not present or broken\nPlease reinstall #{formula.full_name}. Sorry :(" raise "#{formula.opt_prefix} not present or broken\nPlease reinstall #{formula.full_name}. Sorry :("
end end
def normalize_pod2man_outputs!(formula)
keg = Keg.new(formula.prefix)
keg.normalize_pod2man_outputs!
end
end end
begin begin

View File

@ -555,6 +555,31 @@ class Keg
path.find { |pn| FileUtils.rm_rf pn if pn.basename.to_s == "__pycache__" } path.find { |pn| FileUtils.rm_rf pn if pn.basename.to_s == "__pycache__" }
end end
def normalize_pod2man_outputs!
manpages = Dir[path/"share/man/*/*"]
generated_regex = /^\.\\"\s*Automatically generated by .*\n/
manpages.each do |f|
manpage = Pathname.new(f)
next unless manpage.file?
content = manpage.read
content = content.gsub(generated_regex, "")
content = content.lines.map do |line|
next line unless line.start_with?(".TH")
# Split the line by spaces, but preserve quoted strings
parts = line.split(/\s(?=(?:[^"]|"[^"]*")*$)/)
next line if parts.length != 6
# pod2man embeds the perl version used into the 5th field of the footer
T.must(parts[4]).gsub!(/^"perl v.*"$/, "\"\"")
"#{parts.join(" ")}\n"
end.join
manpage.atomic_write(content)
end
end
def binary_executable_or_library_files def binary_executable_or_library_files
[] []
end end