From e1c242614ec034e622d2b78db5d63c475ce23f72 Mon Sep 17 00:00:00 2001 From: Sushain Cherivirala Date: Wed, 17 Jul 2024 13:49:57 -0700 Subject: [PATCH] Set $HOME to $TEST_TMPDIR in test targets --- ruby/private/binary/binary.cmd.tpl | 11 +++++++++++ ruby/private/binary/binary.sh.tpl | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/ruby/private/binary/binary.cmd.tpl b/ruby/private/binary/binary.cmd.tpl index 163a6541..f34e6d41 100644 --- a/ruby/private/binary/binary.cmd.tpl +++ b/ruby/private/binary/binary.cmd.tpl @@ -14,6 +14,17 @@ if "{java_bin}" neq "" ( for %%a in ("!java_bin!\..\..") do set JAVA_HOME=%%~fa ) +:: Bundler expects the %HOME% directory to be writable and produces misleading +:: warnings if it isn't. This isn't the case in every situation (e.g. remote +:: execution) and Bazel recommends using %TEST_TMPDIR% when it's available: +:: https://bazel.build/reference/test-encyclopedia#initial-conditions +:: +:: We set %HOME% prior to setting environment variables from the target itself +:: so that users can override this behavior if they desire. +if defined TEST_TMPDIR ( + set "HOME=%TEST_TMPDIR%" +) + :: Set environment variables. {env} diff --git a/ruby/private/binary/binary.sh.tpl b/ruby/private/binary/binary.sh.tpl index 1469bf0f..825edf29 100644 --- a/ruby/private/binary/binary.sh.tpl +++ b/ruby/private/binary/binary.sh.tpl @@ -26,6 +26,17 @@ if [ -n "{java_bin}" ]; then export JAVA_HOME=$(dirname $(dirname $(rlocation "{java_bin}"))) fi +# Bundler expects the $HOME directory to be writable and produces misleading +# warnings if it isn't. This isn't the case in every situation (e.g. remote +# execution) and Bazel recommends using $TEST_TMPDIR when it's available: +# https://bazel.build/reference/test-encyclopedia#initial-conditions +# +# We set $HOME prior to setting environment variables from the target itself so +# that users can override this behavior if they desire. +if [ -n "${TEST_TMPDIR:-}" ]; then + export HOME=$TEST_TMPDIR +fi + # Set environment variables. {env}