-
-
Notifications
You must be signed in to change notification settings - Fork 16k
Introduce a interfaces to expose the current Command captured env var logic #149070
Copy link
Copy link
Open
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-needs-to-bakeStatus: The implementation is "complete" but it needs time to bake.Status: The implementation is "complete" but it needs time to bake.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
Activity
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-needs-to-bakeStatus: The implementation is "complete" but it needs time to bake.Status: The implementation is "complete" but it needs time to bake.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
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::Commandto expose environment variable resolution logic, addressing the inability to observe the effects ofenv_clear()and the lack of a single source of truth for environment variable resolution.Public API
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.)get_env_clear: Add Command::get_env_clear #149074get_resolved_envs: Add Command::get_resolved_envs #149362Unresolved 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.Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩