@@ -63,7 +63,7 @@ use std::io::SeekFrom;
63
63
use std:: mem;
64
64
use std:: path:: { Path , PathBuf } ;
65
65
use std:: str:: FromStr ;
66
- use std:: sync:: Once ;
66
+ use std:: sync:: { Arc , Once } ;
67
67
use std:: time:: Instant ;
68
68
69
69
use self :: ConfigValue as CV ;
@@ -227,7 +227,7 @@ pub struct GlobalContext {
227
227
target_cfgs : LazyCell < Vec < ( String , TargetCfgConfig ) > > ,
228
228
doc_extern_map : LazyCell < RustdocExternMap > ,
229
229
progress_config : ProgressConfig ,
230
- env_config : LazyCell < EnvConfig > ,
230
+ env_config : LazyCell < Arc < HashMap < String , OsString > > > ,
231
231
/// This should be false if:
232
232
/// - this is an artifact of the rustc distribution process for "stable" or for "beta"
233
233
/// - this is an `#[test]` that does not opt in with `enable_nightly_features`
@@ -1833,34 +1833,47 @@ impl GlobalContext {
1833
1833
& self . progress_config
1834
1834
}
1835
1835
1836
- pub fn env_config ( & self ) -> CargoResult < & EnvConfig > {
1837
- let env_config = self
1838
- . env_config
1839
- . try_borrow_with ( || self . get :: < EnvConfig > ( "env" ) ) ?;
1840
-
1841
- // Reasons for disallowing these values:
1842
- //
1843
- // - CARGO_HOME: The initial call to cargo does not honor this value
1844
- // from the [env] table. Recursive calls to cargo would use the new
1845
- // value, possibly behaving differently from the outer cargo.
1846
- //
1847
- // - RUSTUP_HOME and RUSTUP_TOOLCHAIN: Under normal usage with rustup,
1848
- // this will have no effect because the rustup proxy sets
1849
- // RUSTUP_HOME and RUSTUP_TOOLCHAIN, and that would override the
1850
- // [env] table. If the outer cargo is executed directly
1851
- // circumventing the rustup proxy, then this would affect calls to
1852
- // rustc (assuming that is a proxy), which could potentially cause
1853
- // problems with cargo and rustc being from different toolchains. We
1854
- // consider this to be not a use case we would like to support,
1855
- // since it will likely cause problems or lead to confusion.
1856
- for disallowed in & [ "CARGO_HOME" , "RUSTUP_HOME" , "RUSTUP_TOOLCHAIN" ] {
1857
- if env_config. contains_key ( * disallowed) {
1858
- bail ! (
1859
- "setting the `{disallowed}` environment variable is not supported \
1860
- in the `[env]` configuration table"
1861
- ) ;
1862
- }
1863
- }
1836
+ /// Get the env vars from the config `[env]` table which
1837
+ /// are `force = true` or don't exist in the env snapshot [`GlobalContext::get_env`].
1838
+ pub fn env_config ( & self ) -> CargoResult < & Arc < HashMap < String , OsString > > > {
1839
+ let env_config = self . env_config . try_borrow_with ( || {
1840
+ CargoResult :: Ok ( Arc :: new ( {
1841
+ let env_config = self . get :: < EnvConfig > ( "env" ) ?;
1842
+ // Reasons for disallowing these values:
1843
+ //
1844
+ // - CARGO_HOME: The initial call to cargo does not honor this value
1845
+ // from the [env] table. Recursive calls to cargo would use the new
1846
+ // value, possibly behaving differently from the outer cargo.
1847
+ //
1848
+ // - RUSTUP_HOME and RUSTUP_TOOLCHAIN: Under normal usage with rustup,
1849
+ // this will have no effect because the rustup proxy sets
1850
+ // RUSTUP_HOME and RUSTUP_TOOLCHAIN, and that would override the
1851
+ // [env] table. If the outer cargo is executed directly
1852
+ // circumventing the rustup proxy, then this would affect calls to
1853
+ // rustc (assuming that is a proxy), which could potentially cause
1854
+ // problems with cargo and rustc being from different toolchains. We
1855
+ // consider this to be not a use case we would like to support,
1856
+ // since it will likely cause problems or lead to confusion.
1857
+ for disallowed in & [ "CARGO_HOME" , "RUSTUP_HOME" , "RUSTUP_TOOLCHAIN" ] {
1858
+ if env_config. contains_key ( * disallowed) {
1859
+ bail ! (
1860
+ "setting the `{disallowed}` environment variable is not supported \
1861
+ in the `[env]` configuration table"
1862
+ ) ;
1863
+ }
1864
+ }
1865
+ env_config
1866
+ . into_iter ( )
1867
+ . filter_map ( |( k, v) | {
1868
+ if v. is_force ( ) || self . get_env_os ( & k) . is_none ( ) {
1869
+ Some ( ( k, v. resolve ( self ) . to_os_string ( ) ) )
1870
+ } else {
1871
+ None
1872
+ }
1873
+ } )
1874
+ . collect ( )
1875
+ } ) )
1876
+ } ) ?;
1864
1877
1865
1878
Ok ( env_config)
1866
1879
}
0 commit comments