From f2b4453af73d05845bf97e5a4d2e38b2c4357bfd Mon Sep 17 00:00:00 2001 From: Siddhartha Bagaria Date: Fri, 6 Mar 2020 00:36:49 -0800 Subject: [PATCH] rules_r: fix exporting status vars as env vars in r_binary This was broken by 8a4ab37560a197e9401fb561bdf9aa0c9cd61269 in which we stopped exporting stable status var by default. --- R/scripts/binary.sh.tpl | 10 ++++++++-- tests/stamping/nostamp_test.sh | 6 ++++++ tests/stamping/stamp_test.sh | 6 ++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/R/scripts/binary.sh.tpl b/R/scripts/binary.sh.tpl index 722749f..b1640cf 100644 --- a/R/scripts/binary.sh.tpl +++ b/R/scripts/binary.sh.tpl @@ -21,9 +21,15 @@ fatal() { } # Make bazel status variables available as environment variables, if available. -if [[ -e ./stable-status.txt ]]; then - e="$(cat ./{stable,volatile}-status.txt | sed -e 's/\([^[:space:]]*\) \(.*\)/export \1=\"\2\"/')" +status_to_env() { + local status_file="$1" + e="$(cat "${status_file}" | sed -e 's/\([^[:space:]]*\) \(.*\)/export \1=\"\2\"/')" eval "${e}" +} + +status_to_env "./volatile-status.txt" +if [[ -e ./stable-status.txt ]]; then + status_to_env "./stable-status.txt" fi # Export environment variables, if any. diff --git a/tests/stamping/nostamp_test.sh b/tests/stamping/nostamp_test.sh index 6344d27..fb41640 100755 --- a/tests/stamping/nostamp_test.sh +++ b/tests/stamping/nostamp_test.sh @@ -23,7 +23,13 @@ fail() { if ! grep "^VAR" "volatile-status.txt"; then fail "volatile status file expected" fi +if ! [[ "${VAR:-}" ]]; then + fail "volatile status var expected as env var" +fi if [[ -e stable-info.txt ]]; then fail "stable status file not expected" fi +if [[ "${STABLE_VAR:-}" ]]; then + fail "stable status var not expected as env var" +fi diff --git a/tests/stamping/stamp_test.sh b/tests/stamping/stamp_test.sh index 7091588..5cc10e1 100755 --- a/tests/stamping/stamp_test.sh +++ b/tests/stamping/stamp_test.sh @@ -23,7 +23,13 @@ fail() { if ! grep "^VAR" "volatile-status.txt"; then fail "volatile status file expected" fi +if ! [[ "${VAR:-}" ]]; then + fail "volatile status var expected as env var" +fi if ! grep "^STABLE_VAR" "stable-status.txt"; then fail "stable status file expected and not empty" fi +if ! [[ "${STABLE_VAR:-}" ]]; then + fail "stable status var expected as env var" +fi