From 26cbcccb8463b71f38a458467d454a16c852a481 Mon Sep 17 00:00:00 2001 From: Alex Tercete Date: Fri, 6 Sep 2024 09:48:40 +0100 Subject: [PATCH 1/4] fix(genrule): Include runfiles from binary --- labgrid/genrule/rule.bzl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/labgrid/genrule/rule.bzl b/labgrid/genrule/rule.bzl index 0d276a7a..752dbbe3 100644 --- a/labgrid/genrule/rule.bzl +++ b/labgrid/genrule/rule.bzl @@ -78,8 +78,7 @@ def implementation(ctx): executable = executor.run, arguments = [args], outputs = ctx.outputs.outs, - inputs = depset(transitive = [s.files for s in ctx.attr.srcs]), - tools = [t.files_to_run for t in ctx.attr.tools] + [ctx.executable._sh], + tools = [t.files_to_run for t in (ctx.attr.tools + ctx.attr.srcs)] + [ctx.executable._sh], env = executor.env, mnemonic = "LabGridGenrule", ) -- GitLab From ef9a2c6c6c239d43bf88d6f388aa58aff4726965 Mon Sep 17 00:00:00 2001 From: Alex Tercete Date: Fri, 6 Sep 2024 09:58:23 +0100 Subject: [PATCH 2/4] feat(e2e): Transfer runfiles alongside binary --- e2e/docker/ssh.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/e2e/docker/ssh.py b/e2e/docker/ssh.py index fa8f7e19..0c1ff803 100755 --- a/e2e/docker/ssh.py +++ b/e2e/docker/ssh.py @@ -58,6 +58,12 @@ def main(exe: Path, *args: str) -> int: program = "/tmp/{}".format(parsed.program.name) transfer.put(parsed.program, program) + # Transfer runfiles + src_runfiles = parsed.program.with_suffix(".runfiles") + dest_runfiles = Path(program).with_suffix(".runfiles") + if src_runfiles.exists(): + transfer.put(src_runfiles, dest_runfiles) + # Run the transferred program out, err, code = shell.run(join((program, *parsed.arguments))) for line in out: -- GitLab From e84664f032135bd0c7f21636b716f5c3f5e8931e Mon Sep 17 00:00:00 2001 From: Alex Tercete Date: Fri, 6 Sep 2024 11:00:30 +0100 Subject: [PATCH 3/4] refactor: Reorder load statements --- e2e/docker/BUILD.bazel | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/docker/BUILD.bazel b/e2e/docker/BUILD.bazel index cc34f9a0..747db5fd 100644 --- a/e2e/docker/BUILD.bazel +++ b/e2e/docker/BUILD.bazel @@ -1,8 +1,8 @@ -load("@rules_python//python:defs.bzl", "py_binary", "py_library") -load("@rules_labgrid//labgrid/genrule:defs.bzl", "labgrid_genrule") +load("@rules_diff//diff/file/test:defs.bzl", "diff_file_test") load("@rules_labgrid//labgrid/executor:defs.bzl", "labgrid_executor") +load("@rules_labgrid//labgrid/genrule:defs.bzl", "labgrid_genrule") load("@rules_labgrid//labgrid/transition:defs.bzl", "labgrid_transition") -load("@rules_diff//diff/file/test:defs.bzl", "diff_file_test") +load("@rules_python//python:defs.bzl", "py_binary", "py_library") load("@toolchain_utils//toolchain/info:defs.bzl", "toolchain_info") # The goal of this test/example is to use the nut/bolts of `rules_labgrid` -- GitLab From b5dfcb238526e5b5e837693f255f09b56bed01e5 Mon Sep 17 00:00:00 2001 From: Alex Tercete Date: Mon, 9 Sep 2024 09:24:08 +0100 Subject: [PATCH 4/4] feat(e2e): Use binary that needs runfiles This adds test coverage to binaries that need runfiles to run. There seems to be a bug[1] which affects `py_binary`'s and causes its output to include multiple files (which in turn forces us to use $(locations <...>)). So I had to make my custom implementation of `cat` extra hardcoded. [1]: https://github.com/bazelbuild/bazel/issues/20038 --- e2e/docker/BUILD.bazel | 10 ++++++++-- e2e/docker/cat.py | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 e2e/docker/cat.py diff --git a/e2e/docker/BUILD.bazel b/e2e/docker/BUILD.bazel index 747db5fd..af07985e 100644 --- a/e2e/docker/BUILD.bazel +++ b/e2e/docker/BUILD.bazel @@ -76,6 +76,12 @@ toolchain( toolchain_type = "@rules_labgrid//labgrid/toolchain/executor:type", ) +# A simplistic implementation of cat which dependends on runfiles +py_binary( + name = "cat", + 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 @@ -83,9 +89,9 @@ toolchain( # - `@ape//:cat` is provided to labgrid_genrule( name = "echo", - srcs = ["@ape//:cat"], + srcs = [":cat"], outs = ["stdout.log"], - cmd = "$(location :ssh) $(location @ape//:cat) /etc/os-release > $@", + cmd = "$(location :ssh) $(locations :cat) /etc/os-release > $@", tags = ["manual"], tools = [":ssh"], ) diff --git a/e2e/docker/cat.py b/e2e/docker/cat.py new file mode 100644 index 00000000..13d94bc0 --- /dev/null +++ b/e2e/docker/cat.py @@ -0,0 +1,4 @@ +import fileinput + +for line in fileinput.input(files="/etc/os-release"): + print(line, end="") -- GitLab