-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Handle RunEnvironmentInfo (#68)
Executable rules can include a [RunEnvironmentInfo](https://bazel.build/rules/lib/providers/RunEnvironmentInfo) provider to set envs. These envs are detected and included with explicitly defined envs on the target when defining the multirun commands. Because bazel allows for this provider, it is nice for rules_multirun to handle it. I ran into a situation where a 3rd party ruleset uses this as part of a run action and there is no way to provide the correct value by wrapping in a `command` as the env is internal to the ruleset.
- Loading branch information
1 parent
512e748
commit 8e87b9a
Showing
4 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"Simple executable rule to exercise RunEnvironmentInfo handling" | ||
|
||
def _custom_executable_impl(ctx): | ||
executable = ctx.actions.declare_file(ctx.label.name + ".bash") | ||
|
||
# Create the runfiles object | ||
runfiles = ctx.attr._bash_runfiles[DefaultInfo].default_runfiles | ||
|
||
# Write the script content to the executable | ||
ctx.actions.write( | ||
output = executable, | ||
content = """#!/bin/bash | ||
set -euo pipefail | ||
if [[ "$FOO_ENV" != "foo" ]]; then | ||
echo "error: expected FOO_ENV to be 'foo', got '$FOO_ENV'" | ||
exit 1 | ||
fi | ||
""", | ||
is_executable = True, | ||
) | ||
|
||
return [ | ||
DefaultInfo( | ||
files = depset([executable]), | ||
runfiles = runfiles, | ||
executable = executable, | ||
), | ||
RunEnvironmentInfo( | ||
environment = { | ||
"FOO_ENV": "foo", | ||
}, | ||
), | ||
] | ||
|
||
custom_executable = rule( | ||
implementation = _custom_executable_impl, | ||
attrs = { | ||
"_bash_runfiles": attr.label( | ||
default = "@bazel_tools//tools/bash/runfiles", | ||
), | ||
}, | ||
executable = True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters