@@ -357,7 +357,9 @@ mod dirty_reason;
357
357
358
358
use std:: collections:: hash_map:: { Entry , HashMap } ;
359
359
360
+ use std:: collections:: BTreeMap ;
360
361
use std:: env;
362
+ use std:: ffi:: OsString ;
361
363
use std:: hash:: { self , Hash , Hasher } ;
362
364
use std:: io;
363
365
use std:: path:: { Path , PathBuf } ;
@@ -772,10 +774,18 @@ impl LocalFingerprint {
772
774
// TODO: This is allowed at this moment. Should figure out if it makes
773
775
// sense if permitting to read env from the config system.
774
776
#[ allow( clippy:: disallowed_methods) ]
775
- fn from_env < K : AsRef < str > > ( key : K ) -> LocalFingerprint {
777
+ fn from_env < K : AsRef < str > > (
778
+ key : K ,
779
+ envs : & BTreeMap < String , Option < OsString > > ,
780
+ ) -> LocalFingerprint {
776
781
let key = key. as_ref ( ) ;
777
782
let var = key. to_owned ( ) ;
778
- let val = env:: var ( key) . ok ( ) ;
783
+ let val = envs
784
+ . get ( key)
785
+ . map ( |v| v. to_owned ( ) )
786
+ . or_else ( || Some ( env:: var_os ( key) ) )
787
+ . and_then ( |os_str| os_str?. into_string ( ) . ok ( ) ) ;
788
+
779
789
LocalFingerprint :: RerunIfEnvChanged { var, val }
780
790
}
781
791
@@ -1608,6 +1618,12 @@ fn build_script_local_fingerprints(
1608
1618
bool ,
1609
1619
) {
1610
1620
assert ! ( unit. mode. is_run_custom_build( ) ) ;
1621
+ let envs = build_runner
1622
+ . bcx
1623
+ . target_data
1624
+ . info ( unit. kind )
1625
+ . get_target_envs ( )
1626
+ . clone ( ) ;
1611
1627
// First up, if this build script is entirely overridden, then we just
1612
1628
// return the hash of what we overrode it with. This is the easy case!
1613
1629
if let Some ( fingerprint) = build_script_override_fingerprint ( build_runner, unit) {
@@ -1660,7 +1676,12 @@ fn build_script_local_fingerprints(
1660
1676
// Ok so now we're in "new mode" where we can have files listed as
1661
1677
// dependencies as well as env vars listed as dependencies. Process
1662
1678
// them all here.
1663
- Ok ( Some ( local_fingerprints_deps ( deps, & target_dir, & pkg_root) ) )
1679
+ Ok ( Some ( local_fingerprints_deps (
1680
+ deps,
1681
+ & target_dir,
1682
+ & pkg_root,
1683
+ & envs,
1684
+ ) ) )
1664
1685
} ;
1665
1686
1666
1687
// Note that `false` == "not overridden"
@@ -1695,6 +1716,7 @@ fn local_fingerprints_deps(
1695
1716
deps : & BuildDeps ,
1696
1717
target_root : & Path ,
1697
1718
pkg_root : & Path ,
1719
+ envs : & BTreeMap < String , Option < OsString > > ,
1698
1720
) -> Vec < LocalFingerprint > {
1699
1721
debug ! ( "new local fingerprints deps {:?}" , pkg_root) ;
1700
1722
let mut local = Vec :: new ( ) ;
@@ -1719,7 +1741,7 @@ fn local_fingerprints_deps(
1719
1741
local. extend (
1720
1742
deps. rerun_if_env_changed
1721
1743
. iter ( )
1722
- . map ( LocalFingerprint :: from_env) ,
1744
+ . map ( |v| LocalFingerprint :: from_env ( v , & envs ) ) ,
1723
1745
) ;
1724
1746
1725
1747
local
0 commit comments