Skip to content

Commit aa99e9f

Browse files
committed
Fix some issues with absolute paths in dep-info files.
1 parent 5251d92 commit aa99e9f

File tree

5 files changed

+379
-67
lines changed

5 files changed

+379
-67
lines changed

src/cargo/core/compiler/fingerprint.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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

13621355
fn 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

src/cargo/core/compiler/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ fn rustc<'a, 'cfg>(
223223
let exec = exec.clone();
224224

225225
let root_output = cx.files().host_root().to_path_buf();
226+
let target_dir = cx.bcx.ws.target_dir().into_path_unlocked();
226227
let pkg_root = unit.pkg.root().to_path_buf();
227228
let cwd = rustc
228229
.get_cwd()
@@ -317,7 +318,7 @@ fn rustc<'a, 'cfg>(
317318
&dep_info_loc,
318319
&cwd,
319320
&pkg_root,
320-
&root_output,
321+
&target_dir,
321322
)
322323
.chain_err(|| {
323324
internal(format!(

0 commit comments

Comments
 (0)