Pass keep_tmp? and interactive? instead of using global args.

This commit is contained in:
Markus Reiter 2020-07-23 02:58:12 +02:00
parent a6bc9e155a
commit 6b0b25cd00
4 changed files with 13 additions and 14 deletions

View File

@ -121,12 +121,11 @@ class Build
formula.update_head_version formula.update_head_version
formula.brew(fetch: false) do |_formula, staging| formula.brew(fetch: false, keep_tmp: args.keep_tmp?, interactive: args.interactive?) do |_formula, _staging|
# For head builds, HOMEBREW_FORMULA_PREFIX should include the commit, # For head builds, HOMEBREW_FORMULA_PREFIX should include the commit,
# which is not known until after the formula has been staged. # which is not known until after the formula has been staged.
ENV["HOMEBREW_FORMULA_PREFIX"] = formula.prefix ENV["HOMEBREW_FORMULA_PREFIX"] = formula.prefix
staging.retain! if args.keep_tmp?
formula.patch formula.patch
if args.git? if args.git?

View File

@ -123,6 +123,6 @@ module Homebrew
end end
end end
ensure ensure
FileUtils.rm_rf "update-test" unless Homebrew.args.keep_tmp? FileUtils.rm_rf "update-test" unless args.keep_tmp?
end end
end end

View File

@ -1163,11 +1163,11 @@ class Formula
# yields |self,staging| with current working directory set to the uncompressed tarball # yields |self,staging| with current working directory set to the uncompressed tarball
# where staging is a Mktemp staging context # where staging is a Mktemp staging context
# @private # @private
def brew(fetch: true) def brew(fetch: true, keep_tmp: false, interactive: false)
@prefix_returns_versioned_prefix = true @prefix_returns_versioned_prefix = true
active_spec.fetch if fetch active_spec.fetch if fetch
stage do |staging| stage(interactive: interactive) do |staging|
staging.retain! if Homebrew.args.keep_tmp? staging.retain! if keep_tmp
prepare_patches prepare_patches
fetch_patches if fetch fetch_patches if fetch
@ -1175,7 +1175,7 @@ class Formula
begin begin
yield self, staging yield self, staging
rescue rescue
staging.retain! if Homebrew.args.interactive? || Homebrew.args.debug? staging.retain! if interactive || Homebrew.args.debug?
raise raise
ensure ensure
cp Dir["config.log", "CMakeCache.txt"], logs cp Dir["config.log", "CMakeCache.txt"], logs
@ -1792,7 +1792,7 @@ class Formula
end end
# @private # @private
def run_test def run_test(keep_tmp: false)
@prefix_returns_versioned_prefix = true @prefix_returns_versioned_prefix = true
test_env = { test_env = {
@ -1808,7 +1808,7 @@ class Formula
Utils.set_git_name_email! Utils.set_git_name_email!
mktemp("#{name}-test") do |staging| mktemp("#{name}-test") do |staging|
staging.retain! if Homebrew.args.keep_tmp? staging.retain! if keep_tmp
@testpath = staging.tmpdir @testpath = staging.tmpdir
test_env[:HOME] = @testpath test_env[:HOME] = @testpath
setup_home @testpath setup_home @testpath
@ -2134,7 +2134,7 @@ class Formula
} }
end end
def stage def stage(interactive: false)
active_spec.stage do |staging| active_spec.stage do |staging|
@source_modified_time = active_spec.source_modified_time @source_modified_time = active_spec.source_modified_time
@buildpath = Pathname.pwd @buildpath = Pathname.pwd
@ -2145,7 +2145,7 @@ class Formula
HOMEBREW_PATH: nil, HOMEBREW_PATH: nil,
} }
unless Homebrew.args.interactive? unless interactive
stage_env[:HOME] = env_home stage_env[:HOME] = env_home
stage_env.merge!(common_stage_test_env) stage_env.merge!(common_stage_test_env)
end end

View File

@ -16,13 +16,13 @@ require "dev-cmd/test"
TEST_TIMEOUT_SECONDS = 5 * 60 TEST_TIMEOUT_SECONDS = 5 * 60
begin begin
Homebrew.test_args.parse args = Homebrew.test_args.parse
error_pipe = UNIXSocket.open(ENV["HOMEBREW_ERROR_PIPE"], &:recv_io) error_pipe = UNIXSocket.open(ENV["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 = Homebrew.args.resolved_formulae.first formula = args.resolved_formulae.first
formula.extend(Homebrew::Assertions) formula.extend(Homebrew::Assertions)
formula.extend(Homebrew::FreePort) formula.extend(Homebrew::FreePort)
formula.extend(Debrew::Formula) if Homebrew.args.debug? formula.extend(Debrew::Formula) if Homebrew.args.debug?
@ -32,7 +32,7 @@ begin
# tests can also return false to indicate failure # tests can also return false to indicate failure
Timeout.timeout TEST_TIMEOUT_SECONDS do Timeout.timeout TEST_TIMEOUT_SECONDS do
raise "test returned false" if formula.run_test == false raise "test returned false" if formula.run_test(keep_tmp: args.keep_tmp?) == false
end end
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
error_pipe.puts e.to_json error_pipe.puts e.to_json