diff --git a/e2e/localhost/BUILD.bazel b/e2e/localhost/BUILD.bazel index 5a261932413cadd310f5a4034b384e3b617f9637..f739ea8cf719c037018e2f450416310c1df96ab1 100644 --- a/e2e/localhost/BUILD.bazel +++ b/e2e/localhost/BUILD.bazel @@ -37,6 +37,41 @@ labgrid_genrule( tools = ["@rules_labgrid//labgrid/run"], ) +labgrid_genrule( + name = "hello-and-transfer-to-ruledir", + # We need Bash to redirect to a file on the target + srcs = ["@ape//ape:bash"], + outs = ["run-and-transfer-to-ruledir.actual"], + cmd = "$(location @rules_labgrid//labgrid/run) --get output.txt:$(RULEDIR)/run-and-transfer-to-ruledir.actual $(location @ape//ape:bash) -c 'echo world > output.txt'", + platform = "@rules_labgrid//platform:localhost", + tools = ["@rules_labgrid//labgrid/run"], +) + +labgrid_genrule( + name = "hello-and-transfer-to-d", + # We need Bash to redirect to a file on the target + srcs = ["@ape//ape:bash"], + outs = ["run-and-transfer-to-d.actual"], + cmd = "$(location @rules_labgrid//labgrid/run) --get output.txt:$D/run-and-transfer-to-d.actual $(location @ape//ape:bash) -c 'echo world > output.txt'", + platform = "@rules_labgrid//platform:localhost", + tools = ["@rules_labgrid//labgrid/run"], +) + +labgrid_genrule( + name = "hello-and-transfer-to-nested-d", + # We need Bash to redirect to a file on the target + srcs = ["@ape//ape:bash"], + outs = ["nested/run-and-transfer-to-d.actual"], + cmd = "$(location @rules_labgrid//labgrid/run) --get output.txt:$D/run-and-transfer-to-d.actual $(location @ape//ape:bash) -c 'echo world > output.txt'", + platform = "@rules_labgrid//platform:localhost", + tools = ["@rules_labgrid//labgrid/run"], +) + +alias( + name = "run-and-transfer-to-nested-d.actual", + actual = "nested/run-and-transfer-to-d.actual", +) + labgrid_genrule( name = "hello-with-env", srcs = ["@ape//ape:printenv"], @@ -72,6 +107,9 @@ labgrid_run_binary( "run", "run-with-runfiles", "run-and-transfer-file-back", + "run-and-transfer-to-ruledir", + "run-and-transfer-to-d", + "run-and-transfer-to-nested-d", "run-with-env", "run-binary", ) diff --git a/labgrid/genrule/rule.bzl b/labgrid/genrule/rule.bzl index 6edde1d6d519d205bca2e3c91444b279cc968932..827ffcfd88da73d9e3f5854823fe99d531352303 100644 --- a/labgrid/genrule/rule.bzl +++ b/labgrid/genrule/rule.bzl @@ -1,4 +1,4 @@ -load("@bazel_skylib//lib:shell.bzl", "shell") +load("@bazel_skylib//lib:paths.bzl", "paths") load("//labgrid/cfg:store.bzl", _cfg = "store") visibility("//...") @@ -49,13 +49,14 @@ ATTRS = { } def _substitutions(ctx): - outs = [shell.quote(o.path) for o in ctx.outputs.outs] - srcs = [shell.quote(o.path) for o in ctx.files.srcs] + outs = [o.path for o in ctx.outputs.outs] + srcs = [o.path for o in ctx.files.srcs] # https://bazel.build/reference/be/make-variables#predefined_genrule_variables substitutions = { "$(OUTS)": " ".join(outs), "$(SRCS)": " ".join(srcs), + "$(RULEDIR)": paths.join(ctx.bin_dir.path, ctx.label.package), } if len(srcs) == 1: @@ -65,8 +66,11 @@ def _substitutions(ctx): if len(outs) == 1: substitutions["$@"] = outs[0] + substitutions["$D"] = paths.dirname(outs[0]) elif "$@" in ctx.attr.cmd: fail("Cannot specify `$@` Make variable with zero or multiple `outs`") + else: + substitutions["$D"] = paths.join(ctx.bin_dir.path, ctx.label.package) for key, value in ctx.var.items(): substitutions["$({})".format(key)] = value diff --git a/labgrid/run/run.py b/labgrid/run/run.py index 78ccee71c1019e2bc4326229cd3147e342db5951..aed999019d14627f0f2a84fea80d4becf272c2a4 100644 --- a/labgrid/run/run.py +++ b/labgrid/run/run.py @@ -247,7 +247,7 @@ class Get: def resolve(self, remote: PurePath) -> Get: return Get( remote=self.join(remote, self.remote), - local=self.join(environ.get("BAZEL_GEN_DIR", Path.cwd()), self.local), + local=self.join(Path.cwd(), self.local), optional=self.optional, )