Skip to content

bazel run child should run with bazel invocation's current directory #3325

@kamalmarhubi

Description

@kamalmarhubi

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:

workingDir = ensureRunfilesBuilt(env, targetToRun);

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions