aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2016-11-07 12:30:13 +0000
committerGravatar Klaus Aehlig <aehlig@google.com>2016-11-07 14:01:50 +0000
commitefdfff2aecdf4584b9ddda40ba1d8f106167b1e0 (patch)
tree1535c439d84fdb567ead552c7f6d25302d4347ef /src/test
parentb043fafb957ae8038088e427ff27a5c9f951c979 (diff)
For SpawnActions, also honor the dynamic environment
For SpawnActions, depending on the value of use_default_shell_env, the specified environment is taken. The shell environment, however, consists of two parts: a static mapping of variables to values, and a set of variables where the value is to be taken from the client environment. Make sure, both parts are set correctly. Fixes #2035. -- Change-Id: I32253e9bf651b18ca25107edc5fc839813905726 Reviewed-on: https://bazel-review.googlesource.com/#/c/7211 MOS_MIGRATED_REVID=138376914
Diffstat (limited to 'src/test')
-rwxr-xr-xsrc/test/shell/integration/action_env_test.sh38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/test/shell/integration/action_env_test.sh b/src/test/shell/integration/action_env_test.sh
index 52d0e2b541..2564a5a4cb 100755
--- a/src/test/shell/integration/action_env_test.sh
+++ b/src/test/shell/integration/action_env_test.sh
@@ -34,6 +34,26 @@ genrule(
outs = ["env.txt"],
cmd = "env | sort > \"\$@\""
)
+
+load("//pkg:build.bzl", "environ")
+
+environ(name = "no_default_env", env = 0)
+environ(name = "with_default_env", env = 1)
+EOF
+ cat > pkg/build.bzl <<EOF
+def _impl(ctx):
+ output = ctx.outputs.out
+ ctx.action(
+ inputs=[],
+ outputs=[output],
+ use_default_shell_env = ctx.attr.env,
+ command="env > %s" % output.path)
+
+environ = rule(
+ implementation=_impl,
+ attrs={"env": attr.bool(default=True)},
+ outputs={"out": "%{name}.env"},
+)
EOF
}
@@ -146,4 +166,22 @@ function test_env_freezing() {
rm -f .${PRODUCT_NAME}rc
}
+function test_use_default_shell_env {
+ bazel build --action_env=FOO=bar //pkg/...
+ echo
+ cat bazel-bin/pkg/with_default_env.env
+ echo
+ grep -q FOO=bar bazel-bin/pkg/with_default_env.env \
+ || fail "static action environment not honored"
+ (grep -q FOO=bar bazel-bin/pkg/no_default_env.env \
+ && fail "static action_env used, even though requested not to") || true
+
+ export BAR=baz
+ bazel build --action_env=BAR //pkg/...
+ grep -q BAR=baz bazel-bin/pkg/with_default_env.env \
+ || fail "dynamic action environment not honored"
+ (grep -q BAR bazel-bin/pkg/no_default_env.env \
+ && fail "dynamic action_env used, even though requested not to") || true
+}
+
run_suite "Tests for bazel's handling of environment variables in actions"