Combined newer versions into single list

This commit is contained in:
Aaron Hill 2021-10-08 15:28:35 -05:00
parent ce259228cd
commit 49ae189b3b
No known key found for this signature in database
GPG Key ID: B4087E510E98B164
2 changed files with 22 additions and 60 deletions

View File

@ -954,28 +954,15 @@ impl<'cfg> DrainState<'cfg> {
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join("\n"); .join("\n");
let (compat, incompat) = let updated_versions =
get_updates(bcx.ws, &package_ids).unwrap_or((String::new(), String::new())); get_updates(bcx.ws, &package_ids).unwrap_or(String::new());
let compat_message = if !compat.is_empty() { let update_message = if !updated_versions.is_empty() {
format!( format!(
" "
- Some affected dependencies have minor or patch version updates available: - Some affected dependencies have updates available:
{compat}", {updated_versions}",
compat = compat updated_versions = updated_versions
)
} else {
String::new()
};
let incompat_message = if !incompat.is_empty() {
format!(
"
- If a minor dependency update does not help, you can try updating to a new
major version of those dependencies. You have to do this manually:
{incompat}
",
incompat = incompat
) )
} else { } else {
String::new() String::new()
@ -985,8 +972,7 @@ impl<'cfg> DrainState<'cfg> {
" "
To solve this problem, you can try the following approaches: To solve this problem, you can try the following approaches:
{compat_message} {update_message}
{incompat_message}
- If the issue is not solved by updating the dependencies, a fix has to be - If the issue is not solved by updating the dependencies, a fix has to be
implemented by those dependencies. You can help with that by notifying the implemented by those dependencies. You can help with that by notifying the
maintainers of this problem (e.g. by creating a bug report) or by proposing a maintainers of this problem (e.g. by creating a bug report) or by proposing a
@ -999,8 +985,7 @@ To solve this problem, you can try the following approaches:
https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section
", ",
upstream_info = upstream_info, upstream_info = upstream_info,
compat_message = compat_message, update_message = update_message,
incompat_message = incompat_message
))); )));
drop(bcx.config.shell().note(&format!( drop(bcx.config.shell().note(&format!(
@ -1354,7 +1339,7 @@ feature resolver. Try updating to diesel 1.4.8 to fix this error.
// Returns a pair (compatible_updates, incompatible_updates), // Returns a pair (compatible_updates, incompatible_updates),
// of semver-compatible and semver-incompatible update versions, // of semver-compatible and semver-incompatible update versions,
// respectively. // respectively.
fn get_updates(ws: &Workspace<'_>, package_ids: &BTreeSet<PackageId>) -> Option<(String, String)> { fn get_updates(ws: &Workspace<'_>, package_ids: &BTreeSet<PackageId>) -> Option<String> {
// This in general ignores all errors since this is opportunistic. // This in general ignores all errors since this is opportunistic.
let _lock = ws.config().acquire_package_cache_lock().ok()?; let _lock = ws.config().acquire_package_cache_lock().ok()?;
// Create a set of updated registry sources. // Create a set of updated registry sources.
@ -1375,8 +1360,7 @@ fn get_updates(ws: &Workspace<'_>, package_ids: &BTreeSet<PackageId>) -> Option<
}) })
.collect(); .collect();
// Query the sources for new versions. // Query the sources for new versions.
let mut compatible = String::new(); let mut updates = String::new();
let mut incompatible = String::new();
for pkg_id in package_ids { for pkg_id in package_ids {
let source = match sources.get_mut(&pkg_id.source_id()) { let source = match sources.get_mut(&pkg_id.source_id()) {
Some(s) => s, Some(s) => s,
@ -1384,41 +1368,24 @@ fn get_updates(ws: &Workspace<'_>, package_ids: &BTreeSet<PackageId>) -> Option<
}; };
let dep = Dependency::parse(pkg_id.name(), None, pkg_id.source_id()).ok()?; let dep = Dependency::parse(pkg_id.name(), None, pkg_id.source_id()).ok()?;
let summaries = source.query_vec(&dep).ok()?; let summaries = source.query_vec(&dep).ok()?;
let (mut compatible_versions, mut incompatible_versions): (Vec<_>, Vec<_>) = summaries let mut updated_versions: Vec<_> = summaries.iter().map(|summary| summary.version())
.iter()
.map(|summary| summary.version())
.filter(|version| *version > pkg_id.version()) .filter(|version| *version > pkg_id.version())
.partition(|version| version.major == pkg_id.version().major); .collect();
compatible_versions.sort(); updated_versions.sort();
incompatible_versions.sort();
let compatible_versions = compatible_versions let updated_versions = iter_join(updated_versions
.into_iter() .into_iter()
.map(|version| version.to_string()); .map(|version| version.to_string()),
let compatible_versions = iter_join(compatible_versions, ", "); ", ");
let incompatible_versions = incompatible_versions if !updated_versions.is_empty() {
.into_iter()
.map(|version| version.to_string());
let incompatible_versions = iter_join(incompatible_versions, ", ");
if !compatible_versions.is_empty() {
writeln!( writeln!(
compatible, updates,
"{} has the following newer versions available: {}", "{} has the following newer versions available: {}",
pkg_id, compatible_versions pkg_id, updated_versions
)
.unwrap();
}
if !incompatible_versions.is_empty() {
writeln!(
incompatible,
"{} has the following newer versions available: {}",
pkg_id, incompatible_versions
) )
.unwrap(); .unwrap();
} }
} }
Some((compatible, incompatible)) Some(updates)
} }

View File

@ -424,14 +424,9 @@ fn suggestions_for_updates() {
.env("RUSTFLAGS", "-Zfuture-incompat-test") .env("RUSTFLAGS", "-Zfuture-incompat-test")
.with_stderr_contains( .with_stderr_contains(
"\ "\
- Some affected dependencies have minor or patch version updates available: - Some affected dependencies have updates available:
with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2
- If a minor dependency update does not help, you can try updating to a new
major version of those dependencies. You have to do this manually:
big_update v1.0.0 has the following newer versions available: 2.0.0 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: 3.0.1 with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3.0.1
", ",
) )
.run(); .run();