From 6f18507092bc6e0ede00394f7d1080633f9f6752 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 12 Oct 2021 16:48:56 -0500 Subject: [PATCH] Display update message in report --- src/cargo/core/compiler/future_incompat.rs | 14 +++++++-- src/cargo/core/compiler/job_queue.rs | 36 ++++++++++++---------- tests/testsuite/future_incompat_report.rs | 21 ++++++++----- 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/src/cargo/core/compiler/future_incompat.rs b/src/cargo/core/compiler/future_incompat.rs index 7772442f38b..8955f1ed058 100644 --- a/src/cargo/core/compiler/future_incompat.rs +++ b/src/cargo/core/compiler/future_incompat.rs @@ -75,6 +75,9 @@ pub struct OnDiskReports { struct OnDiskReport { /// Unique reference to the report for the `--id` CLI flag. id: u32, + /// A (possibly empty) message describing which affected + /// packages have newer versions available + update_message: String, /// Report, suitable for printing to the console. /// Maps package names to the corresponding report /// We use a `BTreeMap` so that the iteration order @@ -96,6 +99,7 @@ impl OnDiskReports { /// Saves a new report. pub fn save_report( ws: &Workspace<'_>, + update_message: String, per_package_reports: &[FutureIncompatReportPackage], ) -> OnDiskReports { let mut current_reports = match Self::load(ws) { @@ -110,6 +114,7 @@ impl OnDiskReports { }; let report = OnDiskReport { id: current_reports.next_id, + update_message, per_package: render_report(per_package_reports), }; current_reports.next_id += 1; @@ -192,7 +197,10 @@ impl OnDiskReports { available ) })?; - let to_display = if let Some(package) = package { + + let mut to_display = report.update_message.clone(); + + let package_report = if let Some(package) = package { report .per_package .get(package) @@ -205,7 +213,7 @@ impl OnDiskReports { iter_join(report.per_package.keys(), ", ") ) })? - .clone() + .to_string() } else { report .per_package @@ -214,6 +222,8 @@ impl OnDiskReports { .collect::>() .join("\n") }; + to_display += &package_report; + let to_display = if config.shell().err_supports_color() { to_display } else { diff --git a/src/cargo/core/compiler/job_queue.rs b/src/cargo/core/compiler/job_queue.rs index 9a126d0ddb6..55710682029 100644 --- a/src/cargo/core/compiler/job_queue.rs +++ b/src/cargo/core/compiler/job_queue.rs @@ -928,8 +928,26 @@ impl<'cfg> DrainState<'cfg> { ))); } - let on_disk_reports = - OnDiskReports::save_report(bcx.ws, &self.per_package_future_incompat_reports); + let updated_versions = get_updates(bcx.ws, &package_ids).unwrap_or(String::new()); + + let update_message = if !updated_versions.is_empty() { + format!( + " +- Some affected dependencies have newer versions available. +You may want to consider updating them to a newer version to see if the issue has been fixed. + +{updated_versions}\n", + updated_versions = updated_versions + ) + } else { + String::new() + }; + + let on_disk_reports = OnDiskReports::save_report( + bcx.ws, + update_message.clone(), + &self.per_package_future_incompat_reports, + ); let report_id = on_disk_reports.last_id(); if bcx.build_config.future_incompat_report { @@ -953,20 +971,6 @@ impl<'cfg> DrainState<'cfg> { }) .collect::>() .join("\n"); - - let updated_versions = get_updates(bcx.ws, &package_ids).unwrap_or(String::new()); - - let update_message = if !updated_versions.is_empty() { - format!( - " -- Some affected dependencies have updates available: -{updated_versions}", - updated_versions = updated_versions - ) - } else { - String::new() - }; - drop(bcx.config.shell().note(&format!( " To solve this problem, you can try the following approaches: diff --git a/tests/testsuite/future_incompat_report.rs b/tests/testsuite/future_incompat_report.rs index 539ffce5c0a..a11c38cd61c 100644 --- a/tests/testsuite/future_incompat_report.rs +++ b/tests/testsuite/future_incompat_report.rs @@ -419,15 +419,22 @@ fn suggestions_for_updates() { // in a long while?). p.cargo("update -p without_updates").run(); + let update_message = "\ +- Some affected dependencies have newer versions available. +You may want to consider updating them to a newer version to see if the issue has been fixed. + +big_update v1.0.0 has the following newer versions available: 2.0.0 +with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3.0.1 +"; + p.cargo("check -Zfuture-incompat-report -Zunstable-options --future-incompat-report") .masquerade_as_nightly_cargo() .env("RUSTFLAGS", "-Zfuture-incompat-test") - .with_stderr_contains( - "\ -- Some affected dependencies have updates available: -big_update v1.0.0 has the following newer versions available: 2.0.0 -with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3.0.1 -", - ) + .with_stderr_contains(update_message) .run(); + + p.cargo("report future-incompatibilities") + .masquerade_as_nightly_cargo() + .with_stdout_contains(update_message) + .run() }