Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix add_plugin_deps-related tests. #6327

Merged
merged 1 commit into from
Nov 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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