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

Runfiles library should provide environment variables for subprocesses #2423

Closed
phst opened this issue Apr 5, 2020 · 3 comments · Fixed by #3205
Closed

Runfiles library should provide environment variables for subprocesses #2423

phst opened this issue Apr 5, 2020 · 3 comments · Fixed by #3205

Comments

@phst
Copy link
Contributor

phst commented Apr 5, 2020

If a Bazel-built binary wants to launch another Bazel-built binary, it needs to tell the latter binary where to find the runfiles, because argv[0] for the latter binary will be different (or, in case of scripts, entirely unavailable). Other languages provide a function that returns RUNFILES_DIR and RUNFILES_MANIFEST environment variables (see https://github.com/bazelbuild/bazel/blob/master/tools/cpp/runfiles/runfiles_src.h#L159 for C++), and runfiles.go should provide the same:

func EnvVars() []string
@jayconrod
Copy link
Contributor

Please fill out the issue template and describe the specific problem you're having.

Shouldn't subprocesses already see RUNFILES_DIR or RUNFILES_MANIFEST_FILE from the parent process? Not sure why they'd need to be different.

@phst
Copy link
Contributor Author

phst commented Apr 12, 2020

Please fill out the issue template and describe the specific problem you're having.

This is essentially #2359 combined with https://docs.bazel.build/versions/master/skylark/rules.html#tools-depending-on-tools "To simplify subtool tool logic, it’s recommended that each subtool optionally accept its runfiles root as a parameter (via environment or command line argument/flag). A root tool can thus pass the correct canonical runfiles root to any of its subtools." and the reasoning given at https://github.com/bazelbuild/bazel/blob/master/tools/cpp/runfiles/runfiles_src.h#L58.
I can come up with a full example if you want, but I hope these documents clarify the problem.

Shouldn't subprocesses already see RUNFILES_DIR or RUNFILES_MANIFEST_FILE from the parent process? Not sure why they'd need to be different.

These variables are only set when using bazel run or bazel test, but not when using a Bazel-built binary in a Bazel action or running it directly. Then the runfiles library needs to look at os.Args[0] as described in #2359, but subprocesses that are themselves Bazel-built binaries with runfiles can't do that because for them os.Args[0] is different, so the parent binary needs a way to communicate the runfiles location to the subprocesses.

@jayconrod
Copy link
Contributor

Thanks, that makes more sense. Marking as a feature request.

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

Successfully merging a pull request may close this issue.

2 participants