Significantly improve install speeds with smarter postinstall detection
This commit is contained in:
parent
1c081f379d
commit
8dc2e80a98
@ -24,8 +24,11 @@ module Homebrew
|
||||
|
||||
args.named.to_resolved_formulae.each do |f|
|
||||
ohai "Postinstalling #{f}"
|
||||
fi = FormulaInstaller.new(f, **{ debug: args.debug?, quiet: args.quiet?, verbose: args.verbose? }.compact)
|
||||
fi.post_install
|
||||
f.install_etc_var
|
||||
if f.post_install_defined?
|
||||
fi = FormulaInstaller.new(f, **{ debug: args.debug?, quiet: args.quiet?, verbose: args.verbose? }.compact)
|
||||
fi.post_install
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1142,6 +1142,23 @@ class Formula
|
||||
sig { overridable.void }
|
||||
def post_install; end
|
||||
|
||||
# @private
|
||||
sig { returns(T::Boolean) }
|
||||
def post_install_defined?
|
||||
method(:post_install).owner != Formula
|
||||
end
|
||||
|
||||
# @private
|
||||
sig { void }
|
||||
def install_etc_var
|
||||
etc_var_dirs = [bottle_prefix/"etc", bottle_prefix/"var"]
|
||||
Find.find(*etc_var_dirs.select(&:directory?)) do |path|
|
||||
path = Pathname.new(path)
|
||||
path.extend(InstallRenamed)
|
||||
path.cp_path_sub(bottle_prefix, HOMEBREW_PREFIX)
|
||||
end
|
||||
end
|
||||
|
||||
# @private
|
||||
sig { void }
|
||||
def run_post_install
|
||||
@ -1164,13 +1181,6 @@ class Formula
|
||||
ENV.clear_sensitive_environment!
|
||||
ENV.activate_extensions!
|
||||
|
||||
etc_var_dirs = [bottle_prefix/"etc", bottle_prefix/"var"]
|
||||
Find.find(*etc_var_dirs.select(&:directory?)) do |path|
|
||||
path = Pathname.new(path)
|
||||
path.extend(InstallRenamed)
|
||||
path.cp_path_sub(bottle_prefix, HOMEBREW_PREFIX)
|
||||
end
|
||||
|
||||
with_logging("post_install") do
|
||||
post_install
|
||||
end
|
||||
@ -2174,6 +2184,7 @@ class Formula
|
||||
"disabled" => disabled?,
|
||||
"disable_date" => disable_date,
|
||||
"disable_reason" => disable_reason,
|
||||
"post_install_defined" => post_install_defined?,
|
||||
"service" => (service.serialize if service?),
|
||||
"tap_git_head" => tap_git_head,
|
||||
"ruby_source_path" => ruby_source_path,
|
||||
|
@ -796,7 +796,8 @@ on_request: installed_on_request?, options: options)
|
||||
puts "You can run it manually using:"
|
||||
puts " brew postinstall #{formula.full_name}"
|
||||
else
|
||||
post_install
|
||||
formula.install_etc_var
|
||||
post_install if formula.post_install_defined?
|
||||
end
|
||||
|
||||
keg.prepare_debug_symbols if debug_symbols?
|
||||
|
@ -268,6 +268,12 @@ module Formulary
|
||||
raise "Cannot build from source from abstract formula."
|
||||
end
|
||||
|
||||
@post_install_defined_boolean = json_formula["post_install_defined"]
|
||||
@post_install_defined_boolean = true if @post_install_defined_boolean.nil? # Backwards compatibility
|
||||
def post_install_defined?
|
||||
self.class.instance_variable_get(:@post_install_defined_boolean)
|
||||
end
|
||||
|
||||
if (service_hash = json_formula["service"].presence)
|
||||
service_hash = Homebrew::Service.deserialize(service_hash)
|
||||
service do
|
||||
|
@ -13,6 +13,7 @@ describe Formula do
|
||||
alias_matcher :have_changed_alias, :be_alias_changed
|
||||
|
||||
alias_matcher :have_option_defined, :be_option_defined
|
||||
alias_matcher :have_post_install_defined, :be_post_install_defined
|
||||
alias_matcher :have_test_defined, :be_test_defined
|
||||
alias_matcher :pour_bottle, :be_pour_bottle
|
||||
|
||||
@ -636,6 +637,23 @@ describe Formula do
|
||||
expect(f.desc).to eq("a formula")
|
||||
end
|
||||
|
||||
specify "#post_install_defined?" do
|
||||
f1 = formula do
|
||||
url "foo-1.0"
|
||||
|
||||
def post_install
|
||||
# do nothing
|
||||
end
|
||||
end
|
||||
|
||||
f2 = formula do
|
||||
url "foo-1.0"
|
||||
end
|
||||
|
||||
expect(f1).to have_post_install_defined
|
||||
expect(f2).not_to have_post_install_defined
|
||||
end
|
||||
|
||||
specify "test fixtures" do
|
||||
f1 = formula do
|
||||
url "foo-1.0"
|
||||
|
Loading…
x
Reference in New Issue
Block a user