Skip to content

Commit

Permalink
Fix doctests not running with --target=HOST.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Jun 15, 2020
1 parent c83cdc6 commit cc3af70
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ pub struct Compilation<'cfg> {
/// Flags to pass to rustdoc when invoked from cargo test, per package.
pub rustdocflags: HashMap<PackageId, Vec<String>>,

/// The target host triple.
pub host: String,

config: &'cfg Config,

/// Rustc process to be used by default
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 12 additions & 4 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ fn run_doc_tests(
compilation: &Compilation<'_>,
) -> CargoResult<(Test, Vec<ProcessError>)> {
let mut errors = Vec::new();
let doctest_xcompile = config.cli_unstable().doctest_xcompile;

for doctest_info in &compilation.to_doc_test {
let Doctest {
Expand All @@ -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())?;
Expand All @@ -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());
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cross_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
))
Expand Down

0 comments on commit cc3af70

Please sign in to comment.