From 0b11619e2858ad75a21fb06be9f400a693c8c34b Mon Sep 17 00:00:00 2001 From: Alex Tercete Date: Mon, 28 Jul 2025 15:50:14 +0100 Subject: [PATCH 1/2] refactor: use env var for `Rlocation` path --- e2e/test/BUILD.bazel | 6 ++++++ e2e/test/hello.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/e2e/test/BUILD.bazel b/e2e/test/BUILD.bazel index 1ff1f4c4..8cf5143b 100644 --- a/e2e/test/BUILD.bazel +++ b/e2e/test/BUILD.bazel @@ -6,6 +6,9 @@ py_binary( name = "inner", srcs = ["hello.py"], data = [":hello.txt"], + env = { + "HELLO_PATH": "$(rlocationpath :hello.txt)", + }, main = "hello.py", visibility = [":__subpackages__"], deps = ["@rules_python//python/runfiles"], @@ -110,6 +113,9 @@ labgrid_test( size = "small", src = ":inner-without-data", data = [":hello.txt"], + env = { + "HELLO_PATH": "$(rlocationpath :hello.txt)", + }, ) write_file( diff --git a/e2e/test/hello.py b/e2e/test/hello.py index e1d44184..06543116 100644 --- a/e2e/test/hello.py +++ b/e2e/test/hello.py @@ -1,5 +1,6 @@ import unittest from pathlib import Path +from os import environ from python.runfiles import Runfiles @@ -11,7 +12,7 @@ def _runfile(path): class HelloTestCase(unittest.TestCase): def test(self): - self.assertEqual(_runfile("_main/test/hello.txt").rstrip(), "world") + self.assertEqual(_runfile(environ["HELLO_PATH"]).rstrip(), "world") if __name__ == "__main__": -- GitLab From 1f09c62e577a64c24ca845e02d5601242b8b90e7 Mon Sep 17 00:00:00 2001 From: Alex Tercete Date: Tue, 29 Jul 2025 10:17:19 +0100 Subject: [PATCH 2/2] fix(test): accept `TreeArtifact` runfiles --- e2e/MODULE.bazel | 1 + e2e/MODULE.bazel.lock | 2 +- e2e/test/BUILD.bazel | 24 ++++++++++++++++++++++++ labgrid/runfiles/defs.bzl | 3 ++- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/e2e/MODULE.bazel b/e2e/MODULE.bazel index 25e0f254..7f53b7a5 100644 --- a/e2e/MODULE.bazel +++ b/e2e/MODULE.bazel @@ -10,6 +10,7 @@ bazel_dep(name = "toolchain_utils", version = "1.0.2") bazel_dep(name = "rules_python", version = "1.2.0") bazel_dep(name = "rules_diff", version = "1.0.0") bazel_dep(name = "rules_zstd", version = "1.0.0") +bazel_dep(name = "aspect_bazel_lib", version = "2.14.0") bazel_dep(name = "ape", version = "1.0.1") bazel_dep(name = "rules_labgrid") local_path_override( diff --git a/e2e/MODULE.bazel.lock b/e2e/MODULE.bazel.lock index 6a30297d..f5a9fb6b 100644 --- a/e2e/MODULE.bazel.lock +++ b/e2e/MODULE.bazel.lock @@ -270,7 +270,7 @@ "@@platforms//host:extension.bzl%host_platform": { "general": { "bzlTransitiveDigest": "xelQcPZH8+tmuOHVjL9vDxMnnQNMlwj0SlvgoqBkm4U=", - "usagesDigest": "XzdJB+yoYQTA23Jn6P1B9SSXmlXoFnMxt4fnVhrhjwI=", + "usagesDigest": "eKQSPbCJCzwdqDfIyJ+cheVNlVKVHmts40y1P3np7Sw=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, diff --git a/e2e/test/BUILD.bazel b/e2e/test/BUILD.bazel index 8cf5143b..77f6d559 100644 --- a/e2e/test/BUILD.bazel +++ b/e2e/test/BUILD.bazel @@ -1,3 +1,4 @@ +load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory") load("@bazel_skylib//rules:write_file.bzl", "write_file") load("@rules_labgrid//labgrid/test:defs.bzl", "labgrid_test") load("@rules_python//python:defs.bzl", "py_binary") @@ -182,3 +183,26 @@ labgrid_test( size = "small", src = ":inner-undeclared-outputs-dir", ) + +copy_to_directory( + name = "greetings", + srcs = [":hello.txt"], +) + +py_binary( + name = "inner-tree-artifact", + srcs = ["hello.py"], + data = [":greetings"], + env = { + "HELLO_PATH": "$(rlocationpath :greetings)/hello.txt", + }, + main = "hello.py", + deps = ["@rules_python//python/runfiles"], +) + +# Regression test for: https://gitlab.arm.com/bazel/rules_labgrid/-/issues/81 +labgrid_test( + name = "tree-artifact", + size = "small", + src = ":inner-tree-artifact", +) diff --git a/labgrid/runfiles/defs.bzl b/labgrid/runfiles/defs.bzl index 6c2cd5c6..e21303ff 100644 --- a/labgrid/runfiles/defs.bzl +++ b/labgrid/runfiles/defs.bzl @@ -9,7 +9,8 @@ def runfiles_dir(ctx, target, additional_files = []): runfiles_base = "{}.runfiles".format(target.label.name) files = target.default_runfiles.files.to_list() for file in files + additional_files: - out = ctx.actions.declare_file(paths.join(runfiles_base, to_rlocation_path(ctx, file))) + declare = ctx.actions.declare_directory if file.is_directory else ctx.actions.declare_file + out = declare(paths.join(runfiles_base, to_rlocation_path(ctx, file))) ctx.actions.symlink( output = out, target_file = file, -- GitLab