keith / rules_multirun

Bazel rules for running multiple commands in parallel in a single bazel invocation
Apache License 2.0
65 stars 13 forks source link

Indirect command invocation fails after directory change #13

Closed aherrmann closed 1 year ago

aherrmann commented 1 year ago

Consider the following use-case:

A command that takes the path of another command as an argument, and executes it using runfiles location after changing directory. E.g.

# This will change directory into `$BUILD_WORKSPACE_DIRECTORY`
# and then invoke `buildozer` to generate some Bazel targets.
command(
    name = "update_targets_cmd",
    command = ":update_targets",
    arguments = [
        "--buildozer",
        "$(rootpath :buildozer)",
    ],
    data = [":buildozer"],
)

command(
    name = "buildozer",
    command = select({
        "@platforms//os:linux": "@com_github_bazelbuild_buildtools_buildozer_linux_amd64//file",
        "@platforms//os:macos": "@com_github_bazelbuild_buildtools_buildozer_darwin_amd64//file",
        "@platforms//os:windows": "@com_github_bazelbuild_buildtools_buildozer_windows_amd64//file",
    }),
)

This fails to find the buildozer binary when executing update_targets because the bash script generated by command attempts to execute .short_path directly relative to the current working directory.

To support this use-case the generated bash script would have to look up the target executable using rlocation.