Skip to content
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: 4 additions & 2 deletions rules/actions_run/execute.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ the attribute "merge_tool".

def _impl(ctx):
# The list of arguments we pass to the script.
args = [ctx.outputs.out.path] + [f.path for f in ctx.files.chunks]
args = ctx.actions.args()
args.add(ctx.outputs.out)
args.add_all(ctx.files.chunks)

# Action to call the script.
ctx.actions.run(
inputs = ctx.files.chunks,
outputs = [ctx.outputs.out],
arguments = args,
arguments = [args],
progress_message = "Merging into %s" % ctx.outputs.out.short_path,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an opportunity to also use the %{...} placeholders.

executable = ctx.executable.merge_tool,
)
Expand Down
11 changes: 9 additions & 2 deletions rules/computed_dependencies/hash.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ def _impl(ctx):
processed = ctx.actions.declare_file(ctx.label.name + "_processed")

# Run the selected binary
args = ctx.actions.args()
args.add(ctx.file.src)
args.add(processed)
ctx.actions.run(
outputs = [processed],
inputs = [ctx.file.src],
progress_message = "Apply filter '%s'" % ctx.attr.filter,
arguments = [ctx.file.src.path, processed.path],
arguments = [args],
executable = ctx.executable._filter_bin,
)

Expand All @@ -60,11 +63,15 @@ with open(sys.argv[2], 'w') as f:
""",
)

args = ctx.actions.args()
args.add(hasher)
args.add(processed)
args.add(out)
ctx.actions.run(
outputs = [out],
inputs = [processed, hasher],
executable = "python3",
arguments = [hasher.path, processed.path, out.path],
arguments = [args],
mnemonic = "ComputeHash",
)

Expand Down
4 changes: 3 additions & 1 deletion rules/runfiles/tool.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ def _tool_user_impl(ctx):
# are automatically added to the action.
tool = ctx.executable.tool

args = ctx.actions.args()
args.add(my_out)
ctx.actions.run(
outputs = [my_out],
executable = tool,
arguments = [my_out.path],
arguments = [args],
)

return [DefaultInfo(files = depset([my_out]))]
Expand Down
5 changes: 4 additions & 1 deletion rules/shell_command/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ def _convert_to_uppercase_impl(ctx):
# Both the input and output files are specified by the BUILD file.
in_file = ctx.file.input
out_file = ctx.outputs.output
args = ctx.actions.args()
args.add(in_file)
args.add(out_file)
ctx.actions.run_shell(
outputs = [out_file],
inputs = [in_file],
arguments = [in_file.path, out_file.path],
arguments = [args],
command = "tr '[:lower:]' '[:upper:]' < \"$1\" > \"$2\"",
)
# No need to return anything telling Bazel to build `out_file` when
Expand Down
5 changes: 4 additions & 1 deletion rust-examples/09-oci-container/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,17 @@ def _build_sha265_tag_impl(ctx):
# Both the input and output files are specified by the BUILD file.
in_file = ctx.file.input
out_file = ctx.outputs.output
args = ctx.actions.args()
args.add(in_file)
args.add(out_file)

# No need to return anything telling Bazel to build `out_file` when
# building this target -- It's implied because the output is declared
# as an attribute rather than with `declare_file()`.
ctx.actions.run_shell(
inputs = [in_file],
outputs = [out_file],
arguments = [in_file.path, out_file.path],
arguments = [args],
command = "sed -n 's/.*sha256:\\([[:alnum:]]\\{7\\}\\).*/\\1/p' < \"$1\" > \"$2\"",
)

Expand Down
5 changes: 4 additions & 1 deletion rust-examples/09-oci-container/build/container.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ def _build_sha265_tag_impl(ctx):
# Both the input and output files are specified by the BUILD file.
in_file = ctx.file.input
out_file = ctx.outputs.output
args = ctx.actions.args()
args.add(in_file)
args.add(out_file)

# No need to return anything telling Bazel to build `out_file` when
# building this target -- It's implied because the output is declared
# as an attribute rather than with `declare_file()`.
ctx.actions.run_shell(
inputs = [in_file],
outputs = [out_file],
arguments = [in_file.path, out_file.path],
arguments = [args],
command = "sed -n 's/.*sha256:\\([[:alnum:]]\\{7\\}\\).*/\\1/p' < \"$1\" > \"$2\"",
)

Expand Down