-
Notifications
You must be signed in to change notification settings - Fork 4.4k
--action_env not forwarded through "tools" dependency #4008
Description
Description of the problem:
Variables set by --action_env are not forwarded through tools dependency of a rule. To generate test example, paste following lines into terminal:
mkdir test
cd test
touch WORKSPACE
touch tool.sh
chmod +x tool.sh
cat > BUILD << EOF
genrule(
name = "rule1",
srcs = [],
outs = ["out1.c"],
cmd = "bash -c 'echo RULE1:TESTVAR=\$\$TESTVAR'; exit 1",
)
sh_binary(
name = "tool",
srcs = ["tool.sh"],
# srcs = [":rule1"],
data = [":rule1"],
)
genrule(
name = "rule2",
srcs = [],
outs = ["out2.c"],
cmd = "",
tools = [":tool"],
)
genrule(
name = "rule3",
srcs = [],
outs = ["out3.c"],
cmd = "",
tools = [":rule1"],
)
genrule(
name = "rule4",
srcs = [":rule1"],
outs = ["out4.c"],
cmd = "",
)
cc_binary(
name = "main",
srcs = [
# ":rule1",
# ":rule2",
# ":rule3",
# ":rule4",
],
data = [
# ":rule1",
":rule2",
# ":rule3",
# ":rule4",
# ":tool",
],
)
EOF
bazel build :main --action_env TESTVAR=hellooutputs
RULE1:TESTVAR=
however depending on what is uncommented, i.e., ":rule1",, ":rule2",, ":rule3",, ":rule4",, ":tool", at the end of BUILD, bazel may output also
RULE1:TESTVAR=hello
rule1 gives RULE1:TESTVAR=hello - rule1 is directly referenced
rule2 and rule3 gives RULE1:TESTVAR= - rule1 is referenced via tools option
rule4 and tool again gives RULE1:TESTVAR=hello - rule1 is referenced via middleman
If the rule1 is referenced from the "tool" and from another rule as a dependency, it may be randomly executed with different environment set for each run. Is this the expected behaviour?
A consistent behaviour is obtained when exporting the environment variable into bazel environment, i.e.,
export TESTVAR="hello world!"
bazel shutdown
bazel build :main
NOTE: in case there is a linking error, execute the last command (bazel build ...) once more.
NOTE2: if more than one rule dependency is uncommented, it may randomly output both results, execute multiple times to verify, e.g.,
for i in 1 2 3 4 5; do bazel build :main --action_env TESTVAR=hello 2> /dev/null | grep TESTVAR ; doneEnvironment info
-
Operating System: macOS, Linux
-
Bazel version: release 0.7.0, release 0.5.4