Skip to content

Commit

Permalink
Merge pull request #16300 from Bo98/lazy-debrew
Browse files Browse the repository at this point in the history
Lazy load Debrew (fixes setupterm error on some environments)
  • Loading branch information
Bo98 authored Dec 6, 2023
2 parents 4af96ec + a92a36d commit ab6a7ed
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions Library/Homebrew/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
require "build_options"
require "keg"
require "extend/ENV"
require "debrew"
require "fcntl"
require "socket"
require "cmd/install"
Expand Down Expand Up @@ -126,7 +125,10 @@ def install
}

with_env(new_env) do
formula.extend(Debrew::Formula) if args.debug?
if args.debug?
require "debrew"
formula.extend(Debrew::Formula)
end

formula.update_head_version

Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/debrew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# frozen_string_literal: true

require "mutex_m"
require "debrew/irb"
require "ignorable"

# Helper module for debugging formulae.
Expand Down Expand Up @@ -117,7 +116,10 @@ def self.debug(exception)
set_trace_func proc { |event, _, _, id, binding, klass|
if klass == Object && id == :raise && event == "return"
set_trace_func(nil)
mu_synchronize { IRB.start_within(binding) }
mu_synchronize do
require "debrew/irb"
IRB.start_within(binding)
end
end
}

Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/postinstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
old_trap = trap("INT") { exit! 130 }

require_relative "global"
require "debrew"
require "fcntl"
require "socket"
require "cli/parser"
Expand All @@ -20,7 +19,10 @@
trap("INT", old_trap)

formula = args.named.to_resolved_formulae.first
formula.extend(Debrew::Formula) if args.debug?
if args.debug?
require "debrew"
formula.extend(Debrew::Formula)
end
formula.run_post_install
rescue Exception => e # rubocop:disable Lint/RescueException
error_pipe.puts e.to_json
Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
require_relative "global"
require "extend/ENV"
require "timeout"
require "debrew"
require "formula_assertions"
require "formula_free_port"
require "fcntl"
Expand All @@ -35,7 +34,10 @@
formula = T.must(args.named.to_resolved_formulae.first)
formula.extend(Homebrew::Assertions)
formula.extend(Homebrew::FreePort)
formula.extend(Debrew::Formula) if args.debug?
if args.debug?
require "debrew"
formula.extend(Debrew::Formula)
end

ENV.extend(Stdenv)
ENV.setup_build_environment(formula: formula, testing_formula: true)
Expand Down

0 comments on commit ab6a7ed

Please sign in to comment.