From 80b3aa1513a9b28dfd7dbf3fe57bd05e327bbc30 Mon Sep 17 00:00:00 2001 From: Predrag Gruevski Date: Wed, 28 Feb 2024 15:07:23 +0000 Subject: [PATCH] Output complete repro command when failing to generate rustdoc JSON. 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. --- src/rustdoc_cmd.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/rustdoc_cmd.rs b/src/rustdoc_cmd.rs index 597e32ae..1101577d 100644 --- a/src/rustdoc_cmd.rs +++ b/src/rustdoc_cmd.rs @@ -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(()) })?;