bazel-contrib / bazel-contrib/rules_multitool

`cwd` target missing wrapped target args

Open
#83 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
25
Forks
11
PR merge metrics
No merged PRs in 30d

Description

Hi, when using `cwd` target, the wrapped target no longer gets called with `args`. We're trying to create a `py_binary` target that has `args` and `data` arguments, and wrap this target in `cwd` target. I've prepared an example:

```bazel
load("@rules_multitool//multitool:cwd.bzl", "cwd")

py_binary(
name = "wrapper_script",
main = "wrapper_script.py",
srcs = ["wrapper_script.py"],
args = [
"--flag=test",
],
)

cwd(
name = "wrapper_cwd",
tool = ":wrapper_script",
)

```

```python
import sys
import os

def main():
print(f"CWD: {os.getcwd()}")
print(f"Args: {sys.argv}")

if __name__ == "__main__":
main()

```

When running the `wrapped_script` directly, `args` are passed to the script:
```
~/Development/rules_multitool/examples/workspace main !1 ?2 ❯ bazel run //:wrapper_script
INFO: Analyzed target //:wrapper_script (0 packages loaded, 348 targets configured).
INFO: Found 1 target...
Target //:wrapper_script up-to-date:
bazel-bin/wrapper_script
INFO: Elapsed time: 0.142s, Critical Path: 0.01s
INFO: 6 processes: 6 internal.
INFO: Build completed successfully, 6 total actions
INFO: Running command line: bazel-bin/wrapper_script '--flag=test'
CWD: /private/var/tmp/_bazel_bchmie/010cf06a2ade71317327f6ebfc0743de/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/wrapper_script.runfiles/_main
Args: ['/private/var/tmp/_bazel_bchmie/010cf06a2ade71317327f6ebfc0743de/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/wrapper_script.runfiles/_main/wrapper_script.py', '--flag=test']
```

however, when called using `cwd` target, the args are no longer there:
```
~/Development/rules_multitool/examples/workspace main !1 ?2 ❯ bazel run //:wrapper_cwd 5s
INFO: Analyzed target //:wrapper_cwd (1 packages loaded, 3 targets configured).
INFO: Found 1 target...
Target //:wrapper_cwd up-to-date:
bazel-bin/wrapper_cwd
INFO: Elapsed time: 0.099s, Critical Path: 0.01s
INFO: 5 processes: 5 internal.
INFO: Build completed successfully, 5 total actions
INFO: Running command line: bazel-bin/wrapper_cwd
CWD: /Users/bchmie/Development/rules_multitool/examples/workspace
Args: ['/private/var/tmp/_bazel_bchmie/010cf06a2ade71317327f6ebfc0743de/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/wrapper_cwd.runfiles/_main/wrapper_script.py']
```

I'm attaching a patch with the example.

[repro.patch](https://github.com/user-attachments/files/20878563/repro.patch)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.