Port Homebrew::Cmd::Postinstall

This commit is contained in:
Douglas Eichelberger 2024-04-01 09:53:38 -07:00
parent 31aa89aa7c
commit 427b527335
3 changed files with 26 additions and 27 deletions

View File

@ -1,35 +1,33 @@
# typed: true # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "abstract_command"
require "sandbox" require "sandbox"
require "formula_installer" require "formula_installer"
require "cli/parser"
module Homebrew module Homebrew
module_function module Cmd
class Postinstall < AbstractCommand
cmd_args do
description <<~EOS
Rerun the post-install steps for <formula>.
EOS
sig { returns(CLI::Parser) } named_args :installed_formula, min: 1
def postinstall_args end
Homebrew::CLI::Parser.new do
description <<~EOS
Rerun the post-install steps for <formula>.
EOS
named_args :installed_formula, min: 1 sig { override.void }
end def run
end args.named.to_resolved_formulae.each do |f|
ohai "Postinstalling #{f}"
def postinstall f.install_etc_var
args = postinstall_args.parse if f.post_install_defined?
fi = FormulaInstaller.new(f, **{ debug: args.debug?, quiet: args.quiet?, verbose: args.verbose? }.compact)
args.named.to_resolved_formulae.each do |f| fi.post_install
ohai "Postinstalling #{f}" else
f.install_etc_var opoo "#{f}: no `post_install` method was defined in the formula!"
if f.post_install_defined? end
fi = FormulaInstaller.new(f, **{ debug: args.debug?, quiet: args.quiet?, verbose: args.verbose? }.compact) end
fi.post_install
else
opoo "#{f}: no `post_install` method was defined in the formula!"
end end
end end
end end

View File

@ -12,13 +12,13 @@ require "cli/parser"
require "cmd/postinstall" require "cmd/postinstall"
begin begin
args = Homebrew.postinstall_args.parse args = Homebrew::Cmd::Postinstall.new.args
error_pipe = UNIXSocket.open(ENV.fetch("HOMEBREW_ERROR_PIPE"), &:recv_io) error_pipe = UNIXSocket.open(ENV.fetch("HOMEBREW_ERROR_PIPE"), &:recv_io)
error_pipe.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) error_pipe.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
trap("INT", old_trap) trap("INT", old_trap)
formula = args.named.to_resolved_formulae.first formula = T.must(args.named.to_resolved_formulae.first)
if args.debug? if args.debug?
require "debrew" require "debrew"
formula.extend(Debrew::Formula) formula.extend(Debrew::Formula)

View File

@ -1,7 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
require "cmd/postinstall"
require "cmd/shared_examples/args_parse" require "cmd/shared_examples/args_parse"
RSpec.describe "brew postinstall" do RSpec.describe Homebrew::Cmd::Postinstall do
it_behaves_like "parseable arguments" it_behaves_like "parseable arguments"
end end