Skip to content

Commit

Permalink
chore: improve error when run_binary has no outputs
Browse files Browse the repository at this point in the history
Otherwise users get

```
Traceback (most recent call last):
	File "/private/var/tmp/_bazel_long.ho/a2216e06a77a9425f6dcd5fd195f64d5/external/aspect_bazel_lib/lib/private/run_binary.bzl", line 46, column 20, in _impl
		ctx.actions.run(
Error in run: param 'outputs' may not be empty
```
  • Loading branch information
alexeagle committed Jun 27, 2022
1 parent 5307f58 commit 9107860
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/private/run_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ def _impl(ctx):
if output.is_directory and out_dir.path.startswith(output.path + "/"):
fail("output directory {} is nested within output directory {}; outputs cannot be nested within each other!".format(out_dir.path, output.path))
outputs.append(out_dir)
if len(outputs) < 1:
fail("""\
ERROR: target {target} is not configured to produce any outputs.
Bazel only executes actions when their outputs are required, so it's never correct to create an action with no outputs.
Possible fixes:
- Predict what outputs are created, and list them in the outs and out_dirs attributes.
- If {rule_kind} is a binary, and you meant to run it for its side-effects,
then call it directly with `bazel run` and don't wrap it in a run_binary rule.
""".format(
target = str(ctx.label),
rule_kind = str(ctx.attr.tool.label),
))

# `expand_locations(...).split(" ")` is a work-around https://github.com/bazelbuild/bazel/issues/10309
# _expand_locations returns an array of args to support $(execpaths) expansions.
Expand Down

0 comments on commit 9107860

Please sign in to comment.