From 1bf67a04023e91d72b9ed573651f0fc6c484b150 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 13 Jun 2020 20:56:29 -0700 Subject: [PATCH] Fix doctests not running with --target=HOST. --- src/cargo/core/compiler/compilation.rs | 4 ++++ src/cargo/ops/cargo_test.rs | 16 ++++++++++++---- tests/testsuite/cross_compile.rs | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index b8fb670c299..2738baa2503 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -66,6 +66,9 @@ pub struct Compilation<'cfg> { /// Flags to pass to rustdoc when invoked from cargo test, per package. pub rustdocflags: HashMap>, + /// The target host triple. + pub host: String, + config: &'cfg Config, /// Rustc process to be used by default @@ -123,6 +126,7 @@ impl<'cfg> Compilation<'cfg> { cfgs: HashMap::new(), rustdocflags: HashMap::new(), config: bcx.config, + host: bcx.host_triple().to_string(), rustc_process: rustc, rustc_workspace_wrapper_process, primary_rustc_process, diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index af7c5983ffc..e82827d09a9 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -137,6 +137,7 @@ fn run_doc_tests( compilation: &Compilation<'_>, ) -> CargoResult<(Test, Vec)> { let mut errors = Vec::new(); + let doctest_xcompile = config.cli_unstable().doctest_xcompile; for doctest_info in &compilation.to_doc_test { let Doctest { @@ -145,9 +146,16 @@ fn run_doc_tests( unit, } = doctest_info; - // Skip any `--target` tests unless `doctest-xcompile` is specified. - if !config.cli_unstable().doctest_xcompile && !unit.kind.is_host() { - continue; + if !doctest_xcompile { + match unit.kind { + CompileKind::Host => {} + CompileKind::Target(target) => { + if target.short_name() != compilation.host { + // Skip doctests, -Zdoctest-xcompile not enabled. + continue; + } + } + } } config.shell().status("Doc-tests", unit.target.name())?; @@ -157,7 +165,7 @@ fn run_doc_tests( .arg("--crate-name") .arg(&unit.target.crate_name()); - if config.cli_unstable().doctest_xcompile { + if doctest_xcompile { if let CompileKind::Target(target) = unit.kind { // use `rustc_target()` to properly handle JSON target paths p.arg("--target").arg(target.rustc_target()); diff --git a/tests/testsuite/cross_compile.rs b/tests/testsuite/cross_compile.rs index 14dbd7f0cfd..a781729a7b0 100644 --- a/tests/testsuite/cross_compile.rs +++ b/tests/testsuite/cross_compile.rs @@ -396,6 +396,7 @@ fn no_cross_doctests() { [COMPILING] foo v0.0.1 ([CWD]) [FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/{triple}/debug/deps/foo-[..][EXE] +[DOCTEST] foo ", triple = target ))