Skip to content

Commit

Permalink
Output complete repro command when failing to generate rustdoc JSON.
Browse files Browse the repository at this point in the history
Resolves #570 by making it more likely that users are able to resolve the build error on their own, instead of being confused about why cargo-semver-checks is failing to build their project.
  • Loading branch information
obi1kenobi committed Feb 28, 2024
1 parent cd913df commit 80b3aa1
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/rustdoc_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,29 @@ impl RustdocCommand {
)?;
writeln!(
stderr,
"note: running the following command on the crate should reproduce the error:"
"note: the following command can be used to reproduce the compilation error:"
)?;

let selector = match crate_source {
CrateSource::Registry { version, .. } => format!("{crate_name}@={version}"),
CrateSource::ManifestPath { manifest } => format!(
"--path {}",
manifest
.path
.parent()
.expect("source Cargo.toml had no parent path")
.to_str()
.expect("failed to create path string")
),
};
let feature_list = features.into_iter().join(",");
writeln!(
stderr,
" cargo build --no-default-features --features {}\n",
features.into_iter().join(","),
" \
cargo new --lib example &&
cd example &&
echo '[workspace]' >> Cargo.toml &&
cargo add {selector} --no-default-features --features {feature_list} &&
cargo check\n"
)?;
Ok(())
})?;
Expand Down

0 comments on commit 80b3aa1

Please sign in to comment.