`native_binary`: use target name as filename by default
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.
This commit is contained in:
parent
207acb3850
commit
0f69967615
|
@ -30,7 +30,7 @@ in genrule.tools for example. You can also augment the binary with runfiles.
|
|||
| :------------- | :------------- | :------------- | :------------- | :------------- |
|
||||
| <a id="native_binary-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
|
||||
| <a id="native_binary-data"></a>data | data dependencies. See https://docs.bazel.build/versions/main/be/common-definitions.html#typical.data | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
|
||||
| <a id="native_binary-out"></a>out | An output name for the copy of the binary | String | required | |
|
||||
| <a id="native_binary-out"></a>out | An output name for the copy of the binary (defaults to target name) | String | optional | "" |
|
||||
| <a id="native_binary-src"></a>src | path of the pre-built executable | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
|
||||
|
||||
|
||||
|
@ -56,7 +56,7 @@ the binary with runfiles.
|
|||
| :------------- | :------------- | :------------- | :------------- | :------------- |
|
||||
| <a id="native_test-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
|
||||
| <a id="native_test-data"></a>data | data dependencies. See https://docs.bazel.build/versions/main/be/common-definitions.html#typical.data | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
|
||||
| <a id="native_test-out"></a>out | An output name for the copy of the binary | String | required | |
|
||||
| <a id="native_test-out"></a>out | An output name for the copy of the binary (defaults to target name) | String | optional | "" |
|
||||
| <a id="native_test-src"></a>src | path of the pre-built executable | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
out = ctx.actions.declare_file(out_file)
|
||||
|
||||
ctx.actions.symlink(
|
||||
target_file = ctx.executable.src,
|
||||
output = out,
|
||||
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue