-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(resolver): Add CLI option to resolve minimal version dependencies #5200
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
Changes from 4 commits
9a09892
2a47b6a
f2610df
5907a8b
115d356
131c3e2
a38184f
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 |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ use hamcrest::{assert_that, contains, is_not}; | |
| use cargo::core::source::{GitReference, SourceId}; | ||
| use cargo::core::dependency::Kind::{self, Development}; | ||
| use cargo::core::{Dependency, PackageId, Registry, Summary}; | ||
| use cargo::util::{CargoResult, ToUrl}; | ||
| use cargo::util::{CargoResult, Config, ToUrl}; | ||
| use cargo::core::resolver::{self, Method}; | ||
|
|
||
| fn resolve( | ||
|
|
@@ -45,6 +45,45 @@ fn resolve( | |
| Ok(res) | ||
| } | ||
|
|
||
| // Clone of resolve() from above that also passes down a Config instance. | ||
|
Contributor
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 am not fond of the copy/paste code duplication, but if @klausi thinks that it is the best solution I am ok with it. |
||
| fn resolve_with_config( | ||
| pkg: &PackageId, | ||
| deps: Vec<Dependency>, | ||
| registry: &[Summary], | ||
| config: &Config, | ||
| ) -> CargoResult<Vec<PackageId>> { | ||
| struct MyRegistry<'a>(&'a [Summary]); | ||
| impl<'a> Registry for MyRegistry<'a> { | ||
| fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> { | ||
| for summary in self.0.iter() { | ||
| if dep.matches(summary) { | ||
| f(summary.clone()); | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
| fn supports_checksums(&self) -> bool { | ||
| false | ||
| } | ||
| fn requires_precise(&self) -> bool { | ||
| false | ||
| } | ||
| } | ||
| let mut registry = MyRegistry(registry); | ||
| let summary = Summary::new(pkg.clone(), deps, BTreeMap::new(), None).unwrap(); | ||
| let method = Method::Everything; | ||
| let resolve = resolver::resolve( | ||
| &[(summary, method)], | ||
| &[], | ||
| &mut registry, | ||
| &HashSet::new(), | ||
| Some(config), | ||
| false, | ||
| )?; | ||
| let res = resolve.iter().cloned().collect(); | ||
| Ok(res) | ||
| } | ||
|
|
||
| trait ToDep { | ||
| fn to_dep(self) -> Dependency; | ||
| } | ||
|
|
@@ -320,6 +359,48 @@ fn test_resolving_maximum_version_with_transitive_deps() { | |
| assert_that(&res, is_not(contains(names(&[("util", "1.1.1")])))); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_resolving_minimum_version_with_transitive_deps() { | ||
|
Contributor
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 really like this test, it concisely demonstrates both properties of Also @alexcrichton, do you think this needs a full integration test that calls
Member
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. Oh sorry I missed this. Yeah @klausi mind adding a small integration test to ensure that the flag is plumbed to the right location?
Contributor
Author
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. done! |
||
| let reg = registry(vec![ | ||
| pkg!(("util", "1.2.2")), | ||
| pkg!(("util", "1.0.0")), | ||
| pkg!(("util", "1.1.1")), | ||
| pkg!("foo" => [dep_req("util", "1.0.0")]), | ||
| pkg!("bar" => [dep_req("util", ">=1.0.1")]), | ||
| ]); | ||
|
|
||
| let mut config = Config::default().unwrap(); | ||
| config | ||
| .configure( | ||
| 1, | ||
| None, | ||
| &None, | ||
| false, | ||
| false, | ||
| &["minimal-versions".to_string()], | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| let res = resolve_with_config( | ||
| &pkg_id("root"), | ||
| vec![dep_req("foo", "1.0.0"), dep_req("bar", "1.0.0")], | ||
| ®, | ||
| &config, | ||
| ).unwrap(); | ||
|
|
||
| assert_that( | ||
| &res, | ||
| contains(names(&[ | ||
| ("root", "1.0.0"), | ||
| ("foo", "1.0.0"), | ||
| ("bar", "1.0.0"), | ||
| ("util", "1.1.1"), | ||
| ])), | ||
| ); | ||
| assert_that(&res, is_not(contains(names(&[("util", "1.2.2")])))); | ||
| assert_that(&res, is_not(contains(names(&[("util", "1.0.0")])))); | ||
| } | ||
|
|
||
| #[test] | ||
| fn resolving_incompat_versions() { | ||
| let reg = registry(vec![ | ||
|
|
||
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 needs your code from #5200 (comment). Also match on a bool is somtimes better as an
if, and the.then_with(method may be helpfull. I leave it to your judgment.