mirror of https://github.com/rust-lang/cargo
Auto merge of #13738 - epage:msrv, r=Muscraft
feat(reslve): Respect '--ignore-rust-version' ### What does this PR try to resolve? This is a part of #9930. ### How should we test and review this PR? I had considered several ways of implementing this. I first looked at passing this into `ops::resolve*`. .This would get a bit annoying with the function signature, so I considered moving it to a builder.. Each of the entry points is slightly different with different ownership needs, making it hard to have a common abstraction. In doing this, I noticed we currently pass some state around to the resolver via `Workspace`, so I mirrored that. The nice thing about this location is it provides a good place to hook in config and `package.resolve` so they affect this. ### Additional information
This commit is contained in:
commit
c375398f3b
|
@ -100,6 +100,7 @@ pub struct Workspace<'gctx> {
|
||||||
|
|
||||||
/// The resolver behavior specified with the `resolver` field.
|
/// The resolver behavior specified with the `resolver` field.
|
||||||
resolve_behavior: ResolveBehavior,
|
resolve_behavior: ResolveBehavior,
|
||||||
|
honor_rust_version: Option<bool>,
|
||||||
|
|
||||||
/// Workspace-level custom metadata
|
/// Workspace-level custom metadata
|
||||||
custom_metadata: Option<toml::Value>,
|
custom_metadata: Option<toml::Value>,
|
||||||
|
@ -229,6 +230,7 @@ impl<'gctx> Workspace<'gctx> {
|
||||||
loaded_packages: RefCell::new(HashMap::new()),
|
loaded_packages: RefCell::new(HashMap::new()),
|
||||||
ignore_lock: false,
|
ignore_lock: false,
|
||||||
resolve_behavior: ResolveBehavior::V1,
|
resolve_behavior: ResolveBehavior::V1,
|
||||||
|
honor_rust_version: None,
|
||||||
custom_metadata: None,
|
custom_metadata: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -605,6 +607,14 @@ impl<'gctx> Workspace<'gctx> {
|
||||||
self.members().filter_map(|pkg| pkg.rust_version()).min()
|
self.members().filter_map(|pkg| pkg.rust_version()).min()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_honor_rust_version(&mut self, honor_rust_version: Option<bool>) {
|
||||||
|
self.honor_rust_version = honor_rust_version;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn resolve_honors_rust_version(&self) -> bool {
|
||||||
|
self.gctx().cli_unstable().msrv_policy && self.honor_rust_version.unwrap_or(true)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn custom_metadata(&self) -> Option<&toml::Value> {
|
pub fn custom_metadata(&self) -> Option<&toml::Value> {
|
||||||
self.custom_metadata.as_ref()
|
self.custom_metadata.as_ref()
|
||||||
}
|
}
|
||||||
|
@ -771,7 +781,7 @@ impl<'gctx> Workspace<'gctx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("find_members - {}", manifest_path.display());
|
debug!("find_path_deps - {}", manifest_path.display());
|
||||||
self.members.push(manifest_path.clone());
|
self.members.push(manifest_path.clone());
|
||||||
|
|
||||||
let candidates = {
|
let candidates = {
|
||||||
|
|
|
@ -303,7 +303,7 @@ pub fn resolve_with_previous<'gctx>(
|
||||||
if ws.gctx().cli_unstable().minimal_versions {
|
if ws.gctx().cli_unstable().minimal_versions {
|
||||||
version_prefs.version_ordering(VersionOrdering::MinimumVersionsFirst)
|
version_prefs.version_ordering(VersionOrdering::MinimumVersionsFirst)
|
||||||
}
|
}
|
||||||
if ws.gctx().cli_unstable().msrv_policy {
|
if ws.resolve_honors_rust_version() {
|
||||||
version_prefs.max_rust_version(ws.rust_version().cloned().map(RustVersion::into_partial));
|
version_prefs.max_rust_version(ws.rust_version().cloned().map(RustVersion::into_partial));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -504,6 +504,7 @@ pub trait ArgMatchesExt {
|
||||||
fn workspace<'a>(&self, gctx: &'a GlobalContext) -> CargoResult<Workspace<'a>> {
|
fn workspace<'a>(&self, gctx: &'a GlobalContext) -> CargoResult<Workspace<'a>> {
|
||||||
let root = self.root_manifest(gctx)?;
|
let root = self.root_manifest(gctx)?;
|
||||||
let mut ws = Workspace::new(&root, gctx)?;
|
let mut ws = Workspace::new(&root, gctx)?;
|
||||||
|
ws.set_honor_rust_version(self.honor_rust_version());
|
||||||
if gctx.cli_unstable().avoid_dev_deps {
|
if gctx.cli_unstable().avoid_dev_deps {
|
||||||
ws.set_require_optional_deps(false);
|
ws.set_require_optional_deps(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -347,15 +347,13 @@ fn dependency_rust_version_older_and_newer_than_package() {
|
||||||
p.cargo("check --ignore-rust-version")
|
p.cargo("check --ignore-rust-version")
|
||||||
.arg("-Zmsrv-policy")
|
.arg("-Zmsrv-policy")
|
||||||
.masquerade_as_nightly_cargo(&["msrv-policy"])
|
.masquerade_as_nightly_cargo(&["msrv-policy"])
|
||||||
// This should pick 1.6.0
|
|
||||||
.with_stderr(
|
.with_stderr(
|
||||||
"\
|
"\
|
||||||
[UPDATING] `dummy-registry` index
|
[UPDATING] `dummy-registry` index
|
||||||
[LOCKING] 2 packages
|
[LOCKING] 2 packages
|
||||||
[ADDING] bar v1.5.0 (latest: v1.6.0)
|
|
||||||
[DOWNLOADING] crates ...
|
[DOWNLOADING] crates ...
|
||||||
[DOWNLOADED] bar v1.5.0 (registry `dummy-registry`)
|
[DOWNLOADED] bar v1.6.0 (registry `dummy-registry`)
|
||||||
[CHECKING] bar v1.5.0
|
[CHECKING] bar v1.6.0
|
||||||
[CHECKING] [..]
|
[CHECKING] [..]
|
||||||
[FINISHED] [..]
|
[FINISHED] [..]
|
||||||
",
|
",
|
||||||
|
@ -483,15 +481,13 @@ fn workspace_with_mixed_rust_version() {
|
||||||
p.cargo("check --ignore-rust-version")
|
p.cargo("check --ignore-rust-version")
|
||||||
.arg("-Zmsrv-policy")
|
.arg("-Zmsrv-policy")
|
||||||
.masquerade_as_nightly_cargo(&["msrv-policy"])
|
.masquerade_as_nightly_cargo(&["msrv-policy"])
|
||||||
// This should pick 1.6.0
|
|
||||||
.with_stderr(
|
.with_stderr(
|
||||||
"\
|
"\
|
||||||
[UPDATING] `dummy-registry` index
|
[UPDATING] `dummy-registry` index
|
||||||
[LOCKING] 3 packages
|
[LOCKING] 3 packages
|
||||||
[ADDING] bar v1.4.0 (latest: v1.6.0)
|
|
||||||
[DOWNLOADING] crates ...
|
[DOWNLOADING] crates ...
|
||||||
[DOWNLOADED] bar v1.4.0 (registry `dummy-registry`)
|
[DOWNLOADED] bar v1.6.0 (registry `dummy-registry`)
|
||||||
[CHECKING] bar v1.4.0
|
[CHECKING] bar v1.6.0
|
||||||
[CHECKING] [..]
|
[CHECKING] [..]
|
||||||
[FINISHED] [..]
|
[FINISHED] [..]
|
||||||
",
|
",
|
||||||
|
|
Loading…
Reference in New Issue