diff --git a/e2e/docker/BUILD.bazel b/e2e/docker/BUILD.bazel index f3a2562d174a851265ed368b60ac6c6c0203531e..dd0cf11a7ab83da1b3ca85c5db78487b857e1994 100644 --- a/e2e/docker/BUILD.bazel +++ b/e2e/docker/BUILD.bazel @@ -1,34 +1,8 @@ load("@rules_diff//diff/file/test:defs.bzl", "diff_file_test") load("@rules_labgrid//labgrid/config/toolchain:defs.bzl", "labgrid_config_toolchain") -load("@rules_labgrid//labgrid/genrule:defs.bzl", "labgrid_genrule") -load("@rules_labgrid//labgrid/transition:defs.bzl", "labgrid_transition") +load("@rules_labgrid//labgrid/run:defs.bzl", "labgrid_run") load("@rules_python//python:defs.bzl", "py_binary") -# The goal of this test/example is to use the nut/bolts of `rules_labgrid` -# It exposes _all_ the steps to configure the `labgrid_genrule` -# Usually, higher-level macros are used -# These are _not_ hermetic to avoid implementation complexity. -# To run these rules, the following are needed on the host: -# - `docker` -# - `ssh` -# - `scp` -# The later targets are marked as "manual" so `bazel {build,test} //...` do not pick them up - -# This is *not* hermetic and requires access to `docker`/`ssh` on the host -# Useful as a test with `bazel run -- docker:ssh /path/to/target/binary argument` -# This is used later within `labgrid_genrule` -py_binary( - name = "ssh", - srcs = ["ssh.py"], - args = ["--lg-env=$(location local-ubuntu.16.04-gnu.yaml)"], - data = ["local-ubuntu.16.04-gnu.yaml"], - tags = ["manual"], - deps = [ - "@rules_labgrid//labgrid:pkg", - "@rules_labgrid//labgrid/config:deps", - ], -) - # A constraint to register the toolchain to constraint_setting(name = "device") @@ -65,25 +39,12 @@ py_binary( srcs = ["cat.py"], ) -# Run within the LabGrid environment -# This shows a few things: -# - It resolves the executor registered above to set up the `LG_ENV` enviroment variable -# - `:ssh` target uses `LG_ENV` to start the Docker container -# - `@ape//:cat` is provided to -labgrid_genrule( +labgrid_run( name = "echo", srcs = [":cat"], outs = ["stdout.log"], - cmd = "$(location :ssh) $(locations :cat) /etc/os-release > $@", - tags = ["manual"], - tools = [":ssh"], -) - -# Transition the above `genrule` to the Docker platform -labgrid_transition( - name = "transition", - srcs = [":stdout.log"], - platforms = [":platform"], + cmd = "$(locations :cat) /etc/os-release > $@", + platform = ":platform", tags = ["manual"], ) @@ -92,6 +53,6 @@ diff_file_test( name = "test", size = "small", a = ":version.txt", - b = ":transition", + b = ":stdout.log", tags = ["manual"], ) diff --git a/labgrid/cfg/store.bzl b/labgrid/cfg/store.bzl index 15d63c40f5a56b8e286b50bec01cc1183e279a81..bf810f3ebda78ebfe11e7e83fcc81f175d9e847a 100644 --- a/labgrid/cfg/store.bzl +++ b/labgrid/cfg/store.bzl @@ -9,7 +9,7 @@ def _each(platform): } def implementation(settings, attr): - platform = settings["//command_line_option:platforms"] + platform = attr.platform or settings["//command_line_option:platforms"] if types.is_list(platform): return [_each(p) for p in platform] return _each(platform) diff --git a/labgrid/genrule/rule.bzl b/labgrid/genrule/rule.bzl index 2ba49880c620c7eba3fddd072c34e519cb436434..9739dbdf386c14363412c7cda1984db7ad0af7ad 100644 --- a/labgrid/genrule/rule.bzl +++ b/labgrid/genrule/rule.bzl @@ -29,6 +29,10 @@ ATTRS = { mandatory = True, allow_empty = False, ), + "platform": attr.label( + doc = "Platform to transition to.", + providers = [platform_common.PlatformInfo], + ), "_executor": attr.label( doc = "The LabGrid environment executor", default = "//labgrid/executor", diff --git a/labgrid/run/BUILD.bazel b/labgrid/run/BUILD.bazel new file mode 100644 index 0000000000000000000000000000000000000000..fe0048d7e98957b7dea2b4c6c9024729831978d3 --- /dev/null +++ b/labgrid/run/BUILD.bazel @@ -0,0 +1,12 @@ +load("@rules_python//python:defs.bzl", "py_binary") + +py_binary( + name = "run", + srcs = ["run.py"], + tags = ["manual"], + visibility = ["//visibility:public"], + deps = [ + "//labgrid:pkg", + "//labgrid/config:deps", + ], +) diff --git a/labgrid/run/defs.bzl b/labgrid/run/defs.bzl new file mode 100644 index 0000000000000000000000000000000000000000..011620d53848192245cd4b86f9afa4650a809c99 --- /dev/null +++ b/labgrid/run/defs.bzl @@ -0,0 +1,5 @@ +load(":macro.bzl", _run = "labgrid_run") + +visibility("public") + +labgrid_run = _run diff --git a/labgrid/run/macro.bzl b/labgrid/run/macro.bzl new file mode 100644 index 0000000000000000000000000000000000000000..be08399b88a0f485b04d70f6710b1ca3b95b35f5 --- /dev/null +++ b/labgrid/run/macro.bzl @@ -0,0 +1,15 @@ +load("//labgrid/genrule:defs.bzl", "labgrid_genrule") + +visibility("//...") + +def labgrid_run(name, srcs, outs, cmd, platform = None, **kwargs): + run = Label("//labgrid/run") + labgrid_genrule( + name = name, + srcs = srcs, + outs = outs, + cmd = "$(location {}) {}".format(run, cmd), + platform = platform, + tools = [run], + **kwargs + ) diff --git a/e2e/docker/ssh.py b/labgrid/run/run.py old mode 100755 new mode 100644 similarity index 100% rename from e2e/docker/ssh.py rename to labgrid/run/run.py