@@ -357,7 +357,9 @@ mod dirty_reason;
357357
358358use std:: collections:: hash_map:: { Entry , HashMap } ;
359359
360+ use std:: collections:: BTreeMap ;
360361use std:: env;
362+ use std:: ffi:: OsString ;
361363use std:: hash:: { self , Hash , Hasher } ;
362364use std:: io;
363365use std:: path:: { Path , PathBuf } ;
@@ -772,10 +774,21 @@ impl LocalFingerprint {
772774 // TODO: This is allowed at this moment. Should figure out if it makes
773775 // sense if permitting to read env from the config system.
774776 #[ 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 {
776781 let key = key. as_ref ( ) ;
777782 let var = key. to_owned ( ) ;
778- let val = env:: var ( key) . ok ( ) ;
783+
784+ let val = envs
785+ . get ( key)
786+ . and_then ( |opt| {
787+ opt. as_ref ( )
788+ . and_then ( |os_str| os_str. clone ( ) . into_string ( ) . ok ( ) )
789+ } )
790+ . or_else ( || env:: var ( key) . ok ( ) ) ;
791+
779792 LocalFingerprint :: RerunIfEnvChanged { var, val }
780793 }
781794
@@ -1608,6 +1621,13 @@ fn build_script_local_fingerprints(
16081621 bool ,
16091622) {
16101623 assert ! ( unit. mode. is_run_custom_build( ) ) ;
1624+ let envs = build_runner
1625+ . bcx
1626+ . target_data
1627+ . info ( unit. kind )
1628+ . get_target_envs ( )
1629+ . unwrap ( )
1630+ . clone ( ) ;
16111631 // First up, if this build script is entirely overridden, then we just
16121632 // return the hash of what we overrode it with. This is the easy case!
16131633 if let Some ( fingerprint) = build_script_override_fingerprint ( build_runner, unit) {
@@ -1660,7 +1680,12 @@ fn build_script_local_fingerprints(
16601680 // Ok so now we're in "new mode" where we can have files listed as
16611681 // dependencies as well as env vars listed as dependencies. Process
16621682 // them all here.
1663- Ok ( Some ( local_fingerprints_deps ( deps, & target_dir, & pkg_root) ) )
1683+ Ok ( Some ( local_fingerprints_deps (
1684+ deps,
1685+ & target_dir,
1686+ & pkg_root,
1687+ & envs,
1688+ ) ) )
16641689 } ;
16651690
16661691 // Note that `false` == "not overridden"
@@ -1695,6 +1720,7 @@ fn local_fingerprints_deps(
16951720 deps : & BuildDeps ,
16961721 target_root : & Path ,
16971722 pkg_root : & Path ,
1723+ envs : & BTreeMap < String , Option < OsString > > ,
16981724) -> Vec < LocalFingerprint > {
16991725 debug ! ( "new local fingerprints deps {:?}" , pkg_root) ;
17001726 let mut local = Vec :: new ( ) ;
@@ -1719,7 +1745,7 @@ fn local_fingerprints_deps(
17191745 local. extend (
17201746 deps. rerun_if_env_changed
17211747 . iter ( )
1722- . map ( LocalFingerprint :: from_env) ,
1748+ . map ( |v| LocalFingerprint :: from_env ( v , & envs ) ) ,
17231749 ) ;
17241750
17251751 local
0 commit comments