Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tool executables (from FilesToRunProvider) to action inputs.
Browse files Browse the repository at this point in the history
jmillikin committed Oct 26, 2019
1 parent 54db08b commit e986297
Showing 3 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -197,6 +197,7 @@ private CommandHelper(
Artifact executableArtifact = tool.getExecutable();
// If the label has an executable artifact add that to the multimaps.
if (executableArtifact != null) {
resolvedToolsBuilder.add(executableArtifact);
mapGet(tempLabelMap, label).add(executableArtifact);
// Also send the runfiles when running remotely.
toolsRunfilesBuilder.add(tool.getRunfilesSupplier());
Original file line number Diff line number Diff line change
@@ -799,6 +799,7 @@ public Builder addTool(Artifact tool) {
* source code).
*/
public Builder addTool(FilesToRunProvider tool) {
addTool(tool.getExecutable());
addTransitiveTools(tool.getFilesToRun());
addRunfilesSupplier(tool.getRunfilesSupplier());
return this;
55 changes: 55 additions & 0 deletions src/test/shell/bazel/bazel_rules_test.sh
Original file line number Diff line number Diff line change
@@ -524,4 +524,59 @@ EOF
expect_log "Public or private visibility labels (e.g. //visibility:public or //visibility:private) cannot be used in combination with other labels"
}

function test_executable_without_default_files() {
mkdir pkg
cat >pkg/BUILD <<'EOF'
load(":rules.bzl", "bin_rule", "out_rule")
bin_rule(name = "hello_bin")
out_rule(name = "hello_out")
genrule(
name = "hello_gen",
tools = [":hello_bin"],
outs = ["hello_gen.txt"],
cmd = "$(location :hello_bin) $@",
)
EOF

cat >pkg/rules.bzl <<'EOF'
def _bin_rule(ctx):
out_sh = ctx.actions.declare_file(ctx.attr.name + ".sh")
ctx.actions.write(
output = out_sh,
content = "#!/bin/sh\necho 'hello world' > $@",
is_executable = True,
)
return DefaultInfo(
files = depset(direct = []),
executable = out_sh,
)
def _out_rule(ctx):
out = ctx.actions.declare_file(ctx.attr.name + ".txt")
ctx.actions.run(
executable = ctx.executable._hello_bin,
outputs = [out],
arguments = [out.path],
mnemonic = "HelloOut",
)
return DefaultInfo(
files = depset(direct = [out]),
)
bin_rule = rule(_bin_rule, executable = True)
out_rule = rule(_out_rule, attrs = {
"_hello_bin": attr.label(
default = ":hello_bin",
executable = True,
cfg = "host",
),
})
EOF

bazel build //pkg:hello_out //pkg:hello_gen >$TEST_log 2>&1 || fail "Should build"
assert_contains "hello world" bazel-bin/pkg/hello_out.txt
assert_contains "hello world" bazel-bin/pkg/hello_gen.txt
}

run_suite "rules test"

0 comments on commit e986297

Please sign in to comment.