diff --git a/command.bzl b/command.bzl index f1aa90c..9f4aabc 100644 --- a/command.bzl +++ b/command.bzl @@ -53,6 +53,11 @@ def _command_impl(ctx): expansion_targets = ctx.attr.data + env = {} + if RunEnvironmentInfo in command: + env.update(command[RunEnvironmentInfo].environment) + env.update(ctx.attr.environment) + str_env = [ "export %s=%s" % ( k, @@ -63,7 +68,7 @@ def _command_impl(ctx): targets = expansion_targets, ), ) - for k, v in ctx.attr.environment.items() + for k, v in env.items() ] str_args = [ "%s" % _expand_and_quote(ctx = ctx, attr = "arguments", string = v, targets = expansion_targets) diff --git a/tests/BUILD b/tests/BUILD index 70557b9..2dccde1 100644 --- a/tests/BUILD +++ b/tests/BUILD @@ -202,6 +202,11 @@ custom_executable( name = "validate_custom_executable_rule_env", ) +command( + name = "command_custom_executable_rule_env", + command = ":validate_custom_executable_rule_env", +) + multirun( name = "multirun_custom_executable_rule_env", commands = [":validate_custom_executable_rule_env"], @@ -265,6 +270,7 @@ sh_test( name = "test", srcs = ["test.sh"], data = [ + ":command_custom_executable_rule_env", ":default_pwd_cmd", ":echo_and_fail_cmd", ":hello", diff --git a/tests/test.sh b/tests/test.sh index 8f52150..04edad1 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -41,6 +41,9 @@ $script script=$(rlocation rules_multirun/tests/multirun_custom_executable_rule_env.bash) $script +script=$(rlocation rules_multirun/tests/command_custom_executable_rule_env.bash) +$script + script="$(rlocation rules_multirun/tests/multirun_parallel.bash)" parallel_output="$($script)" if [[ -n "$parallel_output" ]]; then