Skip to content

Commit c111cad

Browse files
committed
Auto merge of #9596 - ehuss:fix-dep-info-local, r=alexcrichton
Fix dep-info files including non-local build script paths. I derped in #8177 and accidentally used the wrong unit when iterating over the dependencies when writing the `.d` file. The consequence here is that all the `rerun-if-changed` paths from a unit's dependencies are included in the `.d` file. This fixes it so that it does not include non-local dependencies. Fixes #9445
2 parents e343f81 + 2db502f commit c111cad

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/cargo/core/compiler/output_depinfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn add_deps_for_unit(
9292
// Recursively traverse all transitive dependencies
9393
let unit_deps = Vec::from(cx.unit_deps(unit)); // Create vec due to mutable borrow.
9494
for dep in unit_deps {
95-
if unit.is_local() {
95+
if dep.unit.is_local() {
9696
add_deps_for_unit(deps, cx, &dep.unit, visited)?;
9797
}
9898
}

tests/testsuite/dep_info.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Tests for dep-info files. This includes the dep-info file Cargo creates in
22
//! the output directory, and the ones stored in the fingerprint.
33
4+
use cargo_test_support::compare::assert_match_exact;
45
use cargo_test_support::paths::{self, CargoPathExt};
56
use cargo_test_support::registry::Package;
67
use cargo_test_support::{
@@ -575,3 +576,40 @@ fn canonical_path() {
575576
&[(0, "src/lib.rs"), (1, "debug/deps/libregdep-*.rmeta")],
576577
);
577578
}
579+
580+
#[cargo_test]
581+
fn non_local_build_script() {
582+
// Non-local build script information is not included.
583+
Package::new("bar", "1.0.0")
584+
.file(
585+
"build.rs",
586+
r#"
587+
fn main() {
588+
println!("cargo:rerun-if-changed=build.rs");
589+
}
590+
"#,
591+
)
592+
.file("src/lib.rs", "")
593+
.publish();
594+
let p = project()
595+
.file(
596+
"Cargo.toml",
597+
r#"
598+
[package]
599+
name = "foo"
600+
version = "0.1.0"
601+
602+
[dependencies]
603+
bar = "1.0"
604+
"#,
605+
)
606+
.file("src/main.rs", "fn main() {}")
607+
.build();
608+
609+
p.cargo("build").run();
610+
let contents = p.read_file("target/debug/foo.d");
611+
assert_match_exact(
612+
"[ROOT]/foo/target/debug/foo[EXE]: [ROOT]/foo/src/main.rs",
613+
&contents,
614+
);
615+
}

0 commit comments

Comments
 (0)