Introduce a interfaces to expose the current `Command` captured env var logic
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Feature gate: #![feature(command_resolved_envs)]
This is a tracking issue for the API Change Proposal (ACP) rust-lang/libs-team#194.
This feature adds two methods to std::process::Command to expose environment variable resolution logic, addressing the inability to observe the effects of env_clear() and the lack of a single source of truth for environment variable resolution.
Public API
// std::process
impl Command {
pub fn get_env_clear(&self) -> bool;
pub fn get_resolved_envs(&self) -> CommandResolvedEnvs;
}
// `get_resolved_envs` returns a concrete iterator type:
pub struct CommandResolvedEnvs { /* .. */ }
impl Iterator for CommandResolvedEnvs {
type Item = (OsString, OsString);
// ..
}
Explanation:
get_env_clearThis makes sure people have all the information Command stores.get_resolved_envsThis should include documentation that says it returns the environment as it would be if the command were executed at that point, and will not match if the environment is subsequently changed (including in a pre_exec hook). This avoids duplicating the Command logic.
Steps / History
(Remember to update the S-tracking-* label when checking boxes.)
- ACP: rust-lang/libs-team#194
- Implementation:
-
get_env_clear: #149074 -
get_resolved_envs: #149362
-
- Final comment period (FCP)^1
- Stabilization PR
Unresolved Questions
Both questions raised at filing time have been resolved during implementation:
Should this useResolved:impl Iteratorin the return type, or a concrete iterator type?get_resolved_envsreturns a concrete iterator type (CommandResolvedEnvs), matching the precedent set bystd::env::vars_os/std::env::VarsOsand leaving room to add impls such asDebug. See #149362 and this comment.Should we allow borrowing fromResolved: the iterator yields ownedstd::process::Command(or other sources) in the returned iterator, rather than requiring(OsString, OsString)which implies fresh allocations for each environment variable and value on every iteration?(OsString, OsString), consistent withstd::env::vars_os. Anyone able to spawn a process can afford these allocations, which are negligible relative to process spawning.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
This is a tracking issue for std::process::Command APIs; read the ACP in rust-lang/libs-team#194 and the stabilization guidance linked in the issue. The implementation work is already recorded as complete in #149074 and #149362, so the remaining milestone is the final comment period followed by a stabilization PR.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100