-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Print information about updated packages on cargo update. #1621
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use std::collections::HashSet; | ||
use std::collections::{HashMap, HashSet}; | ||
use std::path::Path; | ||
|
||
use core::PackageId; | ||
|
@@ -89,6 +89,21 @@ pub fn update_lockfile(manifest_path: &Path, | |
Method::Everything, | ||
Some(&previous_resolve), | ||
Some(&to_avoid))); | ||
for dep in compare_dependency_graphs(&previous_resolve, &resolve) { | ||
try!(match dep { | ||
(None, Some(pkg)) => opts.config.shell().status("Adding", | ||
format!("{} v{}", pkg.name(), pkg.version())), | ||
(Some(pkg), None) => opts.config.shell().status("Removing", | ||
format!("{} v{}", pkg.name(), pkg.version())), | ||
(Some(pkg1), Some(pkg2)) => { | ||
if pkg1.version() != pkg2.version() { | ||
opts.config.shell().status("Updating", | ||
format!("{} v{} -> v{}", pkg1.name(), pkg1.version(), pkg2.version())) | ||
} else {Ok(())} | ||
} | ||
(None, None) => unreachable!(), | ||
}); | ||
} | ||
try!(ops::write_pkg_lockfile(&package, &resolve)); | ||
return Ok(()); | ||
|
||
|
@@ -106,4 +121,23 @@ pub fn update_lockfile(manifest_path: &Path, | |
None => {} | ||
} | ||
} | ||
|
||
fn compare_dependency_graphs<'a>(previous_resolve: &'a Resolve, | ||
resolve: &'a Resolve) -> | ||
Vec<(Option<&'a PackageId>, Option<&'a PackageId>)> { | ||
let mut changes = HashMap::new(); | ||
for dep in previous_resolve.iter() { | ||
changes.insert(dep.name(), (Some(dep), None)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that this may not be quite right as it's possible to have a few different situations:
I think that this could be solved by having the key of the map being When the map is returned the left vector could represent "versions removed" and the right vector could represent "versions added". In the common case of updating a dep we'll remove one version and add one, but it could possibly be more complicated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it really possible to have multiple versions of the same package in the graph? Some time ago hyper depended indirectly on two different versions of openssl and cargo complained and did not build. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a special case because openssl was a system library (so only one is allowed), but in general multiple Rust libraries are indeed allowed. |
||
} | ||
for dep in resolve.iter() { | ||
if !changes.contains_key(dep.name()) { | ||
changes.insert(dep.name(), (None, None)); | ||
} | ||
let value = changes.get_mut(dep.name()).unwrap(); | ||
value.1 = Some(dep); | ||
} | ||
let mut package_names: Vec<&str> = changes.keys().map(|x| *x).collect(); | ||
package_names.sort(); | ||
package_names.iter().map(|name| *changes.get(name).unwrap()).collect() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you can just use |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be better structured like: