keith / rules_multirun

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

Allow user to pass arguments via bazel run #44

Closed alexeagle closed 8 months ago

alexeagle commented 8 months ago

Multirun gets spawned by a generated bash wrapper like this:

exec ./'../rules_multirun~0.7.0/internal/multirun' -f 'tools/format/format.json' "$@"

Currently the multirun executable assumes the last argv is the instructions:

https://github.com/keith/rules_multirun/blob/main/internal/multirun.py#L112

This means if the user passes an argument, say from rules_lint they want to format only one file:

% bazel run format lint.sh

it fails:

  File "/private/var/tmp/_bazel_alexeagle/3eecd93732ac7c6f4f360a54a468da50/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/tools/format/format.bash.runfiles/_main/../rules_multirun~0.7.0/internal/multirun.py", line 91, in <module>
    _main(sys.argv[-1])
  File "/private/var/tmp/_bazel_alexeagle/3eecd93732ac7c6f4f360a54a468da50/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/tools/format/format.bash.runfiles/_main/../rules_multirun~0.7.0/internal/multirun.py", line 73, in _main
    with open(path) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'lint.sh'

In my case, the behavior I had prior to adopting rules_multirun was that the aggregator binary passed the argv to each of the binaries it wraps, so that's what I would want to do here.

keith commented 8 months ago

hrm I actually removed that "$@" in https://github.com/keith/rules_multirun/commit/e7d1d13e52c086586d593d215518509bfb613dfa#diff-50b072d077ec6196a13e98aec4bd258a68b30d4128ee3b6e79aa51e196e1c3b3L116, I think because I thought it wasn't doing anything, so I can add it back and fix this with this I think, can you test it?

https://github.com/keith/rules_multirun/pull/45

alexeagle commented 8 months ago

Thanks - in my case that's not enough, because I want to pass the args to the underlying binary that gets spawned. I think in that commit they still get dropped on the floor.

neckbosov commented 8 months ago

+1, in atlassian/bazel-tools implementation of multirun arguments of bazel run are passed to every command.

keith commented 8 months ago

ah ok, def happy to take a PR to fix

hunshcn commented 8 months ago

https://github.com/keith/rules_multirun/pull/48 it works

cc @keith @alexeagle

alexeagle commented 8 months ago

Nice! Thank you!

keith commented 8 months ago

thanks!