From 652f5966d469b226f12f94a9e869464ee1580ac3 Mon Sep 17 00:00:00 2001 From: Caleb Xu Date: Mon, 3 Feb 2025 22:57:37 -0500 Subject: [PATCH] Clean pod2man-generated manpages after formula build --- Library/Homebrew/build.rb | 7 +++++++ Library/Homebrew/keg.rb | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index ae869d5e08..af091b6112 100644 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -185,6 +185,8 @@ class Build # Find and link metafiles formula.prefix.install_metafiles formula.buildpath formula.prefix.install_metafiles formula.libexec if formula.libexec.exist? + + normalize_pod2man_outputs!(formula) end end end @@ -214,6 +216,11 @@ class Build rescue raise "#{formula.opt_prefix} not present or broken\nPlease reinstall #{formula.full_name}. Sorry :(" end + + def normalize_pod2man_outputs!(formula) + keg = Keg.new(formula.prefix) + keg.normalize_pod2man_outputs! + end end begin diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index 0b0f67d256..bfc863f4d2 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -554,6 +554,31 @@ class Keg path.find { |pn| FileUtils.rm_rf pn if pn.basename.to_s == "__pycache__" } 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 [] end