diff options
author | 2016-08-23 12:25:27 +0000 | |
---|---|---|
committer | 2016-08-23 22:57:20 +0000 | |
commit | 3d4248c6da9630e315f58a18e9d69c2608cd9de5 (patch) | |
tree | 48c5e85c0e208d85d1c2a668065aebc34edaf5c2 /src/test/shell | |
parent | 7e1d576614fdf9f3468ec87c444590ae295b03e3 (diff) |
Add option --action_env and make BuildConfiguration declare environment dependencies
This option will allow to specify which environment variables are to
be provided to the actions. Environment variables for the options will
become opt-in, i.e., only environment variables explicitly specified
will be provided to the actions. However, the full range of rc-files
will be able to nominate options to be added; to avoid dependency on
the invocation environment, absolute values can be provided as well.
As the configuration now no longer completely determines the action
environment extend it to also declare which environment variables are
to be taken from the client environment. This will be implemented in
follow-up patches.
The transition plan is that the newly added option takes precedence
over the environment variables added by the fragments. This is conservative,
as the new option is not yet used anywhere. Then the effect of the
fragments will be provided by rc-files, and finally, the setupShellEnvironment
Method will be removed from the fragments all together.
Also add some simple tests for static (i.e., independent of the client
environment) setting of action environment variables.
This is the first step towards implementing the design on [Specifying
environment variables for actions](http://bazel.io/designs/2016/06/21/environment.html).
--
Change-Id: I0ad36913b7d357787b4d69e341926806b3fc61bf
Reviewed-on: https://bazel-review.googlesource.com/#/c/4241
MOS_MIGRATED_REVID=131044391
Diffstat (limited to 'src/test/shell')
-rw-r--r-- | src/test/shell/integration/BUILD | 7 | ||||
-rwxr-xr-x | src/test/shell/integration/action_env_test.sh | 65 |
2 files changed, 72 insertions, 0 deletions
diff --git a/src/test/shell/integration/BUILD b/src/test/shell/integration/BUILD index 35958d4ce7..613ed750fc 100644 --- a/src/test/shell/integration/BUILD +++ b/src/test/shell/integration/BUILD @@ -52,6 +52,13 @@ sh_test( data = [":test-deps"], ) +sh_test( + name = "action_env_test", + size = "medium", + srcs = ["action_env_test.sh"], + data = [":test-deps"], +) + test_suite( name = "all_tests", visibility = ["//visibility:public"], diff --git a/src/test/shell/integration/action_env_test.sh b/src/test/shell/integration/action_env_test.sh new file mode 100755 index 0000000000..2074c83d27 --- /dev/null +++ b/src/test/shell/integration/action_env_test.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# +# Copyright 2016 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# An end-to-end test that Bazel's provides the correct environment variables +# to actions. + +# Load test environment +source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ + || { echo "testenv.sh not found!" >&2; exit 1; } + +create_and_cd_client +put_bazel_on_path +write_default_bazelrc + + +#### SETUP ############################################################# + +set -e + +function set_up() { + mkdir -p pkg + cat > pkg/BUILD <<EOF +genrule( + name = "showenv", + outs = ["env.txt"], + cmd = "env | sort > \"\$@\"" +) +EOF +} + +#### TESTS ############################################################# + +function test_simple() { + export FOO=baz + bazel build --action_env=FOO=bar pkg:showenv \ + || fail "bazel build showenv failed" + cat `bazel info bazel-genfiles`/pkg/env.txt > $TEST_log + expect_log "FOO=bar" +} + +function test_simple_latest_wins() { + export FOO=environmentfoo + export BAR=environmentbar + bazel build --action_env=FOO=foo \ + --action_env=BAR=willbeoverridden --action_env=BAR=bar pkg:showenv \ + || fail "bazel build showenv failed" + cat `bazel info bazel-genfiles`/pkg/env.txt > $TEST_log + expect_log "FOO=foo" + expect_log "BAR=bar" +} + +run_suite "Tests for bazel's handling of environment variables in actions" |