From 2db502f766bb6c928ab1189a0a30a1150e089b7c Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 17 Jun 2021 18:28:42 -0700 Subject: [PATCH] Fix dep-info files including non-local build script paths. --- src/cargo/core/compiler/output_depinfo.rs | 2 +- tests/testsuite/dep_info.rs | 38 +++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/compiler/output_depinfo.rs b/src/cargo/core/compiler/output_depinfo.rs index b55dd8fa530..01136017dec 100644 --- a/src/cargo/core/compiler/output_depinfo.rs +++ b/src/cargo/core/compiler/output_depinfo.rs @@ -92,7 +92,7 @@ fn add_deps_for_unit( // Recursively traverse all transitive dependencies let unit_deps = Vec::from(cx.unit_deps(unit)); // Create vec due to mutable borrow. for dep in unit_deps { - if unit.is_local() { + if dep.unit.is_local() { add_deps_for_unit(deps, cx, &dep.unit, visited)?; } } diff --git a/tests/testsuite/dep_info.rs b/tests/testsuite/dep_info.rs index e6dcb550f3b..ae385b13781 100644 --- a/tests/testsuite/dep_info.rs +++ b/tests/testsuite/dep_info.rs @@ -1,6 +1,7 @@ //! Tests for dep-info files. This includes the dep-info file Cargo creates in //! the output directory, and the ones stored in the fingerprint. +use cargo_test_support::compare::assert_match_exact; use cargo_test_support::paths::{self, CargoPathExt}; use cargo_test_support::registry::Package; use cargo_test_support::{ @@ -575,3 +576,40 @@ fn canonical_path() { &[(0, "src/lib.rs"), (1, "debug/deps/libregdep-*.rmeta")], ); } + +#[cargo_test] +fn non_local_build_script() { + // Non-local build script information is not included. + Package::new("bar", "1.0.0") + .file( + "build.rs", + r#" + fn main() { + println!("cargo:rerun-if-changed=build.rs"); + } + "#, + ) + .file("src/lib.rs", "") + .publish(); + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + + [dependencies] + bar = "1.0" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("build").run(); + let contents = p.read_file("target/debug/foo.d"); + assert_match_exact( + "[ROOT]/foo/target/debug/foo[EXE]: [ROOT]/foo/src/main.rs", + &contents, + ); +}