Skip to content

Commit 981312f

Browse files
committed
shims/super: add pod2man shim
1 parent c757219 commit 981312f

File tree

5 files changed

+96
-2
lines changed

5 files changed

+96
-2
lines changed

Diff for: Library/Homebrew/shims/linux/super/pod2man

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../super/pod2man

Diff for: Library/Homebrew/shims/mac/super/pod2man

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../super/pod2man

Diff for: Library/Homebrew/shims/super/pod2man

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
# vim: ft=ruby
3+
# Make sure this shim uses the same Ruby interpreter that is used by Homebrew.
4+
if [[ -z "${HOMEBREW_RUBY_PATH}" ]]
5+
then
6+
echo "${0##*/}: The build tool has reset ENV; --env=std required." >&2
7+
exit 1
8+
fi
9+
unset RUBYLIB
10+
exec "${HOMEBREW_RUBY_PATH}" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt -x "$0" "$@"
11+
#!/usr/bin/env ruby -W0
12+
13+
require "open3"
14+
require "pathname"
15+
16+
def split_args(args)
17+
options = []
18+
positional_args = []
19+
args.each do |arg|
20+
# `-` is stdin, so treat it as a positional argument
21+
if arg.start_with?("-") && arg != "-"
22+
options << arg
23+
else
24+
positional_args << arg
25+
end
26+
end
27+
[options, positional_args]
28+
end
29+
30+
def remove_superbin_from_path(paths)
31+
superbin = Pathname.new(__FILE__).dirname.realpath
32+
paths.reject do |x|
33+
path = Pathname.new(x)
34+
path.directory? && path.realpath == superbin
35+
end
36+
end
37+
38+
if __FILE__ == $PROGRAM_NAME
39+
dirname, tool = File.split($PROGRAM_NAME)
40+
separated_args = split_args(ARGV)
41+
options = separated_args[0]
42+
positional_args = separated_args[1]
43+
44+
# pod2man will not accept an empty string for --release, so use a space instead.
45+
# Set this to avoid the perl version from being included in the generated docs.
46+
# By prepending, the caller may choose to override this value to something else (later
47+
# args take precedence).
48+
options.prepend "--release= "
49+
50+
# pod2man accepts any provided positional arguments as input and output pairs. The first
51+
# argument is always assumed to be input. If there is an odd number of positional arguments,
52+
# the output of the last input will be emitted to stdout.
53+
outputs = []
54+
positional_args.each_slice(2) { |_, output| outputs << output unless output.nil? }
55+
56+
paths = ENV["PATH"].split(":")
57+
paths = remove_superbin_from_path(paths)
58+
paths.unshift "#{ENV["HOMEBREW_PREFIX"]}/bin"
59+
ENV["PATH"] = paths.join(":")
60+
61+
# Wrap the execution of the real pod2man. Don't use exec, because we need to
62+
# clean non-deterministic contents from the output files afterwards.
63+
Open3.popen3(tool, *options, *positional_args) do |stdin, stdout, stderr, wait_thr|
64+
# Clean any non-deterministic contents from output emitted via stdout
65+
Thread.new do
66+
stdout.each do |line|
67+
$stdout.puts line.gsub(/^\.\\"\s*Automatically generated by .*\n/, "")
68+
end
69+
end
70+
71+
Thread.new do
72+
stderr.each { |line| $stderr.puts line }
73+
end
74+
75+
while !$stdin.tty? && $stdin.gets
76+
stdin.puts $_
77+
end
78+
79+
stdin.close
80+
wait_thr.value
81+
end
82+
83+
outputs.each do |output|
84+
next if output == "-"
85+
86+
str = File.binread(output).gsub(/^\.\\"\s*Automatically generated by .*\n/, "")
87+
File.write(output, str)
88+
end
89+
end

Diff for: Library/Homebrew/style.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ def self.json_result!(result)
302302
JSON.parse(result.stdout)
303303
end
304304

305+
NON_SHELL_SHIMS = %w[cc pod2man].freeze
306+
305307
def self.shell_scripts
306308
[
307309
HOMEBREW_ORIGINAL_BREW_FILE,
@@ -312,7 +314,7 @@ def self.shell_scripts
312314
*HOMEBREW_LIBRARY.glob("Homebrew/**/*.sh").reject { |path| path.to_s.include?("/vendor/") },
313315
*HOMEBREW_LIBRARY.glob("Homebrew/shims/**/*").map(&:realpath).uniq
314316
.reject(&:directory?)
315-
.reject { |path| path.basename.to_s == "cc" }
317+
.reject { |path| NON_SHELL_SHIMS.include? path.basename.to_s }
316318
.select do |path|
317319
%r{^#! ?/bin/(?:ba)?sh( |$)}.match?(path.read(13))
318320
end,

Diff for: Library/Homebrew/test/bash_spec.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@
4242

4343
describe "every shim script" do
4444
it "has valid Bash syntax" do
45+
shims_to_skip = %w[cc pod2man].freeze # `bash -n` tries to parse the Ruby part
4546
# These have no file extension, but can be identified by their shebang.
4647
(HOMEBREW_LIBRARY_PATH/"shims").find do |path|
4748
next if path.directory?
4849
next if path.symlink?
4950
next unless path.executable?
50-
next if path.basename.to_s == "cc" # `bash -n` tries to parse the Ruby part
51+
next if shims_to_skip.include? path.basename.to_s
5152
next if path.read(12) != "#!/bin/bash\n"
5253

5354
expect(path).to have_valid_bash_syntax

0 commit comments

Comments
 (0)