Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag to keep CWD in bazel run #11780

Closed
kerrick-lyft opened this issue Jul 15, 2020 · 1 comment
Closed

Add flag to keep CWD in bazel run #11780

kerrick-lyft opened this issue Jul 15, 2020 · 1 comment

Comments

@kerrick-lyft
Copy link
Contributor

kerrick-lyft commented Jul 15, 2020

Feature request:

I would like to request a flag --keep_cwd be added to bazel run that, when set, runs the child process in the same working directory that bazel was invoked in.

In addition, I'd propose adding a BUILD_RUNFILES (or maybe just RUNFILES) environment variable that contains the runfiles path (this is the same as PWD when --keep_cwd is not passed). This way, binaries can be updated to be agnostic to whether --keep_cwd was passed or not by always looking under $BUILD_RUNFILES for runfiles instead of under the CWD.

This is similar to #3325 but I'm trying to put forward a concrete proposal that is backwards compatible.

Feature requests: what underlying problem are you trying to solve with this feature?

Oftentimes I would like to bazel run a program relative to the working directory (e.g. a program that dumps some output to a text file in the CWD).

If this option existed, I would probably add it to the .bazelrc in the repository that I work in (after double-checking that binaries correctly reference BUILD_RUNFILES instead of PWD) because running in the CWD is a very common use-case for me and other users of this repository (currently we use the work-around bazel build //path/to:bin && bazel-bin/path/to/bin).

What operating system are you running Bazel on?

macOS 10.15.4.

What's the output of bazel info release?

release 3.3.0-homebrew

What's the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?

(proprietary repo)

Have you found anything relevant by searching the web?

#3325

https://stackoverflow.com/questions/47764221/how-to-write-files-to-current-directory-instead-of-bazel-out

Any other information, logs, or outputs that you want to share?

In #3325 they propose using argv[0] to get the directory that the binary was invoked in in order to infer the runfiles directory, but I'm not sure this is as simple or as general as just having a BUILD_RUNFILES env var.

I'm not hard set on the name --keep_cwd; it's just a suggestion.

@oquenchil
Copy link
Contributor

See Jin's answer here: https://stackoverflow.com/a/47872013

This is not possible by design. I will close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants