Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean pod2man-generated manpages after formula build #19174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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)

Check warning on line 561 in Library/Homebrew/keg.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/keg.rb#L558-L561

Added lines #L558 - L561 were not covered by tests
next unless manpage.file?

content = manpage.read
content = content.gsub(generated_regex, "")
content = content.lines.map do |line|

Check warning on line 566 in Library/Homebrew/keg.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/keg.rb#L564-L566

Added lines #L564 - L566 were not covered by tests
next line unless line.start_with?(".TH")

# Split the line by spaces, but preserve quoted strings
parts = line.split(/\s(?=(?:[^"]|"[^"]*")*$)/)

Check warning on line 570 in Library/Homebrew/keg.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/keg.rb#L570

Added line #L570 was not covered by tests
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"

Check warning on line 575 in Library/Homebrew/keg.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/keg.rb#L574-L575

Added lines #L574 - L575 were not covered by tests
end.join

manpage.atomic_write(content)

Check warning on line 578 in Library/Homebrew/keg.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/keg.rb#L578

Added line #L578 was not covered by tests
end
end

def binary_executable_or_library_files
[]
end
Expand Down
Loading