turbo_tasks_env/
command_line.rs

1use turbo_rcstr::RcStr;
2use turbo_tasks::{FxIndexMap, Vc, mark_session_dependent};
3
4use crate::{EnvMap, GLOBAL_ENV_LOCK, ProcessEnv, sorted_env_vars};
5
6/// Load the environment variables defined via command line.
7#[turbo_tasks::value]
8pub struct CommandLineProcessEnv;
9
10#[turbo_tasks::value_impl]
11impl CommandLineProcessEnv {
12    #[turbo_tasks::function]
13    pub fn new() -> Vc<Self> {
14        CommandLineProcessEnv.cell()
15    }
16}
17
18/// Clones the current env vars into a FxIndexMap.
19fn env_snapshot() -> FxIndexMap<RcStr, RcStr> {
20    let _lock = GLOBAL_ENV_LOCK.lock().unwrap();
21    sorted_env_vars()
22}
23
24#[turbo_tasks::value_impl]
25impl ProcessEnv for CommandLineProcessEnv {
26    #[turbo_tasks::function]
27    fn read_all(&self) -> Vc<EnvMap> {
28        mark_session_dependent();
29        Vc::cell(env_snapshot())
30    }
31}