@@ -1659,12 +1659,18 @@ def run_post_install
16591659 PATH : PATH . new ( ORIGINAL_PATHS ) ,
16601660 }
16611661
1662- with_env ( new_env ) do
1663- ENV . clear_sensitive_environment!
1664- ENV . activate_extensions!
1662+ Dir . mktmpdir ( "#{ name } -postinstall-" ) do |home |
1663+ postinstall_home = Pathname ( home )
1664+ new_env [ :HOME ] = postinstall_home . to_s
1665+ setup_home postinstall_home
16651666
1666- with_logging ( "post_install" ) do
1667- post_install
1667+ with_env ( new_env ) do
1668+ ENV . clear_sensitive_environment!
1669+ ENV . activate_extensions!
1670+
1671+ with_logging ( "post_install" ) do
1672+ post_install
1673+ end
16681674 end
16691675 end
16701676 ensure
@@ -3245,8 +3251,7 @@ def run_test(keep_tmp: false)
32453251 PATH : PATH . new ( ENV . fetch ( "PATH" ) , HOMEBREW_PREFIX /"bin" ) ,
32463252 HOMEBREW_TERM : ENV . fetch ( "TERM" , nil ) ,
32473253 HOMEBREW_PATH : nil ,
3248- } . merge ( common_stage_test_env )
3249- test_env [ :_JAVA_OPTIONS ] += " -Djava.io.tmpdir=#{ HOMEBREW_TEMP } "
3254+ }
32503255
32513256 ENV . clear_sensitive_environment!
32523257 Utils ::Git . set_name_email!
@@ -3255,6 +3260,8 @@ def run_test(keep_tmp: false)
32553260 staging . retain! if keep_tmp
32563261 @testpath = T . let ( staging . tmpdir , T . nilable ( Pathname ) )
32573262 test_env [ :HOME ] = @testpath
3263+ test_env . merge! ( common_stage_test_env ( T . must ( @testpath ) ) )
3264+ test_env [ :_JAVA_OPTIONS ] += " -Djava.io.tmpdir=#{ HOMEBREW_TEMP } "
32583265 setup_home T . must ( @testpath )
32593266 begin
32603267 with_logging ( "test" ) do
@@ -3706,15 +3713,15 @@ def exec_cmd(cmd, args, out, log_filename)
37063713 end
37073714
37083715 # Common environment variables used at both build and test time.
3709- sig { returns ( T ::Hash [ Symbol , String ] ) }
3710- def common_stage_test_env
3716+ sig { params ( home : Pathname ) . returns ( T ::Hash [ Symbol , String ] ) }
3717+ def common_stage_test_env ( home )
37113718 {
37123719 _JAVA_OPTIONS : "-Duser.home=#{ HOMEBREW_CACHE } /java_cache" ,
37133720 GOCACHE : "#{ HOMEBREW_CACHE } /go_cache" ,
37143721 GOPATH : "#{ HOMEBREW_CACHE } /go_mod_cache" ,
37153722 CARGO_HOME : "#{ HOMEBREW_CACHE } /cargo_cache" ,
37163723 PIP_CACHE_DIR : "#{ HOMEBREW_CACHE } /pip_cache" ,
3717- CURL_HOME : ENV . fetch ( "CURL_HOME" ) { Dir . home } ,
3724+ CURL_HOME : ENV . fetch ( "CURL_HOME" ) { home . to_s } ,
37183725 PYTHONDONTWRITEBYTECODE : "1" ,
37193726 }
37203727 end
@@ -3733,7 +3740,7 @@ def stage(interactive: false, debug_symbols: false, &_block)
37333740
37343741 unless interactive
37353742 stage_env [ :HOME ] = env_home
3736- stage_env . merge! ( common_stage_test_env )
3743+ stage_env . merge! ( common_stage_test_env ( env_home ) )
37373744 end
37383745
37393746 setup_home env_home
0 commit comments