Skip to content

Commit

Permalink
Display update message in report
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron1011 committed Oct 12, 2021
1 parent 704540d commit 6f18507
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
14 changes: 12 additions & 2 deletions src/cargo/core/compiler/future_incompat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -205,7 +213,7 @@ impl OnDiskReports {
iter_join(report.per_package.keys(), ", ")
)
})?
.clone()
.to_string()
} else {
report
.per_package
Expand All @@ -214,6 +222,8 @@ impl OnDiskReports {
.collect::<Vec<_>>()
.join("\n")
};
to_display += &package_report;

let to_display = if config.shell().err_supports_color() {
to_display
} else {
Expand Down
36 changes: 20 additions & 16 deletions src/cargo/core/compiler/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -953,20 +971,6 @@ impl<'cfg> DrainState<'cfg> {
})
.collect::<Vec<_>>()
.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:
Expand Down
21 changes: 14 additions & 7 deletions tests/testsuite/future_incompat_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit 6f18507

Please sign in to comment.