@@ -213,7 +213,7 @@ use super::job::{
213213 Freshness :: { Dirty , Fresh } ,
214214 Job , Work ,
215215} ;
216- use super :: { BuildContext , Context , FileFlavor , Kind , Unit } ;
216+ use super :: { BuildContext , Context , FileFlavor , Unit } ;
217217
218218/// Determines if a `unit` is up-to-date, and if not prepares necessary work to
219219/// update the persisted fingerprint.
@@ -1014,7 +1014,7 @@ fn calculate<'a, 'cfg>(
10141014
10151015 // After we built the initial `Fingerprint` be sure to update the
10161016 // `fs_status` field of it.
1017- let target_root = target_root ( cx, unit ) ;
1017+ let target_root = target_root ( cx) ;
10181018 fingerprint. check_filesystem ( unit. pkg . root ( ) , & target_root) ?;
10191019
10201020 let fingerprint = Arc :: new ( fingerprint) ;
@@ -1046,7 +1046,7 @@ fn calculate_normal<'a, 'cfg>(
10461046 // correctly, but otherwise upstream packages like from crates.io or git
10471047 // get bland fingerprints because they don't change without their
10481048 // `PackageId` changing.
1049- let target_root = target_root ( cx, unit ) ;
1049+ let target_root = target_root ( cx) ;
10501050 let local = if use_dep_info ( unit) {
10511051 let dep_info = dep_info_loc ( cx, unit) ;
10521052 let dep_info = dep_info. strip_prefix ( & target_root) . unwrap ( ) . to_path_buf ( ) ;
@@ -1219,8 +1219,8 @@ fn build_script_local_fingerprints<'a, 'cfg>(
12191219 // package. Remember that the fact that this is an `Option` is a bug, but a
12201220 // longstanding bug, in Cargo. Recent refactorings just made it painfully
12211221 // obvious.
1222- let script_root = cx. files ( ) . build_script_run_dir ( unit) ;
12231222 let pkg_root = unit. pkg . root ( ) . to_path_buf ( ) ;
1223+ let target_dir = target_root ( cx) ;
12241224 let calculate =
12251225 move |deps : & BuildDeps , pkg_fingerprint : Option < & dyn Fn ( ) -> CargoResult < String > > | {
12261226 if deps. rerun_if_changed . is_empty ( ) && deps. rerun_if_env_changed . is_empty ( ) {
@@ -1247,7 +1247,7 @@ fn build_script_local_fingerprints<'a, 'cfg>(
12471247 // Ok so now we're in "new mode" where we can have files listed as
12481248 // dependencies as well as env vars listed as dependencies. Process
12491249 // them all here.
1250- Ok ( Some ( local_fingerprints_deps ( deps, & script_root , & pkg_root) ) )
1250+ Ok ( Some ( local_fingerprints_deps ( deps, & target_dir , & pkg_root) ) )
12511251 } ;
12521252
12531253 // Note that `false` == "not overridden"
@@ -1346,17 +1346,10 @@ pub fn dep_info_loc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> Pa
13461346 . join ( & format ! ( "dep-{}" , filename( cx, unit) ) )
13471347}
13481348
1349- /// Returns an absolute path that the `unit`'s outputs should always be relative
1350- /// to. This `target_root` variable is used to store relative path names in
1351- /// `Fingerprint` instead of absolute pathnames (see module comment).
1352- fn target_root < ' a , ' cfg > ( cx : & mut Context < ' a , ' cfg > , unit : & Unit < ' a > ) -> PathBuf {
1353- if unit. mode . is_run_custom_build ( ) {
1354- cx. files ( ) . build_script_run_dir ( unit)
1355- } else if unit. kind == Kind :: Host {
1356- cx. files ( ) . host_root ( ) . to_path_buf ( )
1357- } else {
1358- cx. files ( ) . target_root ( ) . to_path_buf ( )
1359- }
1349+ /// Returns an absolute path that target directory.
1350+ /// All paths are rewritten to be relative to this.
1351+ fn target_root ( cx : & Context < ' _ , ' _ > ) -> PathBuf {
1352+ cx. bcx . ws . target_dir ( ) . into_path_unlocked ( )
13601353}
13611354
13621355fn compare_old_fingerprint (
@@ -1565,10 +1558,10 @@ pub fn translate_dep_info(
15651558 let mut new_contents = Vec :: new ( ) ;
15661559 for file in deps {
15671560 let file = rustc_cwd. join ( file) ;
1568- let ( ty, path) = if let Ok ( stripped) = file. strip_prefix ( pkg_root) {
1569- ( DepInfoPathType :: PackageRootRelative , stripped)
1570- } else if let Ok ( stripped) = file. strip_prefix ( target_root) {
1561+ let ( ty, path) = if let Ok ( stripped) = file. strip_prefix ( target_root) {
15711562 ( DepInfoPathType :: TargetRootRelative , stripped)
1563+ } else if let Ok ( stripped) = file. strip_prefix ( pkg_root) {
1564+ ( DepInfoPathType :: PackageRootRelative , stripped)
15721565 } else {
15731566 // It's definitely not target root relative, but this is an absolute path (since it was
15741567 // joined to rustc_cwd) and as such re-joining it later to the target root will have no
0 commit comments