Skip to content

Commit

Permalink
native_binary: use target name as filename by default
Browse files Browse the repository at this point in the history
This changes the `out` attribute in native binary to default to the target name
if unspecified, which is convenient because it can be omitted when renaming targets
that are linux executables and frequently share the target name.
  • Loading branch information
psigen committed Jun 10, 2022
1 parent 207acb3 commit 9227003
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions rules/native_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ don't depend on Bash and work with --shell_executable="".
"""

def _impl_rule(ctx):
out = ctx.actions.declare_file(ctx.attr.out)
if ctx.attr.out:
out_file = ctx.attr.out
else:
out_file = ctx.name
ctx.actions.declare_file(out_file)

ctx.actions.symlink(
target_file = ctx.executable.src,
output = out,
Expand Down Expand Up @@ -64,7 +69,7 @@ _ATTRS = {
" https://docs.bazel.build/versions/main/be/common-definitions.html#typical.data",
),
# "out" is attr.string instead of attr.output, so that it is select()'able.
"out": attr.string(mandatory = True, doc = "An output name for the copy of the binary"),
"out": attr.string(doc = "An output name for the copy of the binary (defaults to target name)"),
}

native_binary = rule(
Expand Down

0 comments on commit 9227003

Please sign in to comment.