From e1a4558915c81c1a592bc0baf38ae9a8d3265cfc Mon Sep 17 00:00:00 2001 From: Martijn Gribnau Date: Sat, 19 Oct 2024 04:22:19 +0200 Subject: [PATCH 1/4] Support cargo-msrv show within a Cargo workspace --- src/sub_command/show.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sub_command/show.rs b/src/sub_command/show.rs index de316ad4..d9c1b97f 100644 --- a/src/sub_command/show.rs +++ b/src/sub_command/show.rs @@ -23,6 +23,8 @@ impl SubCommand for Show { } fn show_msrv(ctx: &ShowContext, reporter: &impl Reporter) -> TResult<()> { + // TODO: Add support for workspaces, but take care to also still support raw `rustup run`. + let cargo_toml = ctx.environment.manifest(); let metadata = MetadataCommand::new().manifest_path(&cargo_toml).exec()?; From b5037d6d7ac540337af9d271c8d3530e2c4c4da0 Mon Sep 17 00:00:00 2001 From: Martijn Date: Sun, 20 Oct 2024 00:38:46 +0200 Subject: [PATCH 2/4] Group rust release / toolchain modules together --- src/check.rs | 4 ++-- src/check/rustup_toolchain_check.rs | 10 +++++----- src/check/testing.rs | 8 ++++---- src/context.rs | 2 +- src/lib.rs | 17 ++++++----------- src/msrv.rs | 8 ++++---- src/outcome.rs | 18 +++++++++--------- src/reporter/event/check_method.rs | 8 ++++---- src/reporter/event/check_result.rs | 12 ++++++------ src/reporter/event/check_toolchain.rs | 8 ++++---- src/reporter/event/setup_toolchain.rs | 8 ++++---- src/reporter/event/shared/compatibility.rs | 10 +++++----- src/reporter/event/types/verify_result.rs | 12 ++++++------ src/reporter/ui/json/testing/verify.rs | 14 +++++++------- src/reporter/ui/minimal.rs | 8 ++++---- src/{ => rust}/default_target.rs | 0 src/rust/mod.rs | 9 +++++++++ src/{rust_release.rs => rust/release.rs} | 14 +++++++------- src/{ => rust}/release_index.rs | 0 src/{ => rust}/releases_filter.rs | 0 src/{ => rust}/setup_toolchain.rs | 12 ++++++------ src/{ => rust}/toolchain.rs | 18 +++++++++--------- src/search_method.rs | 2 +- src/search_method/bisect.rs | 4 ++-- src/search_method/linear.rs | 8 ++++---- src/sub_command/find.rs | 4 ++-- src/sub_command/verify.rs | 8 ++++---- tests/common/runner.rs | 8 ++++---- 28 files changed, 119 insertions(+), 115 deletions(-) rename src/{ => rust}/default_target.rs (100%) create mode 100644 src/rust/mod.rs rename src/{rust_release.rs => rust/release.rs} (79%) rename src/{ => rust}/release_index.rs (100%) rename src/{ => rust}/releases_filter.rs (100%) rename src/{ => rust}/setup_toolchain.rs (92%) rename src/{ => rust}/toolchain.rs (83%) diff --git a/src/check.rs b/src/check.rs index 68d1d2b4..143ccb61 100644 --- a/src/check.rs +++ b/src/check.rs @@ -1,4 +1,4 @@ -use crate::toolchain::ToolchainSpec; +use crate::rust::Toolchain; mod rustup_toolchain_check; #[cfg(test)] @@ -11,5 +11,5 @@ pub use rustup_toolchain_check::{RunCommand, RustupToolchainCheck}; pub use testing::TestRunner; pub trait Check { - fn check(&self, toolchain: &ToolchainSpec) -> TResult; + fn check(&self, toolchain: &Toolchain) -> TResult; } diff --git a/src/check/rustup_toolchain_check.rs b/src/check/rustup_toolchain_check.rs index 2cf0d0ea..87a46508 100644 --- a/src/check/rustup_toolchain_check.rs +++ b/src/check/rustup_toolchain_check.rs @@ -5,8 +5,8 @@ use crate::external_command::cargo_command::CargoCommand; use crate::external_command::rustup_command::RustupCommand; use crate::lockfile::LockfileHandler; use crate::reporter::event::{CheckMethod, CheckResult, CheckToolchain, Method}; -use crate::setup_toolchain::{SetupRustupToolchain, SetupToolchain}; -use crate::toolchain::ToolchainSpec; +use crate::rust::setup_toolchain::{SetupRustupToolchain, SetupToolchain}; +use crate::rust::Toolchain; use crate::{lockfile, CargoMSRVError, Outcome, Reporter, TResult}; use camino::{Utf8Path, Utf8PathBuf}; use std::fmt; @@ -38,7 +38,7 @@ impl<'reporter, 'env, R: Reporter> RustupToolchainCheck<'reporter, 'env, R> { } impl<'reporter, 'env, R: Reporter> Check for RustupToolchainCheck<'reporter, 'env, R> { - fn check(&self, toolchain: &ToolchainSpec) -> TResult { + fn check(&self, toolchain: &Toolchain) -> TResult { let settings = &self.settings; self.reporter @@ -86,7 +86,7 @@ impl fmt::Debug for RustupToolchainCheck<'_, '_, R> { } } -fn setup_toolchain(reporter: &impl Reporter, toolchain: &ToolchainSpec) -> TResult<()> { +fn setup_toolchain(reporter: &impl Reporter, toolchain: &Toolchain) -> TResult<()> { let downloader = SetupRustupToolchain::new(reporter); downloader.download(toolchain)?; @@ -95,7 +95,7 @@ fn setup_toolchain(reporter: &impl Reporter, toolchain: &ToolchainSpec) -> TResu fn run_check_command_via_rustup( reporter: &impl Reporter, - toolchain: &ToolchainSpec, + toolchain: &Toolchain, dir: &Utf8Path, check: &[String], ) -> TResult { diff --git a/src/check/testing.rs b/src/check/testing.rs index 41fde1cf..3cab172e 100644 --- a/src/check/testing.rs +++ b/src/check/testing.rs @@ -1,7 +1,7 @@ use crate::check::Check; use crate::outcome::Outcome; +use crate::rust::Toolchain; use crate::semver::Version; -use crate::toolchain::ToolchainSpec; use crate::TResult; use std::collections::HashSet; @@ -20,18 +20,18 @@ impl TestRunner { } impl Check for TestRunner { - fn check(&self, toolchain: &ToolchainSpec) -> TResult { + fn check(&self, toolchain: &Toolchain) -> TResult { let v = toolchain.version(); if self.accept_versions.contains(toolchain.version()) { - Ok(Outcome::new_success(ToolchainSpec::new( + Ok(Outcome::new_success(Toolchain::new( v.clone(), self.target, &[], ))) } else { Ok(Outcome::new_failure( - ToolchainSpec::new(v.clone(), self.target, &[]), + Toolchain::new(v.clone(), self.target, &[]), "f".to_string(), )) } diff --git a/src/context.rs b/src/context.rs index b7405361..a3c81fb3 100644 --- a/src/context.rs +++ b/src/context.rs @@ -28,9 +28,9 @@ pub mod verify; use crate::cli::custom_check_opts::CustomCheckOpts; use crate::cli::rust_releases_opts::Edition; use crate::cli::{CargoMsrvOpts, SubCommand}; -use crate::default_target::default_target; use crate::log_level::LogLevel; use crate::reporter::event::SelectedPackage; +use crate::rust::default_target::default_target; pub use find::FindContext; pub use list::ListContext; pub use set::SetContext; diff --git a/src/lib.rs b/src/lib.rs index f647c0e7..1b1bb473 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,31 +29,26 @@ use crate::context::ReleaseSource; use crate::error::{CargoMSRVError, TResult}; use crate::reporter::event::{Meta, SelectedPackages, SubcommandInit}; use crate::reporter::{Event, Reporter}; +use rust::release_index; use rust_releases::semver; pub mod check; pub mod cli; -pub mod error; -pub mod exit_code; -pub mod io; -pub mod reporter; -pub mod toolchain; - mod context; -pub(crate) mod default_target; pub(crate) mod dependency_graph; +pub mod error; +pub mod exit_code; mod external_command; +pub mod io; pub(crate) mod lockfile; pub(crate) mod log_level; pub(crate) mod manifest; pub(crate) mod msrv; pub(crate) mod outcome; -mod release_index; -pub(crate) mod releases_filter; -mod rust_release; +pub mod reporter; +pub mod rust; pub(crate) mod search_method; -pub(crate) mod setup_toolchain; pub(crate) mod sub_command; pub(crate) mod typed_bool; pub(crate) mod writer; diff --git a/src/msrv.rs b/src/msrv.rs index 04459d20..2a5288fd 100644 --- a/src/msrv.rs +++ b/src/msrv.rs @@ -1,5 +1,5 @@ -use crate::rust_release::RustRelease; -use crate::toolchain::ToolchainSpec; +use crate::rust::RustRelease; +use crate::rust::Toolchain; /// An enum to represent the minimal compatibility #[derive(Clone, Debug, Eq, PartialEq)] @@ -7,7 +7,7 @@ pub enum MinimumSupportedRustVersion { /// A toolchain is compatible, if the outcome of a toolchain check results in a success Toolchain { // toolchain - toolchain: ToolchainSpec, + toolchain: Toolchain, }, /// Compatibility is none, if the check on the last available toolchain fails NoCompatibleToolchain, @@ -42,7 +42,7 @@ impl MinimumSupportedRustVersion { #[cfg(test)] mod tests { use crate::msrv::MinimumSupportedRustVersion; - use crate::rust_release::RustRelease; + use crate::rust::RustRelease; use cargo_metadata::semver; #[test] diff --git a/src/outcome.rs b/src/outcome.rs index 49939547..38cf4203 100644 --- a/src/outcome.rs +++ b/src/outcome.rs @@ -2,7 +2,7 @@ //! //! [`check`]: crate::check::Check -use crate::toolchain::ToolchainSpec; +use crate::rust::Toolchain; use rust_releases::semver; #[derive(Clone, Debug)] @@ -12,11 +12,11 @@ pub enum Outcome { } impl Outcome { - pub fn new_success(toolchain_spec: ToolchainSpec) -> Self { + pub fn new_success(toolchain_spec: Toolchain) -> Self { Self::Success(SuccessOutcome { toolchain_spec }) } - pub fn new_failure(toolchain_spec: ToolchainSpec, error_message: String) -> Self { + pub fn new_failure(toolchain_spec: Toolchain, error_message: String) -> Self { Self::Failure(FailureOutcome { toolchain_spec, error_message, @@ -37,7 +37,7 @@ impl Outcome { } } - pub fn toolchain_spec(&self) -> &ToolchainSpec { + pub fn toolchain_spec(&self) -> &Toolchain { match self { Self::Success(outcome) => &outcome.toolchain_spec, Self::Failure(outcome) => &outcome.toolchain_spec, @@ -47,25 +47,25 @@ impl Outcome { #[derive(Clone, Debug, Eq, PartialEq)] pub struct SuccessOutcome { - pub(crate) toolchain_spec: ToolchainSpec, + pub(crate) toolchain_spec: Toolchain, } #[derive(Clone, Debug, Eq, PartialEq)] pub struct FailureOutcome { - pub(crate) toolchain_spec: ToolchainSpec, + pub(crate) toolchain_spec: Toolchain, pub(crate) error_message: String, } #[cfg(test)] mod tests { - use crate::toolchain::ToolchainSpec; + use crate::rust::Toolchain; use crate::Outcome; use rust_releases::semver; #[test] fn success_outcome() { let version = semver::Version::new(1, 2, 3); - let toolchain = ToolchainSpec::new(version, "x", &[]); + let toolchain = Toolchain::new(version, "x", &[]); let outcome = Outcome::new_success(toolchain.clone()); @@ -77,7 +77,7 @@ mod tests { #[test] fn failure_outcome() { let version = semver::Version::new(1, 2, 3); - let toolchain = ToolchainSpec::new(version, "x", &[]); + let toolchain = Toolchain::new(version, "x", &[]); let outcome = Outcome::new_failure(toolchain.clone(), "msg".to_string()); diff --git a/src/reporter/event/check_method.rs b/src/reporter/event/check_method.rs index 17f177d8..e0350fb0 100644 --- a/src/reporter/event/check_method.rs +++ b/src/reporter/event/check_method.rs @@ -1,17 +1,17 @@ use crate::reporter::event::Message; -use crate::toolchain::ToolchainSpec; +use crate::rust::Toolchain; use crate::Event; use camino::{Utf8Path, Utf8PathBuf}; #[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)] #[serde(rename_all = "snake_case")] pub struct CheckMethod { - toolchain: ToolchainSpec, + toolchain: Toolchain, method: Method, } impl CheckMethod { - pub fn new(toolchain: impl Into, method: Method) -> Self { + pub fn new(toolchain: impl Into, method: Method) -> Self { Self { toolchain: toolchain.into(), method, @@ -65,7 +65,7 @@ mod tests { fn reported_event(method: Method) { let reporter = TestReporterWrapper::default(); let event = CheckMethod::new( - ToolchainSpec::new(semver::Version::new(1, 2, 3), "test_target", &[]), + Toolchain::new(semver::Version::new(1, 2, 3), "test_target", &[]), method, ); diff --git a/src/reporter/event/check_result.rs b/src/reporter/event/check_result.rs index f9c15692..8e9c94e0 100644 --- a/src/reporter/event/check_result.rs +++ b/src/reporter/event/check_result.rs @@ -1,6 +1,6 @@ use crate::reporter::event::shared::compatibility::Compatibility; use crate::reporter::event::Message; -use crate::toolchain::ToolchainSpec; +use crate::rust::Toolchain; use crate::Event; #[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)] @@ -11,19 +11,19 @@ pub struct CheckResult { } impl CheckResult { - pub fn compatible(toolchain: impl Into) -> Self { + pub fn compatible(toolchain: impl Into) -> Self { Self { compatibility: Compatibility::compatible(toolchain), } } - pub fn incompatible(toolchain: impl Into, error: Option) -> Self { + pub fn incompatible(toolchain: impl Into, error: Option) -> Self { Self { compatibility: Compatibility::incompatible(toolchain, error), } } - pub fn toolchain(&self) -> &ToolchainSpec { + pub fn toolchain(&self) -> &Toolchain { self.compatibility.toolchain() } @@ -49,7 +49,7 @@ mod tests { #[test] fn reported_compatible_toolchain() { let reporter = TestReporterWrapper::default(); - let event = CheckResult::compatible(ToolchainSpec::new( + let event = CheckResult::compatible(Toolchain::new( semver::Version::new(1, 2, 3), "test_target", &[], @@ -70,7 +70,7 @@ mod tests { fn reported_incompatible_toolchain(error_message: Option) { let reporter = TestReporterWrapper::default(); let event = CheckResult::incompatible( - ToolchainSpec::new(semver::Version::new(1, 2, 3), "test_target", &[]), + Toolchain::new(semver::Version::new(1, 2, 3), "test_target", &[]), error_message, ); diff --git a/src/reporter/event/check_toolchain.rs b/src/reporter/event/check_toolchain.rs index 9e4194f1..138492b3 100644 --- a/src/reporter/event/check_toolchain.rs +++ b/src/reporter/event/check_toolchain.rs @@ -1,15 +1,15 @@ use crate::reporter::event::Message; -use crate::toolchain::ToolchainSpec; +use crate::rust::Toolchain; use crate::Event; #[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)] #[serde(rename_all = "snake_case")] pub struct CheckToolchain { - pub toolchain: ToolchainSpec, + pub toolchain: Toolchain, } impl CheckToolchain { - pub fn new(toolchain: impl Into) -> Self { + pub fn new(toolchain: impl Into) -> Self { Self { toolchain: toolchain.into(), } @@ -33,7 +33,7 @@ mod tests { #[test] fn reported_event() { let reporter = TestReporterWrapper::default(); - let event = CheckToolchain::new(ToolchainSpec::new( + let event = CheckToolchain::new(Toolchain::new( semver::Version::new(1, 2, 3), "test_target", &[], diff --git a/src/reporter/event/setup_toolchain.rs b/src/reporter/event/setup_toolchain.rs index fab6be2b..a521ec51 100644 --- a/src/reporter/event/setup_toolchain.rs +++ b/src/reporter/event/setup_toolchain.rs @@ -1,15 +1,15 @@ use crate::reporter::event::Message; -use crate::toolchain::ToolchainSpec; +use crate::rust::Toolchain; use crate::Event; #[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)] #[serde(rename_all = "snake_case")] pub struct SetupToolchain { - toolchain: ToolchainSpec, + toolchain: Toolchain, } impl SetupToolchain { - pub fn new(toolchain: impl Into) -> Self { + pub fn new(toolchain: impl Into) -> Self { Self { toolchain: toolchain.into(), } @@ -33,7 +33,7 @@ mod tests { #[test] fn reported_event() { let reporter = TestReporterWrapper::default(); - let event = SetupToolchain::new(ToolchainSpec::new( + let event = SetupToolchain::new(Toolchain::new( semver::Version::new(1, 2, 3), "test_target", &[], diff --git a/src/reporter/event/shared/compatibility.rs b/src/reporter/event/shared/compatibility.rs index 6a30d128..d68486d8 100644 --- a/src/reporter/event/shared/compatibility.rs +++ b/src/reporter/event/shared/compatibility.rs @@ -1,4 +1,4 @@ -use crate::toolchain::ToolchainSpec; +use crate::rust::Toolchain; /// Reports whether a crate is compatible with a certain toolchain, or not. /// If it's not compatible, it may specify a reason why it is not compatible. @@ -6,14 +6,14 @@ use crate::toolchain::ToolchainSpec; #[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)] #[serde(rename_all = "snake_case")] pub struct Compatibility { - toolchain: ToolchainSpec, + toolchain: Toolchain, is_compatible: bool, #[serde(skip_serializing_if = "Option::is_none")] error: Option, } impl Compatibility { - pub fn compatible(toolchain: impl Into) -> Self { + pub fn compatible(toolchain: impl Into) -> Self { Self { toolchain: toolchain.into(), is_compatible: true, @@ -21,7 +21,7 @@ impl Compatibility { } } - pub fn incompatible(toolchain: impl Into, error: Option) -> Self { + pub fn incompatible(toolchain: impl Into, error: Option) -> Self { Self { toolchain: toolchain.into(), is_compatible: false, @@ -29,7 +29,7 @@ impl Compatibility { } } - pub fn toolchain(&self) -> &ToolchainSpec { + pub fn toolchain(&self) -> &Toolchain { &self.toolchain } diff --git a/src/reporter/event/types/verify_result.rs b/src/reporter/event/types/verify_result.rs index b733f7a0..fd5bcd2d 100644 --- a/src/reporter/event/types/verify_result.rs +++ b/src/reporter/event/types/verify_result.rs @@ -1,7 +1,7 @@ use crate::reporter::event::shared::compatibility::Compatibility; use crate::reporter::event::subcommand_result::SubcommandResult; use crate::reporter::event::Message; -use crate::toolchain::ToolchainSpec; +use crate::rust::Toolchain; use crate::Event; #[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)] @@ -11,19 +11,19 @@ pub struct VerifyResult { } impl VerifyResult { - pub fn compatible(toolchain: impl Into) -> Self { + pub fn compatible(toolchain: impl Into) -> Self { Self { result: Compatibility::compatible(toolchain), } } - pub fn incompatible(toolchain: impl Into, error: Option) -> Self { + pub fn incompatible(toolchain: impl Into, error: Option) -> Self { Self { result: Compatibility::incompatible(toolchain, error), } } - pub fn toolchain(&self) -> &ToolchainSpec { + pub fn toolchain(&self) -> &Toolchain { self.result.toolchain() } @@ -55,7 +55,7 @@ mod tests { #[test] fn reported_compatible_toolchain() { let reporter = TestReporterWrapper::default(); - let event = VerifyResult::compatible(ToolchainSpec::new( + let event = VerifyResult::compatible(Toolchain::new( semver::Version::new(1, 2, 3), "test_target", &[], @@ -78,7 +78,7 @@ mod tests { fn reported_incompatible_toolchain(error_message: Option) { let reporter = TestReporterWrapper::default(); let event = VerifyResult::incompatible( - ToolchainSpec::new(semver::Version::new(1, 2, 3), "test_target", &[]), + Toolchain::new(semver::Version::new(1, 2, 3), "test_target", &[]), error_message, ); diff --git a/src/reporter/ui/json/testing/verify.rs b/src/reporter/ui/json/testing/verify.rs index f85f8052..b4f77030 100644 --- a/src/reporter/ui/json/testing/verify.rs +++ b/src/reporter/ui/json/testing/verify.rs @@ -1,12 +1,12 @@ use crate::reporter::event::VerifyResult; use crate::reporter::JsonHandler; +use crate::rust::Toolchain; use crate::semver; -use crate::toolchain::ToolchainSpec; use storyteller::EventHandler; #[test] fn handler_success() { - let event = VerifyResult::compatible(ToolchainSpec::new( + let event = VerifyResult::compatible(Toolchain::new( semver::Version::new(1, 2, 3), "my-target", &[], @@ -37,7 +37,7 @@ fn handler_success() { #[test] fn event_success() { - let event = VerifyResult::compatible(ToolchainSpec::new( + let event = VerifyResult::compatible(Toolchain::new( semver::Version::new(1, 2, 3), "my-target", &[], @@ -61,7 +61,7 @@ fn event_success() { #[test] fn handler_failure_with_message() { let event = VerifyResult::incompatible( - ToolchainSpec::new(semver::Version::new(1, 2, 3), "my-target", &[]), + Toolchain::new(semver::Version::new(1, 2, 3), "my-target", &[]), Some("Hello World".to_string()), ); @@ -92,7 +92,7 @@ fn handler_failure_with_message() { #[test] fn event_failure_with_message() { let event = VerifyResult::incompatible( - ToolchainSpec::new(semver::Version::new(1, 2, 3), "my-target", &[]), + Toolchain::new(semver::Version::new(1, 2, 3), "my-target", &[]), Some("Hello World".to_string()), ); @@ -115,7 +115,7 @@ fn event_failure_with_message() { #[test] fn handler_failure_without_message() { let event = VerifyResult::incompatible( - ToolchainSpec::new(semver::Version::new(1, 2, 3), "my-target", &[]), + Toolchain::new(semver::Version::new(1, 2, 3), "my-target", &[]), None, ); @@ -145,7 +145,7 @@ fn handler_failure_without_message() { #[test] fn event_failure_without_message() { let event = VerifyResult::incompatible( - ToolchainSpec::new(semver::Version::new(1, 2, 3), "my-target", &[]), + Toolchain::new(semver::Version::new(1, 2, 3), "my-target", &[]), None, ); diff --git a/src/reporter/ui/minimal.rs b/src/reporter/ui/minimal.rs index 2083bf56..a9c51ce0 100644 --- a/src/reporter/ui/minimal.rs +++ b/src/reporter/ui/minimal.rs @@ -111,8 +111,8 @@ mod tests { FindResult, ListResult, Progress, SetResult, ShowResult, VerifyResult, }; use crate::reporter::ui::minimal::MinimalOutputHandler; + use crate::rust::Toolchain; use crate::semver; - use crate::toolchain::ToolchainSpec; use camino::Utf8Path; use cargo_metadata::PackageId; use storyteller::EventHandler; @@ -232,7 +232,7 @@ mod tests { #[test] fn verify_true() { - let event = VerifyResult::compatible(ToolchainSpec::new( + let event = VerifyResult::compatible(Toolchain::new( semver::Version::new(1, 2, 3), "test_target", &[], @@ -255,7 +255,7 @@ mod tests { #[test] fn verify_false_no_error_message() { let event = VerifyResult::incompatible( - ToolchainSpec::new(semver::Version::new(1, 2, 3), "test_target", &[]), + Toolchain::new(semver::Version::new(1, 2, 3), "test_target", &[]), None, ); @@ -276,7 +276,7 @@ mod tests { #[test] fn verify_false_with_error_message() { let event = VerifyResult::incompatible( - ToolchainSpec::new(semver::Version::new(1, 2, 3), "test_target", &[]), + Toolchain::new(semver::Version::new(1, 2, 3), "test_target", &[]), Some("error message".to_string()), ); diff --git a/src/default_target.rs b/src/rust/default_target.rs similarity index 100% rename from src/default_target.rs rename to src/rust/default_target.rs diff --git a/src/rust/mod.rs b/src/rust/mod.rs new file mode 100644 index 00000000..58149bec --- /dev/null +++ b/src/rust/mod.rs @@ -0,0 +1,9 @@ +pub(crate) mod default_target; +mod release; +pub mod release_index; +pub(crate) mod releases_filter; +pub(crate) mod setup_toolchain; +mod toolchain; + +pub use release::RustRelease; +pub use toolchain::Toolchain; diff --git a/src/rust_release.rs b/src/rust/release.rs similarity index 79% rename from src/rust_release.rs rename to src/rust/release.rs index ea439196..60921d8e 100644 --- a/src/rust_release.rs +++ b/src/rust/release.rs @@ -1,4 +1,4 @@ -use crate::toolchain::ToolchainSpec; +use crate::rust::Toolchain; /// A `cargo-msrv` Rust release. /// @@ -26,17 +26,17 @@ impl RustRelease { } } - /// Get the [`ToolchainSpec`] for the given Rust release. - pub fn to_toolchain_spec(&self) -> ToolchainSpec { + /// Get the [`Toolchain`] for the given Rust release. + pub fn to_toolchain_spec(&self) -> Toolchain { let version = self.release.version(); - ToolchainSpec::new(version.clone(), self.target, self.components) + Toolchain::new(version.clone(), self.target, self.components) } } #[cfg(test)] mod tests { - use crate::rust_release::RustRelease; - use crate::toolchain::ToolchainSpec; + use crate::rust::RustRelease; + use crate::rust::Toolchain; use rust_releases::semver; #[test] @@ -49,7 +49,7 @@ mod tests { ); let spec = rust_release.to_toolchain_spec(); - let expected = ToolchainSpec::new(version, "x", &[]); + let expected = Toolchain::new(version, "x", &[]); assert_eq!(spec, expected); } } diff --git a/src/release_index.rs b/src/rust/release_index.rs similarity index 100% rename from src/release_index.rs rename to src/rust/release_index.rs diff --git a/src/releases_filter.rs b/src/rust/releases_filter.rs similarity index 100% rename from src/releases_filter.rs rename to src/rust/releases_filter.rs diff --git a/src/setup_toolchain.rs b/src/rust/setup_toolchain.rs similarity index 92% rename from src/setup_toolchain.rs rename to src/rust/setup_toolchain.rs index dc4335f1..ac6d2cd4 100644 --- a/src/setup_toolchain.rs +++ b/src/rust/setup_toolchain.rs @@ -3,11 +3,11 @@ use crate::error::{ }; use crate::external_command::rustup_command::RustupCommand; use crate::reporter::event::SetupToolchain as SetupToolchainEvent; -use crate::toolchain::ToolchainSpec; +use crate::rust::Toolchain; use crate::{CargoMSRVError, Reporter, TResult}; pub trait SetupToolchain { - fn download(&self, toolchain: &ToolchainSpec) -> TResult<()>; + fn download(&self, toolchain: &Toolchain) -> TResult<()>; } #[derive(Debug)] @@ -23,7 +23,7 @@ impl<'reporter, R: Reporter> SetupRustupToolchain<'reporter, R> { impl<'reporter, R: Reporter> SetupToolchain for SetupRustupToolchain<'reporter, R> { #[instrument(skip(self, toolchain))] - fn download(&self, toolchain: &ToolchainSpec) -> TResult<()> { + fn download(&self, toolchain: &Toolchain) -> TResult<()> { self.reporter .run_scoped_event(SetupToolchainEvent::new(toolchain.to_owned()), || { install_toolchain(toolchain) @@ -40,7 +40,7 @@ impl<'reporter, R: Reporter> SetupToolchain for SetupRustupToolchain<'reporter, } #[instrument(skip(toolchain))] -fn install_toolchain(toolchain: &ToolchainSpec) -> TResult<()> { +fn install_toolchain(toolchain: &Toolchain) -> TResult<()> { info!(toolchain = toolchain.spec(), "installing host toolchain"); let rustup = RustupCommand::new() @@ -71,7 +71,7 @@ fn install_toolchain(toolchain: &ToolchainSpec) -> TResult<()> { } #[instrument(skip(toolchain))] -fn add_target(toolchain: &ToolchainSpec) -> TResult<()> { +fn add_target(toolchain: &Toolchain) -> TResult<()> { info!( toolchain = toolchain.spec(), target = toolchain.target(), @@ -112,7 +112,7 @@ fn add_target(toolchain: &ToolchainSpec) -> TResult<()> { } #[instrument(skip(toolchain))] -fn add_components(toolchain: &ToolchainSpec) -> TResult<()> { +fn add_components(toolchain: &Toolchain) -> TResult<()> { info!( toolchain = toolchain.spec(), target = toolchain.target(), diff --git a/src/toolchain.rs b/src/rust/toolchain.rs similarity index 83% rename from src/toolchain.rs rename to src/rust/toolchain.rs index 6fd808bc..992a6556 100644 --- a/src/toolchain.rs +++ b/src/rust/toolchain.rs @@ -3,7 +3,7 @@ use rust_releases::semver; #[derive(Debug, Clone, Eq, PartialEq, serde::Serialize)] #[serde(rename_all = "snake_case")] -pub struct ToolchainSpec { +pub struct Toolchain { version: semver::Version, target: &'static str, components: &'static [&'static str], @@ -11,7 +11,7 @@ pub struct ToolchainSpec { spec: OnceCell, } -impl ToolchainSpec { +impl Toolchain { pub fn new( version: semver::Version, target: &'static str, @@ -43,7 +43,7 @@ impl ToolchainSpec { } } -impl std::fmt::Display for ToolchainSpec { +impl std::fmt::Display for Toolchain { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_fmt(format_args!("{}", self.spec())) } @@ -60,7 +60,7 @@ mod tests_toolchain_spec { #[test] fn get_spec() { let version = semver::Version::new(1, 2, 3); - let toolchain = ToolchainSpec::new(version, "x", &[]); + let toolchain = Toolchain::new(version, "x", &[]); assert_eq!(toolchain.spec(), "1.2.3-x"); } @@ -68,7 +68,7 @@ mod tests_toolchain_spec { #[test] fn get_version() { let version = semver::Version::new(1, 2, 3); - let toolchain = ToolchainSpec::new(version, "x", &[]); + let toolchain = Toolchain::new(version, "x", &[]); assert_eq!(toolchain.version(), &semver::Version::new(1, 2, 3)); } @@ -76,7 +76,7 @@ mod tests_toolchain_spec { #[test] fn get_target() { let version = semver::Version::new(1, 2, 3); - let toolchain = ToolchainSpec::new(version, "x", &[]); + let toolchain = Toolchain::new(version, "x", &[]); assert_eq!(toolchain.target(), "x"); } @@ -84,7 +84,7 @@ mod tests_toolchain_spec { #[test] fn get_components() { let version = semver::Version::new(1, 2, 3); - let toolchain = ToolchainSpec::new(version, "x", &["hello", "chris!"]); + let toolchain = Toolchain::new(version, "x", &["hello", "chris!"]); assert_eq!(toolchain.components(), &["hello", "chris!"]); } @@ -97,7 +97,7 @@ mod tests_make_toolchain_spec { #[test] fn display() { let version = semver::Version::new(1, 2, 3); - let toolchain = ToolchainSpec::new(version, "y", &[]); + let toolchain = Toolchain::new(version, "y", &[]); let spec = format!("{}", toolchain); @@ -115,7 +115,7 @@ mod tests_make_toolchain_spec { #[test] fn display_ignores_components() { let version = semver::Version::new(1, 2, 3); - let toolchain = ToolchainSpec::new(version, "y", &["to", "be", "ignored"]); + let toolchain = Toolchain::new(version, "y", &["to", "be", "ignored"]); let spec = format!("{}", toolchain); diff --git a/src/search_method.rs b/src/search_method.rs index f1e5aaee..683a9bf7 100644 --- a/src/search_method.rs +++ b/src/search_method.rs @@ -2,7 +2,7 @@ pub use {bisect::Bisect, linear::Linear}; use crate::msrv::MinimumSupportedRustVersion; use crate::reporter::Reporter; -use crate::rust_release::RustRelease; +use crate::rust::RustRelease; use crate::TResult; /// Use a bisection method to find the MSRV. By using a binary search, we halve our search space each diff --git a/src/search_method/bisect.rs b/src/search_method/bisect.rs index 74ccf403..f76bde05 100644 --- a/src/search_method/bisect.rs +++ b/src/search_method/bisect.rs @@ -7,7 +7,7 @@ use crate::msrv::MinimumSupportedRustVersion; use crate::outcome::{FailureOutcome, Outcome, SuccessOutcome}; use crate::reporter::event::{FindMsrv, Progress}; use crate::reporter::Reporter; -use crate::rust_release::RustRelease; +use crate::rust::RustRelease; use crate::search_method::FindMinimalSupportedRustVersion; use crate::TResult; @@ -119,7 +119,7 @@ mod tests { use crate::check::TestRunner; use crate::reporter::TestReporterWrapper; - use crate::rust_release::RustRelease; + use crate::rust::RustRelease; use crate::search_method::FindMinimalSupportedRustVersion; use crate::semver; diff --git a/src/search_method/linear.rs b/src/search_method/linear.rs index 241a57de..b7557fcb 100644 --- a/src/search_method/linear.rs +++ b/src/search_method/linear.rs @@ -5,7 +5,7 @@ use crate::msrv::MinimumSupportedRustVersion; use crate::outcome::Outcome; use crate::reporter::event::{FindMsrv, Progress}; use crate::reporter::Reporter; -use crate::rust_release::RustRelease; +use crate::rust::RustRelease; use crate::search_method::FindMinimalSupportedRustVersion; use crate::TResult; @@ -68,8 +68,8 @@ mod tests { use super::*; use crate::check::TestRunner; use crate::reporter::TestReporterWrapper; + use crate::rust::Toolchain; use crate::semver; - use crate::toolchain::ToolchainSpec; use rust_releases::{Release, ReleaseIndex}; use std::iter::FromIterator; @@ -123,7 +123,7 @@ mod tests { .unwrap(); let expected = MinimumSupportedRustVersion::Toolchain { - toolchain: ToolchainSpec::new(semver::Version::new(1, 54, 0), "x", &[]), + toolchain: Toolchain::new(semver::Version::new(1, 54, 0), "x", &[]), }; assert_eq!(actual, expected); @@ -152,7 +152,7 @@ mod tests { .unwrap(); let expected = MinimumSupportedRustVersion::Toolchain { - toolchain: ToolchainSpec::new(semver::Version::new(1, 56, 0), "x", &[]), + toolchain: Toolchain::new(semver::Version::new(1, 56, 0), "x", &[]), }; assert_eq!(actual, expected); diff --git a/src/sub_command/find.rs b/src/sub_command/find.rs index 4f2cf4cf..f84560dd 100644 --- a/src/sub_command/find.rs +++ b/src/sub_command/find.rs @@ -5,10 +5,10 @@ use crate::context::{FindContext, SearchMethod}; use crate::error::{CargoMSRVError, NoToolchainsToTryError, TResult}; use crate::manifest::bare_version::BareVersion; use crate::msrv::MinimumSupportedRustVersion; -use crate::releases_filter::ReleasesFilter; use crate::reporter::event::FindResult; use crate::reporter::Reporter; -use crate::rust_release::RustRelease; +use crate::rust::releases_filter::ReleasesFilter; +use crate::rust::RustRelease; use crate::search_method::{Bisect, FindMinimalSupportedRustVersion, Linear}; use crate::writer::toolchain_file::write_toolchain_file; use crate::writer::write_msrv::write_msrv; diff --git a/src/sub_command/verify.rs b/src/sub_command/verify.rs index 73f56c73..b964b445 100644 --- a/src/sub_command/verify.rs +++ b/src/sub_command/verify.rs @@ -12,8 +12,8 @@ use crate::manifest::CargoManifest; use crate::outcome::Outcome; use crate::reporter::event::VerifyResult; use crate::reporter::Reporter; +use crate::rust::Toolchain; use crate::sub_command::SubCommand; -use crate::toolchain::ToolchainSpec; /// Verifier which determines whether a given Rust version is deemed compatible or not. pub struct Verify<'index, C: Check> { @@ -69,7 +69,7 @@ fn verify_msrv( let target = ctx.toolchain.target; let components = ctx.toolchain.components; - let toolchain = ToolchainSpec::new(version.clone(), target, components); + let toolchain = Toolchain::new(version.clone(), target, components); match runner.check(&toolchain)? { Outcome::Success(_) => success(reporter, toolchain), @@ -78,7 +78,7 @@ fn verify_msrv( } // Report the successful verification to the user -fn success(reporter: &impl Reporter, toolchain: ToolchainSpec) -> TResult<()> { +fn success(reporter: &impl Reporter, toolchain: Toolchain) -> TResult<()> { reporter.report_event(VerifyResult::compatible(toolchain))?; Ok(()) } @@ -86,7 +86,7 @@ fn success(reporter: &impl Reporter, toolchain: ToolchainSpec) -> TResult<()> { // Report the failed verification to the user, and return a VerifyFailed error fn failure( reporter: &impl Reporter, - toolchain: ToolchainSpec, + toolchain: Toolchain, rust_version: RustVersion, error: Option, ) -> TResult<()> { diff --git a/tests/common/runner.rs b/tests/common/runner.rs index 76967a53..a35995f4 100644 --- a/tests/common/runner.rs +++ b/tests/common/runner.rs @@ -7,7 +7,7 @@ use std::collections::HashSet; use cargo_msrv::check::Check; use cargo_msrv::error::CargoMSRVError; -use cargo_msrv::toolchain::ToolchainSpec; +use cargo_msrv::rust::Toolchain; use cargo_msrv::Outcome; use rust_releases::semver::Version; @@ -26,19 +26,19 @@ impl TestRunner { } impl Check for TestRunner { - fn check(&self, toolchain: &ToolchainSpec) -> Result { + fn check(&self, toolchain: &Toolchain) -> Result { let version = toolchain.version(); let components = toolchain.components(); if self.accept_versions.contains(toolchain.version()) { - Ok(Outcome::new_success(ToolchainSpec::new( + Ok(Outcome::new_success(Toolchain::new( version.clone(), self.target, components, ))) } else { Ok(Outcome::new_failure( - ToolchainSpec::new(version.clone(), self.target, components), + Toolchain::new(version.clone(), self.target, components), "f".to_string(), )) } From 38ae52076e8da0ce9f873cd1596be9b282ead3d1 Mon Sep 17 00:00:00 2001 From: Martijn Date: Sun, 20 Oct 2024 01:51:09 +0200 Subject: [PATCH 3/4] Convert modules back to mod.rs style --- src/{check.rs => check/mod.rs} | 0 src/{cli.rs => cli/mod.rs} | 0 src/{context.rs => context/mod.rs} | 0 .../mod.rs} | 0 .../mod.rs} | 0 src/lib.rs | 22 +++++++++---------- src/{manifest.rs => manifest/mod.rs} | 0 src/reporter/{event.rs => event/mod.rs} | 0 .../event/{shared.rs => shared/mod.rs} | 0 .../{list_result.rs => list_result/mod.rs} | 0 src/reporter/event/{types.rs => types/mod.rs} | 0 src/{reporter.rs => reporter/mod.rs} | 0 src/reporter/ui/{json.rs => json/mod.rs} | 0 .../ui/json/{testing.rs => testing/mod.rs} | 0 src/reporter/{ui.rs => ui/mod.rs} | 0 .../mod.rs} | 0 src/sub_command/{find.rs => find/mod.rs} | 0 src/{sub_command.rs => sub_command/mod.rs} | 0 src/{writer.rs => writer/mod.rs} | 0 19 files changed, 11 insertions(+), 11 deletions(-) rename src/{check.rs => check/mod.rs} (100%) rename src/{cli.rs => cli/mod.rs} (100%) rename src/{context.rs => context/mod.rs} (100%) rename src/{dependency_graph.rs => dependency_graph/mod.rs} (100%) rename src/{external_command.rs => external_command/mod.rs} (100%) rename src/{manifest.rs => manifest/mod.rs} (100%) rename src/reporter/{event.rs => event/mod.rs} (100%) rename src/reporter/event/{shared.rs => shared/mod.rs} (100%) rename src/reporter/event/types/{list_result.rs => list_result/mod.rs} (100%) rename src/reporter/event/{types.rs => types/mod.rs} (100%) rename src/{reporter.rs => reporter/mod.rs} (100%) rename src/reporter/ui/{json.rs => json/mod.rs} (100%) rename src/reporter/ui/json/{testing.rs => testing/mod.rs} (100%) rename src/reporter/{ui.rs => ui/mod.rs} (100%) rename src/{search_method.rs => search_method/mod.rs} (100%) rename src/sub_command/{find.rs => find/mod.rs} (100%) rename src/{sub_command.rs => sub_command/mod.rs} (100%) rename src/{writer.rs => writer/mod.rs} (100%) diff --git a/src/check.rs b/src/check/mod.rs similarity index 100% rename from src/check.rs rename to src/check/mod.rs diff --git a/src/cli.rs b/src/cli/mod.rs similarity index 100% rename from src/cli.rs rename to src/cli/mod.rs diff --git a/src/context.rs b/src/context/mod.rs similarity index 100% rename from src/context.rs rename to src/context/mod.rs diff --git a/src/dependency_graph.rs b/src/dependency_graph/mod.rs similarity index 100% rename from src/dependency_graph.rs rename to src/dependency_graph/mod.rs diff --git a/src/external_command.rs b/src/external_command/mod.rs similarity index 100% rename from src/external_command.rs rename to src/external_command/mod.rs diff --git a/src/lib.rs b/src/lib.rs index 1b1bb473..76ddac45 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,23 +35,23 @@ use rust_releases::semver; pub mod check; pub mod cli; -mod context; -pub(crate) mod dependency_graph; +pub mod context; +pub mod dependency_graph; pub mod error; pub mod exit_code; mod external_command; pub mod io; -pub(crate) mod lockfile; -pub(crate) mod log_level; -pub(crate) mod manifest; -pub(crate) mod msrv; -pub(crate) mod outcome; +pub mod lockfile; +pub mod log_level; +pub mod manifest; +pub mod msrv; +pub mod outcome; pub mod reporter; pub mod rust; -pub(crate) mod search_method; -pub(crate) mod sub_command; -pub(crate) mod typed_bool; -pub(crate) mod writer; +pub mod search_method; +pub mod sub_command; +pub mod typed_bool; +pub mod writer; pub fn run_app(ctx: &Context, reporter: &impl Reporter) -> TResult<()> { reporter.report_event(Meta::default())?; diff --git a/src/manifest.rs b/src/manifest/mod.rs similarity index 100% rename from src/manifest.rs rename to src/manifest/mod.rs diff --git a/src/reporter/event.rs b/src/reporter/event/mod.rs similarity index 100% rename from src/reporter/event.rs rename to src/reporter/event/mod.rs diff --git a/src/reporter/event/shared.rs b/src/reporter/event/shared/mod.rs similarity index 100% rename from src/reporter/event/shared.rs rename to src/reporter/event/shared/mod.rs diff --git a/src/reporter/event/types/list_result.rs b/src/reporter/event/types/list_result/mod.rs similarity index 100% rename from src/reporter/event/types/list_result.rs rename to src/reporter/event/types/list_result/mod.rs diff --git a/src/reporter/event/types.rs b/src/reporter/event/types/mod.rs similarity index 100% rename from src/reporter/event/types.rs rename to src/reporter/event/types/mod.rs diff --git a/src/reporter.rs b/src/reporter/mod.rs similarity index 100% rename from src/reporter.rs rename to src/reporter/mod.rs diff --git a/src/reporter/ui/json.rs b/src/reporter/ui/json/mod.rs similarity index 100% rename from src/reporter/ui/json.rs rename to src/reporter/ui/json/mod.rs diff --git a/src/reporter/ui/json/testing.rs b/src/reporter/ui/json/testing/mod.rs similarity index 100% rename from src/reporter/ui/json/testing.rs rename to src/reporter/ui/json/testing/mod.rs diff --git a/src/reporter/ui.rs b/src/reporter/ui/mod.rs similarity index 100% rename from src/reporter/ui.rs rename to src/reporter/ui/mod.rs diff --git a/src/search_method.rs b/src/search_method/mod.rs similarity index 100% rename from src/search_method.rs rename to src/search_method/mod.rs diff --git a/src/sub_command/find.rs b/src/sub_command/find/mod.rs similarity index 100% rename from src/sub_command/find.rs rename to src/sub_command/find/mod.rs diff --git a/src/sub_command.rs b/src/sub_command/mod.rs similarity index 100% rename from src/sub_command.rs rename to src/sub_command/mod.rs diff --git a/src/writer.rs b/src/writer/mod.rs similarity index 100% rename from src/writer.rs rename to src/writer/mod.rs From de068183fa48169f213151933a0d86cdebea3c75 Mon Sep 17 00:00:00 2001 From: Martijn Date: Sun, 20 Oct 2024 02:48:18 +0200 Subject: [PATCH 4/4] Flatten json test modules --- src/reporter/ui/json/mod.rs | 11 ++++++++++- .../ui/json/{testing/find.rs => test_find.rs} | 0 src/reporter/ui/json/{testing/set.rs => test_set.rs} | 0 .../ui/json/{testing/show.rs => test_show.rs} | 0 .../ui/json/{testing/verify.rs => test_verify.rs} | 0 src/reporter/ui/json/testing/mod.rs | 4 ---- 6 files changed, 10 insertions(+), 5 deletions(-) rename src/reporter/ui/json/{testing/find.rs => test_find.rs} (100%) rename src/reporter/ui/json/{testing/set.rs => test_set.rs} (100%) rename src/reporter/ui/json/{testing/show.rs => test_show.rs} (100%) rename src/reporter/ui/json/{testing/verify.rs => test_verify.rs} (100%) delete mode 100644 src/reporter/ui/json/testing/mod.rs diff --git a/src/reporter/ui/json/mod.rs b/src/reporter/ui/json/mod.rs index 0596d78b..5f9b9967 100644 --- a/src/reporter/ui/json/mod.rs +++ b/src/reporter/ui/json/mod.rs @@ -8,7 +8,16 @@ use std::sync::{Arc, Mutex}; use storyteller::EventHandler; #[cfg(test)] -mod testing; +mod test_find; + +#[cfg(test)] +mod test_set; + +#[cfg(test)] +mod test_show; + +#[cfg(test)] +mod test_verify; pub struct JsonHandler { writer: Arc>, diff --git a/src/reporter/ui/json/testing/find.rs b/src/reporter/ui/json/test_find.rs similarity index 100% rename from src/reporter/ui/json/testing/find.rs rename to src/reporter/ui/json/test_find.rs diff --git a/src/reporter/ui/json/testing/set.rs b/src/reporter/ui/json/test_set.rs similarity index 100% rename from src/reporter/ui/json/testing/set.rs rename to src/reporter/ui/json/test_set.rs diff --git a/src/reporter/ui/json/testing/show.rs b/src/reporter/ui/json/test_show.rs similarity index 100% rename from src/reporter/ui/json/testing/show.rs rename to src/reporter/ui/json/test_show.rs diff --git a/src/reporter/ui/json/testing/verify.rs b/src/reporter/ui/json/test_verify.rs similarity index 100% rename from src/reporter/ui/json/testing/verify.rs rename to src/reporter/ui/json/test_verify.rs diff --git a/src/reporter/ui/json/testing/mod.rs b/src/reporter/ui/json/testing/mod.rs deleted file mode 100644 index a1746a6d..00000000 --- a/src/reporter/ui/json/testing/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -mod find; -mod set; -mod show; -mod verify;