Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mnemonic, progress_message && execution_requirements to run_binary #161

Merged
merged 1 commit into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/run_binary.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 32 additions & 1 deletion lib/private/run_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def _impl(ctx):
tools = tool_inputs,
executable = ctx.executable.tool,
arguments = [args],
mnemonic = "RunBinary",
mnemonic = ctx.attr.mnemonic if ctx.attr.mnemonic else None,
progress_message = ctx.attr.progress_message if ctx.attr.progress_message else None,
execution_requirements = ctx.attr.execution_requirements if ctx.attr.execution_requirements else None,
use_default_shell_env = False,
env = dicts.add(ctx.configuration.default_shell_env, envs),
input_manifests = tool_input_mfs,
Expand All @@ -75,6 +77,9 @@ _run_binary = rule(
"out_dirs": attr.string_list(),
"outs": attr.output_list(),
"args": attr.string_list(),
"mnemonic": attr.string(),
"progress_message": attr.string(),
"execution_requirements": attr.string_dict(),
},
)

Expand All @@ -86,6 +91,9 @@ def run_binary(
env = {},
outs = [],
out_dirs = [],
mnemonic = "RunBinary",
progress_message = None,
execution_requirements = None,
# TODO: remove output_dir in 2.x release
output_dir = False,
**kwargs):
Expand Down Expand Up @@ -128,6 +136,26 @@ def run_binary(

Output directories cannot be nested within other output directories in out_dirs.

mnemonic: A one-word description of the action, for example, CppCompile or GoLink.

progress_message: Progress message to show to the user during the build, for example,
"Compiling foo.cc to create foo.o". The message may contain %{label}, %{input}, or
%{output} patterns, which are substituted with label string, first input, or output's
path, respectively. Prefer to use patterns instead of static strings, because the former
are more efficient.

execution_requirements: Information for scheduling the action.
gregmagolan marked this conversation as resolved.
Show resolved Hide resolved

For example,

```
execution_requirements = {
"no-cache": "1",
},
```

See https://docs.bazel.build/versions/main/be/common-definitions.html#common.tags for useful keys.

output_dir: If set to True then an output directory named the same as the target name
is added to out_dirs.

Expand All @@ -143,5 +171,8 @@ def run_binary(
env = env,
outs = outs,
out_dirs = out_dirs + ([name] if output_dir else []),
mnemonic = mnemonic,
progress_message = progress_message,
execution_requirements = execution_requirements,
**kwargs
)
6 changes: 6 additions & 0 deletions lib/tests/run_binary/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ write_file(
content = [
"#!/usr/bin/env bash",
"set -o errexit -o nounset -o pipefail",
"sleep 3",
"outdir=$1",
"echo 'foo' > \"$outdir/foo\"",
"echo 'bar' > \"$outdir/bar\"",
Expand All @@ -27,7 +28,12 @@ sh_binary(
run_binary(
name = "dir_a",
args = ["$(@D)"],
execution_requirements = {
"no-cache": "1",
},
mnemonic = "SomeAction",
out_dirs = ["dir_a"],
progress_message = "doing some work to make %{output}",
tool = ":make_dir_a",
)

Expand Down