-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add host dependency path via -L for cargo_test. #4447
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
Changes from 1 commit
2b7f37b
3b5ec88
a5d8298
95c6e68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,6 +126,7 @@ fn run_doc_tests(options: &TestOptions, | |
| -> CargoResult<(Test, Vec<ProcessError>)> { | ||
| let mut errors = Vec::new(); | ||
| let config = options.compile_opts.config; | ||
| let host_deps = find_host_deps(options, compilation); | ||
|
|
||
| // We don't build/rust doctests if target != host | ||
| if config.rustc()?.host != compilation.target { | ||
|
|
@@ -144,6 +145,8 @@ fn run_doc_tests(options: &TestOptions, | |
| p.arg("--test").arg(lib) | ||
| .arg("--crate-name").arg(&crate_name); | ||
|
|
||
| p.arg("-L").arg(&host_deps); | ||
|
|
||
| for &rust_dep in &[&compilation.deps_output] { | ||
| let mut arg = OsString::from("dependency="); | ||
| arg.push(rust_dep); | ||
|
|
@@ -198,3 +201,24 @@ fn run_doc_tests(options: &TestOptions, | |
| } | ||
| Ok((Test::Doc, errors)) | ||
| } | ||
|
|
||
| fn find_host_deps(options: &TestOptions, compilation: &Compilation) -> OsString { | ||
|
||
| let build_type = if options.compile_opts.release { "release" } else { "debug" }; | ||
| let mut dir = compilation.root_output.clone(); | ||
|
|
||
| // first pop off the build_type | ||
| dir.pop(); | ||
| // if we see the target next, pop it off | ||
| let target: &OsStr = compilation.target.as_ref(); | ||
| if dir.file_name().unwrap() == target { | ||
| dir.pop(); | ||
| } | ||
| // push the build_type back on | ||
| dir.push(build_type); | ||
| // and we are looking for the deps directory | ||
| dir.push("deps"); | ||
|
|
||
| let mut host_deps = OsString::from("dependency="); | ||
| host_deps.push(dir); | ||
| host_deps | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ use std::fs::File; | |
| use std::io::prelude::*; | ||
| use std::str; | ||
|
|
||
| use cargotest::{sleep_ms, is_nightly}; | ||
| use cargotest::{sleep_ms, is_nightly, rustc_host}; | ||
| use cargotest::support::{project, execs, basic_bin_manifest, basic_lib_manifest, cargo_exe}; | ||
| use cargotest::support::paths::CargoPathExt; | ||
| use cargotest::support::registry::Package; | ||
|
|
@@ -2782,3 +2782,53 @@ fn publish_a_crate_without_tests() { | |
| assert_that(p.cargo("test").arg("--package").arg("testless"), | ||
| execs().with_status(0)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn find_dependency_of_proc_macro_dependency_with_target() { | ||
| let workspace = project("workspace") | ||
| .file("Cargo.toml", r#" | ||
| [workspace] | ||
| members = ["root", "proc_macro_dep"] | ||
| "#) | ||
| .file("root/Cargo.toml", r#" | ||
| [project] | ||
| name = "root" | ||
| version = "0.1.0" | ||
| authors = [] | ||
|
|
||
| [dependencies] | ||
| proc_macro_dep = { path = "../proc_macro_dep" } | ||
| "#) | ||
| .file("root/src/lib.rs", r#" | ||
| #[macro_use] | ||
| extern crate proc_macro_dep; | ||
|
|
||
| #[derive(Noop)] | ||
| pub struct X; | ||
| "#) | ||
| .file("proc_macro_dep/Cargo.toml", r#" | ||
| [project] | ||
| name = "proc_macro_dep" | ||
| version = "0.1.0" | ||
| authors = [] | ||
|
|
||
| [lib] | ||
| proc-macro = true | ||
|
|
||
| [dependencies] | ||
| base64 = "^0.6" | ||
|
||
| "#) | ||
| .file("proc_macro_dep/src/lib.rs", r#" | ||
| extern crate base64; | ||
| extern crate proc_macro; | ||
| use proc_macro::TokenStream; | ||
|
|
||
| #[proc_macro_derive(Noop)] | ||
| pub fn noop(_input: TokenStream) -> TokenStream { | ||
| "".parse().unwrap() | ||
| } | ||
| "#); | ||
| workspace.build(); | ||
| assert_that(workspace.cargo("test").arg("--all").arg("--target").arg(rustc_host()), | ||
| execs().with_status(0)); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It occurred to me that this line may need to be further down to put the host directory after the others? Does the ordering of the
-Loptions mean this is buggy despite passing tests?