Skip to content

Commit

Permalink
Auto merge of #6327 - ehuss:add_plugin_deps-tests, r=alexcrichton
Browse files Browse the repository at this point in the history
Fix add_plugin_deps-related tests.

These tests were modified in #3974 in such a way that they stopped testing the `add_plugin_deps` code path. The tests can't be directly reverted because #3651 changed it so that dylib paths must be within the root output directory. I compromised by just copying the dylib into `$OUT_DIR`.

Closes #6318.
  • Loading branch information
bors committed Nov 18, 2018
2 parents ebd0ef1 + 83ff57a commit 3468918
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 45 deletions.
34 changes: 17 additions & 17 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,18 +1376,8 @@ fn test_dev_dep_build_script() {

#[test]
fn build_script_with_dynamic_native_dependency() {
let _workspace = project()
.at("ws")
.file(
"Cargo.toml",
r#"
[workspace]
members = ["builder", "foo"]
"#,
).build();

let build = project()
.at("ws/builder")
.at("builder")
.file(
"Cargo.toml",
r#"
Expand All @@ -1399,13 +1389,11 @@ fn build_script_with_dynamic_native_dependency() {
[lib]
name = "builder"
crate-type = ["dylib"]
plugin = true
"#,
).file("src/lib.rs", "#[no_mangle] pub extern fn foo() {}")
.build();

let foo = project()
.at("ws/foo")
.file(
"Cargo.toml",
r#"
Expand Down Expand Up @@ -1433,12 +1421,23 @@ fn build_script_with_dynamic_native_dependency() {
"bar/build.rs",
r#"
use std::env;
use std::fs;
use std::path::PathBuf;
fn main() {
let src = PathBuf::from(env::var("SRC").unwrap());
println!("cargo:rustc-link-search=native={}/target/debug/deps",
src.display());
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let root = PathBuf::from(env::var("BUILDER_ROOT").unwrap());
let file = format!("{}builder{}",
env::consts::DLL_PREFIX,
env::consts::DLL_SUFFIX);
let src = root.join(&file);
let dst = out_dir.join(&file);
fs::copy(src, dst).unwrap();
if cfg!(windows) {
fs::copy(root.join("builder.dll.lib"),
out_dir.join("builder.dll.lib")).unwrap();
}
println!("cargo:rustc-link-search=native={}", out_dir.display());
}
"#,
).file(
Expand All @@ -1458,8 +1457,9 @@ fn build_script_with_dynamic_native_dependency() {
.env("RUST_LOG", "cargo::ops::cargo_rustc")
.run();

let root = build.root().join("target").join("debug");
foo.cargo("build -v")
.env("SRC", build.root())
.env("BUILDER_ROOT", root)
.env("RUST_LOG", "cargo::ops::cargo_rustc")
.run();
}
Expand Down
46 changes: 18 additions & 28 deletions tests/testsuite/plugins.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use std::env;
use std::fs;

use support::{basic_manifest, project};
use support::{is_nightly, rustc_host};

Expand Down Expand Up @@ -103,18 +100,8 @@ fn plugin_with_dynamic_native_dependency() {
return;
}

let workspace = project()
.at("ws")
.file(
"Cargo.toml",
r#"
[workspace]
members = ["builder", "foo"]
"#,
).build();

let build = project()
.at("ws/builder")
.at("builder")
.file(
"Cargo.toml",
r#"
Expand All @@ -131,7 +118,6 @@ fn plugin_with_dynamic_native_dependency() {
.build();

let foo = project()
.at("ws/foo")
.file(
"Cargo.toml",
r#"
Expand Down Expand Up @@ -167,12 +153,24 @@ fn plugin_with_dynamic_native_dependency() {
).file(
"bar/build.rs",
r#"
use std::path::PathBuf;
use std::env;
use std::fs;
use std::path::PathBuf;
fn main() {
let src = PathBuf::from(env::var("SRC").unwrap());
println!("cargo:rustc-flags=-L {}/deps", src.parent().unwrap().display());
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let root = PathBuf::from(env::var("BUILDER_ROOT").unwrap());
let file = format!("{}builder{}",
env::consts::DLL_PREFIX,
env::consts::DLL_SUFFIX);
let src = root.join(&file);
let dst = out_dir.join(&file);
fs::copy(src, dst).unwrap();
if cfg!(windows) {
fs::copy(root.join("builder.dll.lib"),
out_dir.join("builder.dll.lib")).unwrap();
}
println!("cargo:rustc-flags=-L {}", out_dir.display());
}
"#,
).file(
Expand All @@ -196,16 +194,8 @@ fn plugin_with_dynamic_native_dependency() {

build.cargo("build").run();

let src = workspace.root().join("target/debug");
let lib = fs::read_dir(&src)
.unwrap()
.map(|s| s.unwrap().path())
.find(|lib| {
let lib = lib.file_name().unwrap().to_str().unwrap();
lib.starts_with(env::consts::DLL_PREFIX) && lib.ends_with(env::consts::DLL_SUFFIX)
}).unwrap();

foo.cargo("build -v").env("SRC", &lib).run();
let root = build.root().join("target").join("debug");
foo.cargo("build -v").env("BUILDER_ROOT", root).run();
}

#[test]
Expand Down

0 comments on commit 3468918

Please sign in to comment.