Future of labgrid_run
The labgrid_run
is a very thin layer on top of labgrid_genrule
that uses //labgrid/run
to run the provided cmd
on the device.
Currently, it's trying to serve two potentially contradictory purposes:
- Be a genrule for the target
- Provide syntax sugar
Should we pick one, or have a separate macros for each? If so, what names should we use?
Genrule for the target
If we think of labgrid_run
as a version of labgrid_genrule
that runs on the target, then the following is already possible:
labgrid_run(
name = "hello",
srcs = ["@ape//ape:echo"],
outs = ["output.txt"],
cmd = "$(location @ape//ape:echo) world > $@",
platform = ":platform",
)
But that quickly falls apart:
labgrid_run(
name = "hello",
srcs = [
"@ape//ape:echo",
"@ape//ape:tee",
],
outs = ["output.txt"],
cmd = "$(location @ape//ape:echo) world | @(location @ape//ape:tee) $@",
platform = ":platform",
)
This doesn't work because labgrid_run
isn't really a genrule: cmd
runs on the host, so any Bash pipes or redirections will happen there.
We could possibly implement labgrid_target_genrule
by running cmd
inside of a hermetic Bash inside of the device. But there would be some complications, such as making sure the srcs
(or possibly tools
in this case) transition to the target and are transferred to the device. Or finding a way to substitute $(location)
and $@
to values that make sense for the device, and making sure the output files are transferred back to the host.
Syntax sugar
If we think of labgrid_run
as a convenient way to run labgrid_genrule
and //labgrid/run
, then we should probably add env
and get
attributes to it, which would translate into --env
and --get
flags for //labgrid/run
.
So that this:
labgrid_genrule(
name = "hello-with-env",
srcs = ["@ape//ape:printenv"],
outs = ["run-with-env.actual"],
cmd = "$(location @rules_labgrid//labgrid/run) --env HELLO=world -- $(location @ape//ape:printenv) HELLO > $@",
platform = ":platform",
tools = ["@rules_labgrid//labgrid/run"],
)
Could be written as:
labgrid_run(
name = "hello-with-env",
srcs = ["@ape//ape:printenv"],
outs = ["run-with-env.actual"],
env = {
"HELLO": "world",
}
cmd = "$(location @ape//ape:printenv) HELLO > $@",
platform = ":platform",
)