Skip to content

Commit

Permalink
Clean pod2man-generated manpages after formula build
Browse files Browse the repository at this point in the history
  • Loading branch information
alebcay committed Feb 4, 2025
1 parent c5e2aa6 commit 594f0a9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Library/Homebrew/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ def install
# 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
Expand Down Expand Up @@ -214,6 +216,11 @@ def fixopt(formula)
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
Expand Down
25 changes: 25 additions & 0 deletions Library/Homebrew/keg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,31 @@ def delete_pyc_files!
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
parts[4].gsub!(/^"perl v.*"$/, "\"\"")
"#{parts.join(" ")}\n"
end.join

manpage.atomic_write(content)
end
end

def binary_executable_or_library_files
[]
end
Expand Down

0 comments on commit 594f0a9

Please sign in to comment.