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 doctests not running with --target=HOST. #8358

Merged
merged 1 commit into from
Jun 15, 2020
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
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