diff --git a/Library/Homebrew/cmd/postinstall.rb b/Library/Homebrew/cmd/postinstall.rb index 02fd8a5f64..77320c2042 100644 --- a/Library/Homebrew/cmd/postinstall.rb +++ b/Library/Homebrew/cmd/postinstall.rb @@ -2,6 +2,7 @@ #: Rerun the post-install steps for . require "sandbox" +require "formula_installer" module Homebrew module_function @@ -9,43 +10,8 @@ module Homebrew def postinstall ARGV.resolved_formulae.each do |f| ohai "Postinstalling #{f}" - run_post_install(f) - end - end - - def run_post_install(formula) - args = %W[ - nice #{RUBY_PATH} - -W0 - -I #{HOMEBREW_LOAD_PATH} - -- - #{HOMEBREW_LIBRARY_PATH}/postinstall.rb - #{formula.path} - ].concat(ARGV.options_only) - - if formula.head? - args << "--HEAD" - elsif formula.devel? - args << "--devel" - end - - Utils.safe_fork do - if Sandbox.formula?(formula) - sandbox = Sandbox.new - formula.logs.mkpath - sandbox.record_log(formula.logs/"postinstall.sandbox.log") - sandbox.allow_write_temp_and_cache - sandbox.allow_write_log(formula) - sandbox.allow_write_xcode - sandbox.deny_write_homebrew_repository - sandbox.allow_write_cellar(formula) - Keg::TOP_LEVEL_DIRECTORIES.each do |dir| - sandbox.allow_write_path "#{HOMEBREW_PREFIX}/#{dir}" - end - sandbox.exec(*args) - else - exec(*args) - end + fi = FormulaInstaller.new(f) + fi.post_install end end end diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 7ed473ee89..c4ac366118 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -7,7 +7,6 @@ require "caveats" require "cleaner" require "formula_cellar_checks" require "install_renamed" -require "cmd/postinstall" require "debrew" require "sandbox" require "emoji" @@ -837,7 +836,39 @@ class FormulaInstaller end def post_install - Homebrew.run_post_install(formula) + args = %W[ + nice #{RUBY_PATH} + -W0 + -I #{HOMEBREW_LOAD_PATH} + -- + #{HOMEBREW_LIBRARY_PATH}/postinstall.rb + #{formula.path} + ].concat(ARGV.options_only) + + if formula.head? + args << "--HEAD" + elsif formula.devel? + args << "--devel" + end + + Utils.safe_fork do + if Sandbox.formula?(formula) + sandbox = Sandbox.new + formula.logs.mkpath + sandbox.record_log(formula.logs/"postinstall.sandbox.log") + sandbox.allow_write_temp_and_cache + sandbox.allow_write_log(formula) + sandbox.allow_write_xcode + sandbox.deny_write_homebrew_repository + sandbox.allow_write_cellar(formula) + Keg::TOP_LEVEL_DIRECTORIES.each do |dir| + sandbox.allow_write_path "#{HOMEBREW_PREFIX}/#{dir}" + end + sandbox.exec(*args) + else + exec(*args) + end + end rescue Exception => e # rubocop:disable Lint/RescueException opoo "The post-install step did not complete successfully" puts "You can try again using `brew postinstall #{formula.full_name}`"