diff --git a/e2e/run/BUILD.bazel b/e2e/run/BUILD.bazel index 139415376b4d5b997a10f5b17464f03a38baf3ea..34cf2f097f7878b1f8a28daec43d3a75e8c079ba 100644 --- a/e2e/run/BUILD.bazel +++ b/e2e/run/BUILD.bazel @@ -1,6 +1,7 @@ load("@bazel_skylib//rules:write_file.bzl", "write_file") load("@rules_diff//diff/file/test:defs.bzl", "diff_file_test") load("@rules_labgrid//labgrid/genrule:defs.bzl", "labgrid_genrule") +load("@rules_labgrid//labgrid/run/binary:defs.bzl", "labgrid_run_binary") load("@rules_python//python:defs.bzl", "py_binary") labgrid_genrule( @@ -105,6 +106,24 @@ labgrid_genrule( tools = ["@rules_labgrid//labgrid/run"], ) +# Regression test for: https://gitlab.arm.com/bazel/rules_labgrid/-/issues/73 +labgrid_run_binary( + name = "hello-with-program-prefix", + srcs = ["@ape//ape:bash"], + outs = ["program-prefix.actual"], + args = [ + "--program-prefix", + "''", + "--get", + "output.txt:$(location :program-prefix.actual)", + "$(location @ape//ape:bash)", + "-c", + "echo world > output.txt", + ], + platform = "@rules_labgrid//labgrid/platform:localhost", + tool = "@rules_labgrid//labgrid/run", +) + write_file( name = "expected", out = ":hello.txt", @@ -131,5 +150,6 @@ write_file( "put-file-with-remote", "put-file-without-remote", "env", + "program-prefix", ) ] diff --git a/labgrid/run/__main__.py b/labgrid/run/__main__.py index ae8eab7bf5bcd5f44d2b7630fcfbc01076c81710..b9021c529d61048e205c10bdddfaca93d8db1530 100644 --- a/labgrid/run/__main__.py +++ b/labgrid/run/__main__.py @@ -26,8 +26,8 @@ def arguments(prsr: ArgumentParser) -> None: ) prsr.add_argument( "--program-prefix", - type=PurePath, - default=PurePath(""), + type=unquoted, + default="", help="Prefix of the path to the program on the device.", ) prsr.add_argument( @@ -70,6 +70,11 @@ def resolve(value: str) -> Path: return Path(value) +def unquoted(value: str) -> str: + # FIXME: Extract `BazelArgumentParser` to handle quoting + return value.removeprefix("'").removesuffix("'") + + def env(arg: str) -> tuple[str, str]: key, sep, value = arg.partition("=") if not sep: @@ -80,8 +85,7 @@ def env(arg: str) -> tuple[str, str]: def get(value: str) -> FileTransfer: - # FIXME: Extract `BazelArgumentParser` to handle quoting - remote, found, local = value.removeprefix("'").removesuffix("'").partition(":") + remote, found, local = unquoted(value).partition(":") optional = remote.endswith("?") if optional: remote = remote.removesuffix("?") @@ -93,8 +97,7 @@ def get(value: str) -> FileTransfer: def put(value: str) -> FileTransfer: - # FIXME: Extract `BazelArgumentParser` to handle quoting - local, found, remote = value.removeprefix("'").removesuffix("'").partition(":") + local, found, remote = unquoted(value).partition(":") if found: local = Template(local).substitute(environ) else: @@ -114,7 +117,7 @@ def main(exe: Path, *args: str) -> int: return run( parsed.program, *parsed.arguments, - program_prefix=parsed.program_prefix, + program_prefix=PurePath(parsed.program_prefix), downloads=parsed.downloads, uploads=parsed.uploads, env=dict(parsed.env),