diff --git a/.github/workflows/msrv.yml b/.github/workflows/msrv.yml index 68d89940..75b28f3e 100644 --- a/.github/workflows/msrv.yml +++ b/.github/workflows/msrv.yml @@ -9,9 +9,23 @@ on: schedule: - cron: '00 06 * * *' jobs: + # MSRV check and e2e test msrv: name: msrv - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + build: [ ubuntu, macos ] # [, windows] ... Disabled Windows for now, see #1036 + include: + - build: ubuntu + os: ubuntu-latest + + - build: macos + os: macos-latest + + # - build: windows + # os: windows-latest continue-on-error: true steps: - name: checkout_repo @@ -19,17 +33,20 @@ jobs: - name: install_rust uses: dtolnay/rust-toolchain@stable - name: install_cargo_msrv - run: cargo install cargo-msrv --all-features + if: matrix.build == 'ubuntu' + run: cargo install cargo-msrv + - name: install_cargo_msrv_no_default + if: matrix.build != 'ubuntu' + run: cargo install cargo-msrv --no-default-features - name: version_of_cargo_msrv run: cargo msrv --version - name: run_cargo_msrv - run: cargo msrv --output-format json verify + run: cargo msrv verify --output-format json - name: run_cargo_msrv_on_verify_failure if: ${{ failure() }} run: cargo msrv find --output-format json # The same as the 'msrv' job, except it takes the latest release, including beta releases - # We don't use --all-features here! msrv_pre_release: name: msrv_pre_release runs-on: ubuntu-latest @@ -43,11 +60,11 @@ jobs: with: tool: cargo-binstall - name: install_cargo_msrv_bin - run: cargo binstall --version 0.16.0 --no-confirm cargo-msrv + run: cargo binstall --version 0.16.2 --no-confirm cargo-msrv - name: version_of_cargo_msrv run: cargo msrv --version - name: run_cargo_msrv - run: cargo msrv --output-format json verify + run: cargo msrv verify --output-format json - name: run_cargo_msrv_on_verify_failure if: ${{ failure() }} run: cargo msrv find --output-format json @@ -68,7 +85,7 @@ jobs: - name: version_of_cargo_msrv run: cargo msrv --version - name: run_cargo_msrv - run: cargo msrv --output-format json verify + run: cargo msrv verify --output-format json - name: run_cargo_msrv_on_verify_failure if: ${{ failure() }} run: cargo msrv find --output-format json diff --git a/CHANGELOG.md b/CHANGELOG.md index b12a67c9..ae942094 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,16 @@ the [discussions section](https://github.com/foresterre/cargo-msrv/discussions). * Added `--workspace`, `--all`, `--package` and `--exclude` CLI options for package selection when in a Cargo project ( with limited workspace support for now) +* `cargo msrv find --write-msrv` is now aliased by `cargo msrv find --set`, which is consistent in terminology with + `cargo msrv set` + +### Changed + +* Toolchains installed with `rustup install` now use the `--no-self-update` flag + +### Known issues + +* Installing toolchains on GitHub Actions can fail for the windows runner (#1036) ## [0.16.2] - 2024-10-10 diff --git a/deny.toml b/deny.toml index de24e230..8b95dceb 100644 --- a/deny.toml +++ b/deny.toml @@ -1,6 +1,7 @@ [advisories] ignore = [ - "RUSTSEC-2024-0370" # proc-macro-error is unmaintained (via tabled > tabled_derive) + "RUSTSEC-2024-0370", # https://rustsec.org/advisories/RUSTSEC-2024-0370 `proc-macro-error` is unmaintained (via `tabled` > `tabled_derive`) + "RUSTSEC-2024-0384", # https://rustsec.org/advisories/RUSTSEC-2024-0384 `instant` is unmaintained (via `indicatif`) ] [licenses] diff --git a/src/check/mod.rs b/src/check/mod.rs deleted file mode 100644 index 143ccb61..00000000 --- a/src/check/mod.rs +++ /dev/null @@ -1,15 +0,0 @@ -use crate::rust::Toolchain; - -mod rustup_toolchain_check; -#[cfg(test)] -mod testing; - -use crate::{Outcome, TResult}; -pub use rustup_toolchain_check::{RunCommand, RustupToolchainCheck}; - -#[cfg(test)] -pub use testing::TestRunner; - -pub trait Check { - fn check(&self, toolchain: &Toolchain) -> TResult; -} diff --git a/src/compatibility/mod.rs b/src/compatibility/mod.rs new file mode 100644 index 00000000..f6fe76b1 --- /dev/null +++ b/src/compatibility/mod.rs @@ -0,0 +1,26 @@ +use crate::rust::Toolchain; + +mod rustup_toolchain_check; +#[cfg(test)] +mod testing; + +use crate::{Compatibility, TResult}; +pub use rustup_toolchain_check::{RunCommand, RustupToolchainCheck}; + +#[cfg(test)] +pub use testing::TestRunner; + +/// Implementers of this trait must determine whether a Rust toolchain is _supported_ +/// for a Rust project. This is a step in the process of determining the _minimally +/// supported_ Rust version; the MSRV. +pub trait IsCompatible { + fn before(&self, _toolchain: &Toolchain) -> TResult<()> { + Ok(()) + } + + fn is_compatible(&self, toolchain: &Toolchain) -> TResult; + + fn after(&self, _toolchain: &Toolchain) -> TResult<()> { + Ok(()) + } +} diff --git a/src/check/rustup_toolchain_check.rs b/src/compatibility/rustup_toolchain_check.rs similarity index 90% rename from src/check/rustup_toolchain_check.rs rename to src/compatibility/rustup_toolchain_check.rs index 87a46508..92aad1ab 100644 --- a/src/check/rustup_toolchain_check.rs +++ b/src/compatibility/rustup_toolchain_check.rs @@ -1,4 +1,4 @@ -use crate::check::Check; +use crate::compatibility::IsCompatible; use crate::context::EnvironmentContext; use crate::error::{IoError, IoErrorSource}; use crate::external_command::cargo_command::CargoCommand; @@ -7,7 +7,7 @@ use crate::lockfile::LockfileHandler; use crate::reporter::event::{CheckMethod, CheckResult, CheckToolchain, Method}; use crate::rust::setup_toolchain::{SetupRustupToolchain, SetupToolchain}; use crate::rust::Toolchain; -use crate::{lockfile, CargoMSRVError, Outcome, Reporter, TResult}; +use crate::{lockfile, CargoMSRVError, Compatibility, Reporter, TResult}; use camino::{Utf8Path, Utf8PathBuf}; use std::fmt; use std::fmt::Formatter; @@ -37,8 +37,8 @@ impl<'reporter, 'env, R: Reporter> RustupToolchainCheck<'reporter, 'env, R> { } } -impl<'reporter, 'env, R: Reporter> Check for RustupToolchainCheck<'reporter, 'env, R> { - fn check(&self, toolchain: &Toolchain) -> TResult { +impl<'reporter, 'env, R: Reporter> IsCompatible for RustupToolchainCheck<'reporter, 'env, R> { + fn is_compatible(&self, toolchain: &Toolchain) -> TResult { let settings = &self.settings; self.reporter @@ -98,7 +98,7 @@ fn run_check_command_via_rustup( toolchain: &Toolchain, dir: &Utf8Path, check: &[String], -) -> TResult { +) -> TResult { let version = format!("{}", toolchain.version()); let mut cmd = vec![version.as_str()]; cmd.extend(check.iter().map(|s| s.as_str())); @@ -121,7 +121,7 @@ fn run_check_command_via_rustup( let status = rustup_output.exit_status(); if status.success() { - Ok(Outcome::new_success(toolchain.to_owned())) + Ok(Compatibility::new_success(toolchain.to_owned())) } else { let stderr = rustup_output.stderr(); let command = cmd.join(" "); @@ -133,7 +133,7 @@ fn run_check_command_via_rustup( "try_building run failed" ); - Ok(Outcome::new_failure( + Ok(Compatibility::new_failure( toolchain.to_owned(), stderr.to_string(), )) @@ -142,22 +142,22 @@ fn run_check_command_via_rustup( fn report_outcome( reporter: &impl Reporter, - outcome: &Outcome, + outcome: &Compatibility, no_error_report: bool, ) -> TResult<()> { match outcome { - Outcome::Success(outcome) => { + Compatibility::Compatible(outcome) => { // report compatibility with this toolchain reporter.report_event(CheckResult::compatible(outcome.toolchain_spec.to_owned()))? } - Outcome::Failure(outcome) if no_error_report => { + Compatibility::Incompatible(outcome) if no_error_report => { // report incompatibility with this toolchain reporter.report_event(CheckResult::incompatible( outcome.toolchain_spec.to_owned(), None, ))? } - Outcome::Failure(outcome) => { + Compatibility::Incompatible(outcome) => { // report incompatibility with this toolchain reporter.report_event(CheckResult::incompatible( outcome.toolchain_spec.to_owned(), @@ -225,7 +225,7 @@ pub struct RunCommand { } impl RunCommand { - pub fn default(cargo_command: CargoCommand) -> Self { + pub fn from_cargo_command(cargo_command: CargoCommand) -> Self { Self { command: cargo_command.into_args(), } diff --git a/src/check/testing.rs b/src/compatibility/testing.rs similarity index 72% rename from src/check/testing.rs rename to src/compatibility/testing.rs index 3cab172e..24b0bcf1 100644 --- a/src/check/testing.rs +++ b/src/compatibility/testing.rs @@ -1,5 +1,5 @@ -use crate::check::Check; -use crate::outcome::Outcome; +use crate::compatibility::IsCompatible; +use crate::outcome::Compatibility; use crate::rust::Toolchain; use crate::semver::Version; use crate::TResult; @@ -19,18 +19,18 @@ impl TestRunner { } } -impl Check for TestRunner { - fn check(&self, toolchain: &Toolchain) -> TResult { +impl IsCompatible for TestRunner { + fn is_compatible(&self, toolchain: &Toolchain) -> TResult { let v = toolchain.version(); if self.accept_versions.contains(toolchain.version()) { - Ok(Outcome::new_success(Toolchain::new( + Ok(Compatibility::new_success(Toolchain::new( v.clone(), self.target, &[], ))) } else { - Ok(Outcome::new_failure( + Ok(Compatibility::new_failure( Toolchain::new(v.clone(), self.target, &[]), "f".to_string(), )) diff --git a/src/context/find.rs b/src/context/find.rs index a50aa755..20587577 100644 --- a/src/context/find.rs +++ b/src/context/find.rs @@ -1,5 +1,5 @@ -use crate::check::RunCommand; use crate::cli::{CargoMsrvOpts, SubCommand}; +use crate::compatibility::RunCommand; use crate::context::{ CheckCommandContext, EnvironmentContext, RustReleasesContext, SearchMethod, ToolchainContext, }; @@ -83,7 +83,7 @@ impl FindContext { .all_features(self.check_cmd.cargo_all_features) .no_default_features(self.check_cmd.cargo_no_default_features); - RunCommand::default(cargo_command) + RunCommand::from_cargo_command(cargo_command) } } } diff --git a/src/context/verify.rs b/src/context/verify.rs index 2b033ef7..cb55b172 100644 --- a/src/context/verify.rs +++ b/src/context/verify.rs @@ -3,7 +3,7 @@ use crate::context::{ CheckCommandContext, EnvironmentContext, RustReleasesContext, ToolchainContext, }; -use crate::check::RunCommand; +use crate::compatibility::RunCommand; use crate::error::CargoMSRVError; use crate::external_command::cargo_command::CargoCommand; use crate::sub_command::verify::RustVersion; @@ -78,7 +78,7 @@ impl VerifyContext { .all_features(self.check_cmd.cargo_all_features) .no_default_features(self.check_cmd.cargo_no_default_features); - RunCommand::default(cargo_command) + RunCommand::from_cargo_command(cargo_command) } } } diff --git a/src/external_command/cargo_command.rs b/src/external_command/cargo_command.rs index 3768f724..6063b0de 100644 --- a/src/external_command/cargo_command.rs +++ b/src/external_command/cargo_command.rs @@ -33,7 +33,7 @@ impl CargoCommand { /// Intended to be used in conjunction with [`RunCommand`] and/or [`RustupCommand`]. /// - /// [`RunCommand`]: crate::check::RunCommand + /// [`RunCommand`]: crate::compatibility::RunCommand /// [`RustupCommand`]: crate::external_command::rustup_command::RustupCommand // Currently we don't invoke it from here directly, but we might eventually, if // we want to also provide some nicer structs around parsing. However compared to diff --git a/src/external_command/rustup_command.rs b/src/external_command/rustup_command.rs index 7d2a41f8..2d538bc1 100644 --- a/src/external_command/rustup_command.rs +++ b/src/external_command/rustup_command.rs @@ -1,14 +1,15 @@ +use crate::error::{IoError, IoErrorSource, TResult}; +use camino::Utf8Path; use std::ffi::{OsStr, OsString}; -use std::path::Path; use std::process::{Command, Stdio}; -use crate::error::{IoError, IoErrorSource, TResult}; - pub struct RustupCommand { command: Command, args: Vec, stdout: Stdio, stderr: Stdio, + // Span used to trace the path to execution of a RustupCommand + _span: tracing::Span, } impl RustupCommand { @@ -18,11 +19,27 @@ impl RustupCommand { args: Vec::new(), stdout: Stdio::null(), stderr: Stdio::null(), + _span: tracing::debug_span!("RustupCommand"), } } - pub fn with_dir(mut self, path: impl AsRef) -> Self { - let _ = self.command.current_dir(path); + pub fn with_dir(mut self, path: impl AsRef) -> Self { + // The block ensures the scope of the _span.enter() will exit before + // returning self at the end of the method scope. + { + let _span = self._span.enter(); + + let path = path.as_ref(); + + if let Ok(canonical_path) = path.canonicalize() { + debug!(name: "rustup_command_path", canonicalized = true, path = %canonical_path.display()); + self.command.current_dir(canonical_path); + } else { + debug!(name: "rustup_command_path", canonicalized = false, %path); + self.command.current_dir(path); + } + } + self } @@ -70,10 +87,14 @@ impl RustupCommand { /// * [RustupCommand::run](RustupCommand::run) /// * [RustupCommand::install](RustupCommand::install) /// * [RustupCommand::show](RustupCommand::show) - pub fn execute(mut self, cmd: &OsStr) -> TResult { + fn execute(mut self, cmd: &OsStr) -> TResult { + let _span = self._span.enter(); + debug!( + name: "rustup_command_execute_start", cmd = ?cmd, - args = ?self.args.as_slice() + args = ?self.args.as_slice(), + current_dir = ?self.command.get_current_dir(), ); self.command.arg(cmd); @@ -86,11 +107,18 @@ impl RustupCommand { error, source: IoErrorSource::SpawnProcess(cmd.to_owned()), })?; + let output = child.wait_with_output().map_err(|error| IoError { error, source: IoErrorSource::WaitForProcessAndCollectOutput(cmd.to_owned()), })?; + debug!( + name: "rustup_command_execute_finish", + cmd = ?cmd, + success = output.status.success(), + ); + Ok(RustupOutput { output, stdout: once_cell::sync::OnceCell::new(), diff --git a/src/lib.rs b/src/lib.rs index 76ddac45..c0d78ba4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,10 +21,10 @@ extern crate core; extern crate tracing; pub use crate::context::{Context, OutputFormat, TracingOptions, TracingTargetOption}; -pub use crate::outcome::Outcome; +pub use crate::outcome::Compatibility; pub use crate::sub_command::{Find, List, Set, Show, SubCommand, Verify}; -use crate::check::RustupToolchainCheck; +use crate::compatibility::RustupToolchainCheck; use crate::context::ReleaseSource; use crate::error::{CargoMSRVError, TResult}; use crate::reporter::event::{Meta, SelectedPackages, SubcommandInit}; @@ -32,8 +32,8 @@ use crate::reporter::{Event, Reporter}; use rust::release_index; use rust_releases::semver; -pub mod check; pub mod cli; +pub mod compatibility; pub mod context; pub mod dependency_graph; diff --git a/src/outcome.rs b/src/outcome.rs index 38cf4203..e9e67c68 100644 --- a/src/outcome.rs +++ b/src/outcome.rs @@ -1,23 +1,23 @@ //! The outcome of a single toolchain [`check`] run. //! -//! [`check`]: crate::check::Check +//! [`check`]: crate::compatibility::IsCompatible use crate::rust::Toolchain; use rust_releases::semver; #[derive(Clone, Debug)] -pub enum Outcome { - Success(SuccessOutcome), - Failure(FailureOutcome), +pub enum Compatibility { + Compatible(Compatible), + Incompatible(Incompatible), } -impl Outcome { +impl Compatibility { pub fn new_success(toolchain_spec: Toolchain) -> Self { - Self::Success(SuccessOutcome { toolchain_spec }) + Self::Compatible(Compatible { toolchain_spec }) } pub fn new_failure(toolchain_spec: Toolchain, error_message: String) -> Self { - Self::Failure(FailureOutcome { + Self::Incompatible(Incompatible { toolchain_spec, error_message, }) @@ -25,33 +25,33 @@ impl Outcome { pub fn is_success(&self) -> bool { match self { - Self::Success { .. } => true, - Self::Failure { .. } => false, + Self::Compatible { .. } => true, + Self::Incompatible { .. } => false, } } pub fn version(&self) -> &semver::Version { match self { - Self::Success(outcome) => outcome.toolchain_spec.version(), - Self::Failure(outcome) => outcome.toolchain_spec.version(), + Self::Compatible(outcome) => outcome.toolchain_spec.version(), + Self::Incompatible(outcome) => outcome.toolchain_spec.version(), } } pub fn toolchain_spec(&self) -> &Toolchain { match self { - Self::Success(outcome) => &outcome.toolchain_spec, - Self::Failure(outcome) => &outcome.toolchain_spec, + Self::Compatible(outcome) => &outcome.toolchain_spec, + Self::Incompatible(outcome) => &outcome.toolchain_spec, } } } #[derive(Clone, Debug, Eq, PartialEq)] -pub struct SuccessOutcome { +pub struct Compatible { pub(crate) toolchain_spec: Toolchain, } #[derive(Clone, Debug, Eq, PartialEq)] -pub struct FailureOutcome { +pub struct Incompatible { pub(crate) toolchain_spec: Toolchain, pub(crate) error_message: String, } @@ -59,7 +59,7 @@ pub struct FailureOutcome { #[cfg(test)] mod tests { use crate::rust::Toolchain; - use crate::Outcome; + use crate::Compatibility; use rust_releases::semver; #[test] @@ -67,7 +67,7 @@ mod tests { let version = semver::Version::new(1, 2, 3); let toolchain = Toolchain::new(version, "x", &[]); - let outcome = Outcome::new_success(toolchain.clone()); + let outcome = Compatibility::new_success(toolchain.clone()); assert!(outcome.is_success()); assert_eq!(outcome.version(), &semver::Version::new(1, 2, 3)); @@ -79,7 +79,7 @@ mod tests { let version = semver::Version::new(1, 2, 3); let toolchain = Toolchain::new(version, "x", &[]); - let outcome = Outcome::new_failure(toolchain.clone(), "msg".to_string()); + let outcome = Compatibility::new_failure(toolchain.clone(), "msg".to_string()); assert!(!outcome.is_success()); assert_eq!(outcome.version(), &semver::Version::new(1, 2, 3)); diff --git a/src/rust/setup_toolchain.rs b/src/rust/setup_toolchain.rs index ac6d2cd4..298134ed 100644 --- a/src/rust/setup_toolchain.rs +++ b/src/rust/setup_toolchain.rs @@ -46,7 +46,12 @@ fn install_toolchain(toolchain: &Toolchain) -> TResult<()> { let rustup = RustupCommand::new() .with_stdout() .with_stderr() - .with_args(["--profile", "minimal", &format!("{}", toolchain.version())]) + .with_args([ + "--no-self-update", + "--profile", + "minimal", + &format!("{}", toolchain.version()), + ]) .install()?; let status = rustup.exit_status(); diff --git a/src/search_method/bisect.rs b/src/search_method/bisect.rs index f76bde05..e7e8cb03 100644 --- a/src/search_method/bisect.rs +++ b/src/search_method/bisect.rs @@ -1,21 +1,21 @@ use bisector::{Bisector, ConvergeTo, Indices, Step}; -use crate::check::Check; +use crate::compatibility::IsCompatible; use crate::context::SearchMethod; use crate::error::NoToolchainsToTryError; use crate::msrv::MinimumSupportedRustVersion; -use crate::outcome::{FailureOutcome, Outcome, SuccessOutcome}; +use crate::outcome::{Compatibility, Compatible, Incompatible}; use crate::reporter::event::{FindMsrv, Progress}; use crate::reporter::Reporter; use crate::rust::RustRelease; use crate::search_method::FindMinimalSupportedRustVersion; use crate::TResult; -pub struct Bisect<'runner, R: Check> { +pub struct Bisect<'runner, R: IsCompatible> { runner: &'runner R, } -impl<'runner, R: Check> Bisect<'runner, R> { +impl<'runner, R: IsCompatible> Bisect<'runner, R> { pub fn new(runner: &'runner R) -> Self { Self { runner } } @@ -24,13 +24,13 @@ impl<'runner, R: Check> Bisect<'runner, R> { runner: &R, release: &RustRelease, _reporter: &impl Reporter, - ) -> TResult> { + ) -> TResult> { let toolchain = release.to_toolchain_spec(); - match runner.check(&toolchain) { + match runner.is_compatible(&toolchain) { Ok(outcome) => match outcome { - Outcome::Success(outcome) => Ok(ConvergeTo::Right(outcome)), - Outcome::Failure(outcome) => Ok(ConvergeTo::Left(outcome)), + Compatibility::Compatible(outcome) => Ok(ConvergeTo::Right(outcome)), + Compatibility::Incompatible(outcome) => Ok(ConvergeTo::Left(outcome)), }, Err(err) => Err(err), } @@ -50,7 +50,7 @@ impl<'runner, R: Check> Bisect<'runner, R> { } } -impl<'runner, R: Check> FindMinimalSupportedRustVersion for Bisect<'runner, R> { +impl<'runner, R: IsCompatible> FindMinimalSupportedRustVersion for Bisect<'runner, R> { fn find_toolchain( &self, search_space: &[RustRelease], @@ -117,7 +117,7 @@ impl<'runner, R: Check> FindMinimalSupportedRustVersion for Bisect<'runner, R> { mod tests { use rust_releases::Release; - use crate::check::TestRunner; + use crate::compatibility::TestRunner; use crate::reporter::TestReporterWrapper; use crate::rust::RustRelease; use crate::search_method::FindMinimalSupportedRustVersion; diff --git a/src/search_method/linear.rs b/src/search_method/linear.rs index b7557fcb..1bacd52d 100644 --- a/src/search_method/linear.rs +++ b/src/search_method/linear.rs @@ -1,30 +1,34 @@ -use crate::check::Check; +use crate::compatibility::IsCompatible; use crate::context::SearchMethod; use crate::error::NoToolchainsToTryError; use crate::msrv::MinimumSupportedRustVersion; -use crate::outcome::Outcome; +use crate::outcome::Compatibility; use crate::reporter::event::{FindMsrv, Progress}; use crate::reporter::Reporter; use crate::rust::RustRelease; use crate::search_method::FindMinimalSupportedRustVersion; use crate::TResult; -pub struct Linear<'runner, R: Check> { +pub struct Linear<'runner, R: IsCompatible> { runner: &'runner R, } -impl<'runner, R: Check> Linear<'runner, R> { +impl<'runner, R: IsCompatible> Linear<'runner, R> { pub fn new(runner: &'runner R) -> Self { Self { runner } } - fn run_check(runner: &R, release: &RustRelease, _reporter: &impl Reporter) -> TResult { + fn run_check( + runner: &R, + release: &RustRelease, + _reporter: &impl Reporter, + ) -> TResult { let toolchain = release.to_toolchain_spec(); - runner.check(&toolchain) + runner.is_compatible(&toolchain) } } -impl<'runner, R: Check> FindMinimalSupportedRustVersion for Linear<'runner, R> { +impl<'runner, R: IsCompatible> FindMinimalSupportedRustVersion for Linear<'runner, R> { fn find_toolchain( &self, search_space: &[RustRelease], @@ -47,10 +51,10 @@ impl<'runner, R: Check> FindMinimalSupportedRustVersion for Linear<'runner, R> { let outcome = Self::run_check(self.runner, release, reporter)?; match outcome { - Outcome::Failure(_outcome) => { + Compatibility::Incompatible(_outcome) => { break; } - Outcome::Success(_outcome) => {} + Compatibility::Compatible(_outcome) => {} } last_compatible_index = Some(i); @@ -66,7 +70,7 @@ impl<'runner, R: Check> FindMinimalSupportedRustVersion for Linear<'runner, R> { #[cfg(test)] mod tests { use super::*; - use crate::check::TestRunner; + use crate::compatibility::TestRunner; use crate::reporter::TestReporterWrapper; use crate::rust::Toolchain; use crate::semver; diff --git a/src/sub_command/find/mod.rs b/src/sub_command/find/mod.rs index f84560dd..94791653 100644 --- a/src/sub_command/find/mod.rs +++ b/src/sub_command/find/mod.rs @@ -1,6 +1,6 @@ use rust_releases::{Release, ReleaseIndex}; -use crate::check::Check; +use crate::compatibility::IsCompatible; use crate::context::{FindContext, SearchMethod}; use crate::error::{CargoMSRVError, NoToolchainsToTryError, TResult}; use crate::manifest::bare_version::BareVersion; @@ -14,12 +14,12 @@ use crate::writer::toolchain_file::write_toolchain_file; use crate::writer::write_msrv::write_msrv; use crate::{semver, SubCommand}; -pub struct Find<'index, C: Check> { +pub struct Find<'index, C: IsCompatible> { release_index: &'index ReleaseIndex, runner: C, } -impl<'index, C: Check> Find<'index, C> { +impl<'index, C: IsCompatible> Find<'index, C> { pub fn new(release_index: &'index ReleaseIndex, runner: C) -> Self { Self { release_index, @@ -28,7 +28,7 @@ impl<'index, C: Check> Find<'index, C> { } } -impl<'index, C: Check> SubCommand for Find<'index, C> { +impl<'index, C: IsCompatible> SubCommand for Find<'index, C> { type Context = FindContext; type Output = semver::Version; @@ -41,7 +41,7 @@ fn find_msrv( ctx: &FindContext, reporter: &impl Reporter, release_index: &ReleaseIndex, - runner: &impl Check, + runner: &impl IsCompatible, ) -> TResult { let search_result = search(ctx, reporter, release_index, runner)?; @@ -89,7 +89,7 @@ fn search( ctx: &FindContext, reporter: &impl Reporter, index: &ReleaseIndex, - runner: &impl Check, + runner: &impl IsCompatible, ) -> TResult { let releases = index.releases(); @@ -111,7 +111,7 @@ fn run_with_search_method( ctx: &FindContext, included_releases: &[Release], reporter: &impl Reporter, - runner: &impl Check, + runner: &impl IsCompatible, ) -> TResult { let search_method = ctx.search_method; info!(?search_method); diff --git a/src/sub_command/find/tests.rs b/src/sub_command/find/tests.rs index e041244f..efa73e2f 100644 --- a/src/sub_command/find/tests.rs +++ b/src/sub_command/find/tests.rs @@ -1,5 +1,5 @@ use super::*; -use crate::check::TestRunner; +use crate::compatibility::TestRunner; use crate::context::{ CheckCommandContext, EnvironmentContext, ReleaseSource, RustReleasesContext, ToolchainContext, WorkspacePackages, diff --git a/src/sub_command/verify.rs b/src/sub_command/verify.rs index b964b445..8cba966b 100644 --- a/src/sub_command/verify.rs +++ b/src/sub_command/verify.rs @@ -4,24 +4,24 @@ use std::convert::TryFrom; use rust_releases::{Release, ReleaseIndex}; -use crate::check::Check; +use crate::compatibility::IsCompatible; use crate::context::{EnvironmentContext, VerifyContext}; use crate::error::{CargoMSRVError, TResult}; use crate::manifest::bare_version::BareVersion; use crate::manifest::CargoManifest; -use crate::outcome::Outcome; +use crate::outcome::Compatibility; use crate::reporter::event::VerifyResult; use crate::reporter::Reporter; use crate::rust::Toolchain; use crate::sub_command::SubCommand; /// Verifier which determines whether a given Rust version is deemed compatible or not. -pub struct Verify<'index, C: Check> { +pub struct Verify<'index, C: IsCompatible> { release_index: &'index ReleaseIndex, runner: C, } -impl<'index, C: Check> Verify<'index, C> { +impl<'index, C: IsCompatible> Verify<'index, C> { /// Instantiate the verifier using a release index and a runner. /// /// The runner is used to determine whether a given Rust version will be deemed compatible or not. @@ -33,7 +33,7 @@ impl<'index, C: Check> Verify<'index, C> { } } -impl<'index, C: Check> SubCommand for Verify<'index, C> { +impl<'index, C: IsCompatible> SubCommand for Verify<'index, C> { type Context = VerifyContext; type Output = (); @@ -61,7 +61,7 @@ fn verify_msrv( ctx: &VerifyContext, release_index: &ReleaseIndex, rust_version: RustVersion, - runner: &impl Check, + runner: &impl IsCompatible, ) -> TResult<()> { let bare_version = rust_version.version(); let version = @@ -71,9 +71,11 @@ fn verify_msrv( let components = ctx.toolchain.components; let toolchain = Toolchain::new(version.clone(), target, components); - match runner.check(&toolchain)? { - Outcome::Success(_) => success(reporter, toolchain), - Outcome::Failure(f) => failure(reporter, toolchain, rust_version, Some(f.error_message)), + match runner.is_compatible(&toolchain)? { + Compatibility::Compatible(_) => success(reporter, toolchain), + Compatibility::Incompatible(f) => { + failure(reporter, toolchain, rust_version, Some(f.error_message)) + } } } diff --git a/tests/common/runner.rs b/tests/common/runner.rs index a35995f4..99f1072a 100644 --- a/tests/common/runner.rs +++ b/tests/common/runner.rs @@ -5,10 +5,10 @@ use std::collections::HashSet; -use cargo_msrv::check::Check; +use cargo_msrv::compatibility::IsCompatible; use cargo_msrv::error::CargoMSRVError; use cargo_msrv::rust::Toolchain; -use cargo_msrv::Outcome; +use cargo_msrv::Compatibility; use rust_releases::semver::Version; pub struct TestRunner { @@ -25,19 +25,19 @@ impl TestRunner { } } -impl Check for TestRunner { - fn check(&self, toolchain: &Toolchain) -> Result { +impl IsCompatible for TestRunner { + fn is_compatible(&self, toolchain: &Toolchain) -> Result { let version = toolchain.version(); let components = toolchain.components(); if self.accept_versions.contains(toolchain.version()) { - Ok(Outcome::new_success(Toolchain::new( + Ok(Compatibility::new_success(Toolchain::new( version.clone(), self.target, components, ))) } else { - Ok(Outcome::new_failure( + Ok(Compatibility::new_failure( Toolchain::new(version.clone(), self.target, components), "f".to_string(), )) diff --git a/tests/common/sub_cmd_find.rs b/tests/common/sub_cmd_find.rs index b29c3580..500fd3a8 100644 --- a/tests/common/sub_cmd_find.rs +++ b/tests/common/sub_cmd_find.rs @@ -1,6 +1,6 @@ use crate::common::reporter::EventTestDevice; -use cargo_msrv::check::RustupToolchainCheck; use cargo_msrv::cli::CargoCli; +use cargo_msrv::compatibility::RustupToolchainCheck; use cargo_msrv::error::CargoMSRVError; use cargo_msrv::reporter::{Message, SubcommandResult}; use cargo_msrv::{Context, Find, SubCommand}; diff --git a/tests/common/sub_cmd_verify.rs b/tests/common/sub_cmd_verify.rs index cdac0d11..5b6ae3cf 100644 --- a/tests/common/sub_cmd_verify.rs +++ b/tests/common/sub_cmd_verify.rs @@ -1,6 +1,6 @@ use crate::common::reporter::EventTestDevice; -use cargo_msrv::check::RustupToolchainCheck; use cargo_msrv::cli::CargoCli; +use cargo_msrv::compatibility::RustupToolchainCheck; use cargo_msrv::error::CargoMSRVError; use cargo_msrv::{Context, SubCommand, Verify}; use rust_releases::{Release, ReleaseIndex};