From 8ec3f6ad7d033f8a76beb18cbcc27b275e11c19a Mon Sep 17 00:00:00 2001 From: Michael Fairley Date: Tue, 28 Nov 2017 23:31:34 -0400 Subject: [PATCH] Allow metadata hash to be computed when checking dylibs --- src/cargo/ops/cargo_rustc/context.rs | 2 +- tests/check.rs | 40 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 9e3696787..44b6cbb9a 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -535,7 +535,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { // just here for rustbuild. We need a more principled method // doing this eventually. let __cargo_default_lib_metadata = env::var("__CARGO_DEFAULT_LIB_METADATA"); - if !unit.profile.test && + if !(unit.profile.test || unit.profile.check) && (unit.target.is_dylib() || unit.target.is_cdylib() || (unit.target.is_bin() && self.target_triple().starts_with("wasm32-"))) && unit.pkg.package_id().source_id().is_path() && diff --git a/tests/check.rs b/tests/check.rs index 073ee3186..68e1615ec 100644 --- a/tests/check.rs +++ b/tests/check.rs @@ -1,3 +1,4 @@ +#[macro_use] extern crate cargotest; extern crate hamcrest; extern crate glob; @@ -298,6 +299,45 @@ fn issue_3419() { execs().with_status(0)); } +// Check on a dylib should have a different metadata hash than build. +#[test] +fn check_dylib() { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.1.0" + authors = [] + + [lib] + crate-type = ["dylib"] + + [dependencies] + "#) + .file("src/lib.rs", "") + .build(); + + let build_output = t!(String::from_utf8( + t!(p.cargo("build").arg("-v").exec_with_output()) + .stderr, + )); + let build_metadata = build_output + .split_whitespace() + .find(|arg| arg.starts_with("metadata=")) + .unwrap(); + + let check_output = t!(String::from_utf8( + t!(p.cargo("check").arg("-v").exec_with_output()) + .stderr, + )); + let check_metadata = check_output + .split_whitespace() + .find(|arg| arg.starts_with("metadata=")) + .unwrap(); + + assert_ne!(build_metadata, check_metadata); +} + // test `cargo rustc --profile check` #[test] fn rustc_check() { -- 2.39.5