From f9f62ff2b9138dc1e61534063aeadd455034cba7 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Sat, 11 Apr 2020 11:33:58 +0200 Subject: [PATCH 01/10] fix target --- src/cargo/ops/cargo_test.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index e142d831fe4..0d9b7baf995 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -1,6 +1,6 @@ use std::ffi::OsString; -use crate::core::compiler::{Compilation, Doctest}; +use crate::core::compiler::{Compilation, CompileKind, Doctest}; use crate::core::shell::Verbosity; use crate::core::Workspace; use crate::ops; @@ -163,7 +163,9 @@ fn run_doc_tests( .arg(&target.crate_name()); if doctest_xcompile { - p.arg("--target").arg(&compilation.target); + if let CompileKind::Target(target) = options.compile_opts.build_config.requested_kind { + p.arg("--target").arg(target.rustc_target()); + } p.arg("-Zunstable-options"); p.arg("--enable-per-target-ignores"); } From 5a051ebe08d51c0188a4c3bbb41789c0d4cb0f82 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Sun, 12 Apr 2020 17:49:05 +0200 Subject: [PATCH 02/10] remove host & target attributes --- src/cargo/core/compiler/compilation.rs | 5 ----- src/cargo/ops/cargo_test.rs | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index 58a6c39d2da..b270aa39352 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -69,9 +69,6 @@ pub struct Compilation<'cfg> { /// Flags to pass to rustdoc when invoked from cargo test, per package. pub rustdocflags: HashMap>, - pub host: String, - pub target: String, - config: &'cfg Config, /// Rustc process to be used by default @@ -129,8 +126,6 @@ impl<'cfg> Compilation<'cfg> { rustc_process: rustc, rustc_workspace_wrapper_process, primary_rustc_process, - host: bcx.host_triple().to_string(), - target: bcx.target_data.short_name(&default_kind).to_string(), target_runner: target_runner(bcx, default_kind)?, }) } diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 0d9b7baf995..e320c3a9fdc 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -144,7 +144,7 @@ fn run_doc_tests( let mut runtool: &Option<(std::path::PathBuf, Vec)> = &None; if doctest_xcompile { runtool = compilation.target_runner(); - } else if compilation.host != compilation.target { + } else if options.compile_opts.build_config.requested_kind.is_host() { return Ok((Test::Doc, errors)); } From 060c5e13e123683bce605c420bff95b2205fd131 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Tue, 14 Apr 2020 16:41:18 +0200 Subject: [PATCH 03/10] fix running doctest for host target --- src/cargo/ops/cargo_test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index e320c3a9fdc..40d93607dc2 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -144,7 +144,7 @@ fn run_doc_tests( let mut runtool: &Option<(std::path::PathBuf, Vec)> = &None; if doctest_xcompile { runtool = compilation.target_runner(); - } else if options.compile_opts.build_config.requested_kind.is_host() { + } else if !options.compile_opts.build_config.requested_kind.is_host() { return Ok((Test::Doc, errors)); } From b365b0fa060eed8df83d5ec32111e1f7936224ac Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Wed, 15 Apr 2020 12:51:22 +0200 Subject: [PATCH 04/10] Revert "fix running doctest for host target" This reverts commit 060c5e13e123683bce605c420bff95b2205fd131. --- src/cargo/ops/cargo_test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 40d93607dc2..e320c3a9fdc 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -144,7 +144,7 @@ fn run_doc_tests( let mut runtool: &Option<(std::path::PathBuf, Vec)> = &None; if doctest_xcompile { runtool = compilation.target_runner(); - } else if !options.compile_opts.build_config.requested_kind.is_host() { + } else if options.compile_opts.build_config.requested_kind.is_host() { return Ok((Test::Doc, errors)); } From 86d857ec584178e8ad3b527ba0de73448f99b402 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Wed, 15 Apr 2020 12:51:37 +0200 Subject: [PATCH 05/10] Revert "remove host & target attributes" This reverts commit 5a051ebe08d51c0188a4c3bbb41789c0d4cb0f82. --- src/cargo/core/compiler/compilation.rs | 5 +++++ src/cargo/ops/cargo_test.rs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index b270aa39352..58a6c39d2da 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -69,6 +69,9 @@ pub struct Compilation<'cfg> { /// Flags to pass to rustdoc when invoked from cargo test, per package. pub rustdocflags: HashMap>, + pub host: String, + pub target: String, + config: &'cfg Config, /// Rustc process to be used by default @@ -126,6 +129,8 @@ impl<'cfg> Compilation<'cfg> { rustc_process: rustc, rustc_workspace_wrapper_process, primary_rustc_process, + host: bcx.host_triple().to_string(), + target: bcx.target_data.short_name(&default_kind).to_string(), target_runner: target_runner(bcx, default_kind)?, }) } diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index e320c3a9fdc..0d9b7baf995 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -144,7 +144,7 @@ fn run_doc_tests( let mut runtool: &Option<(std::path::PathBuf, Vec)> = &None; if doctest_xcompile { runtool = compilation.target_runner(); - } else if options.compile_opts.build_config.requested_kind.is_host() { + } else if compilation.host != compilation.target { return Ok((Test::Doc, errors)); } From ecffdcc2b025ac8fdccb4462567da3809eaef389 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Thu, 16 Apr 2020 11:35:38 +0200 Subject: [PATCH 06/10] add clarifying comment --- src/cargo/ops/cargo_test.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 0d9b7baf995..ff71d0b1aa9 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -164,6 +164,7 @@ fn run_doc_tests( if doctest_xcompile { if let CompileKind::Target(target) = options.compile_opts.build_config.requested_kind { + // use `rustc_target()` to properly handle JSON target paths p.arg("--target").arg(target.rustc_target()); } p.arg("-Zunstable-options"); From 60a61d471a30a2d5943225b8b6e4041729b81167 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Thu, 16 Apr 2020 11:48:12 +0200 Subject: [PATCH 07/10] add tests for doctests with cross compilation --- tests/testsuite/cross_compile.rs | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/testsuite/cross_compile.rs b/tests/testsuite/cross_compile.rs index a781729a7b0..569dc7604b6 100644 --- a/tests/testsuite/cross_compile.rs +++ b/tests/testsuite/cross_compile.rs @@ -437,6 +437,42 @@ fn no_cross_doctests() { .run(); } +#[cargo_test] +fn cross_doctests() { + if cross_compile::disabled() || !cross_compile::can_run_on_host() || !is_nightly() { + return; + } + + let p = project() + .file( + "src/lib.rs", + r#" + //! ``` + //! extern crate foo; + //! assert!(true); + //! ``` + "#, + ) + .build(); + + let target = cross_compile::alternate(); + + // This tests the library and runs the doc tests. + p.cargo("test -v -Z doctest-xcompile --target") + .arg(&target) + .with_stderr(&format!( + "\ +[COMPILING] foo v0.0.1 ([CWD]) +[RUNNING] `rustc --crate-name foo [..]--test[..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] +[RUNNING] `[CWD]/target/{triple}/debug/deps/foo-[..][EXE]` +[DOCTEST] foo +", + triple = target + )) + .run(); +} + #[cargo_test] fn simple_cargo_run() { if !cross_compile::can_run_on_host() { From 6fc37f5611a61f73525fa7e88d2873e15a19d0f0 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Thu, 16 Apr 2020 12:07:15 +0200 Subject: [PATCH 08/10] make test use nightly --- tests/testsuite/cross_compile.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testsuite/cross_compile.rs b/tests/testsuite/cross_compile.rs index 569dc7604b6..fbe1645f9a0 100644 --- a/tests/testsuite/cross_compile.rs +++ b/tests/testsuite/cross_compile.rs @@ -460,6 +460,7 @@ fn cross_doctests() { // This tests the library and runs the doc tests. p.cargo("test -v -Z doctest-xcompile --target") .arg(&target) + .masquerade_as_nightly_cargo() .with_stderr(&format!( "\ [COMPILING] foo v0.0.1 ([CWD]) From 4785b6464255eadd0042b9d2e75cb120ec2dfb51 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Thu, 16 Apr 2020 13:08:00 +0200 Subject: [PATCH 09/10] fix test --- tests/testsuite/cross_compile.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testsuite/cross_compile.rs b/tests/testsuite/cross_compile.rs index fbe1645f9a0..3b234a7645d 100644 --- a/tests/testsuite/cross_compile.rs +++ b/tests/testsuite/cross_compile.rs @@ -464,10 +464,12 @@ fn cross_doctests() { .with_stderr(&format!( "\ [COMPILING] foo v0.0.1 ([CWD]) +[RUNNING] `rustc --crate-name foo [..] [RUNNING] `rustc --crate-name foo [..]--test[..] [FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] `[CWD]/target/{triple}/debug/deps/foo-[..][EXE]` [DOCTEST] foo +[RUNNING] `rustdoc [..] ", triple = target )) From e5d9b034ec7e4a2513f0f7600139a0b81274406f Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Fri, 17 Apr 2020 17:35:10 +0200 Subject: [PATCH 10/10] add test for doctests with custom target paths --- tests/testsuite/cross_compile.rs | 39 -------------------------------- tests/testsuite/custom_target.rs | 6 +++++ 2 files changed, 6 insertions(+), 39 deletions(-) diff --git a/tests/testsuite/cross_compile.rs b/tests/testsuite/cross_compile.rs index 3b234a7645d..a781729a7b0 100644 --- a/tests/testsuite/cross_compile.rs +++ b/tests/testsuite/cross_compile.rs @@ -437,45 +437,6 @@ fn no_cross_doctests() { .run(); } -#[cargo_test] -fn cross_doctests() { - if cross_compile::disabled() || !cross_compile::can_run_on_host() || !is_nightly() { - return; - } - - let p = project() - .file( - "src/lib.rs", - r#" - //! ``` - //! extern crate foo; - //! assert!(true); - //! ``` - "#, - ) - .build(); - - let target = cross_compile::alternate(); - - // This tests the library and runs the doc tests. - p.cargo("test -v -Z doctest-xcompile --target") - .arg(&target) - .masquerade_as_nightly_cargo() - .with_stderr(&format!( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[RUNNING] `rustc --crate-name foo [..] -[RUNNING] `rustc --crate-name foo [..]--test[..] -[FINISHED] test [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `[CWD]/target/{triple}/debug/deps/foo-[..][EXE]` -[DOCTEST] foo -[RUNNING] `rustdoc [..] -", - triple = target - )) - .run(); -} - #[cargo_test] fn simple_cargo_run() { if !cross_compile::can_run_on_host() { diff --git a/tests/testsuite/custom_target.rs b/tests/testsuite/custom_target.rs index 3970bc8d43f..75aba8a9976 100644 --- a/tests/testsuite/custom_target.rs +++ b/tests/testsuite/custom_target.rs @@ -51,6 +51,12 @@ fn custom_target_minimal() { p.cargo("build --lib --target custom-target.json -v").run(); p.cargo("build --lib --target src/../custom-target.json -v") .run(); + + // Ensure that the correct style of flag is passed to --target with doc tests. + p.cargo("test --doc --target src/../custom-target.json -v -Zdoctest-xcompile") + .masquerade_as_nightly_cargo() + .with_stderr_contains("[RUNNING] `rustdoc [..]--target [..]foo/custom-target.json[..]") + .run(); } #[cargo_test]