-
Notifications
You must be signed in to change notification settings - Fork 4.4k
bazel run child should run with bazel invocation's current directory #3325
Copy link
Copy link
Closed
Labels
Description
Description of the problem / feature request / question:
When using the bazel run command, the spawned child has a working directory different from the directory where the command is run. This leads to bazel run //path/to/target and bazel-bin/path/to/target/target being quite different. If possible, it would be ideal to have the child inherit the bazel invocation's working directory.
If possible, provide a minimal example to reproduce the problem:
Note difference between output of last two commands.
$ cd $(mktemp -d)
$ pwd
/tmp/tmp.VzGLDvgQvk
$ touch WORKSPACE
$ mkdir -p path/to/target
$ cat <<EOF > path/to/target/BUILD
sh_binary(
name = "target",
srcs = ["target.sh"],
)
EOF
$ cat <<EOF > path/to/target/target.sh
#!/bin/bash
pwd
EOF
$ chmod +x path/to/target/target.sh
$ bazel run //path/to/target 2>/dev/null
/home/kamal/.cache/bazel/_bazel_kamal/f4a400f5a0927c37f590fcc3c0d7cf1c/execroot/tmp.VzGLDvgQvk/bazel-out/local-fastbuild/bin/path/to/target/target.runfiles/__main__
$ bazel-bin/path/to/target/target
/tmp/tmp.VzGLDvgQvk
Environment info
- Operating System:
$ head -1 /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
$ uname -r
4.9.0-3-amd64
- Bazel version (output of
bazel info release):
$ bazel info release
release 0.5.1
Have you found anything relevant by searching the web?
Original bazel-discuss thread: https://groups.google.com/d/msgid/bazel-discuss/CAA%3DsxTgFY9D1kyGaGKCuqUftUBAizNdXu28o_zsKRkgA3F-ZwA
Anything else, information or logs or outputs that would be helpful?
The working directory seems to be set here to the runfiles dir:
bazel/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java
Line 220 in 5e60e38
| workingDir = ensureRunfilesBuilt(env, targetToRun); |
Reactions are currently unavailable