Skip to content

Commit

Permalink
feat(reslve): Respect '--ignore-rust-version'
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Apr 11, 2024
1 parent 11448b4 commit cd3d31b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub struct Workspace<'gctx> {

/// The resolver behavior specified with the `resolver` field.
resolve_behavior: ResolveBehavior,
honor_rust_version: Option<bool>,

/// Workspace-level custom metadata
custom_metadata: Option<toml::Value>,
Expand Down Expand Up @@ -229,6 +230,7 @@ impl<'gctx> Workspace<'gctx> {
loaded_packages: RefCell::new(HashMap::new()),
ignore_lock: false,
resolve_behavior: ResolveBehavior::V1,
honor_rust_version: None,
custom_metadata: None,
}
}
Expand Down Expand Up @@ -605,8 +607,12 @@ impl<'gctx> Workspace<'gctx> {
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.gctx().cli_unstable().msrv_policy && self.honor_rust_version.unwrap_or(true)
}

pub fn custom_metadata(&self) -> Option<&toml::Value> {
Expand Down
1 change: 1 addition & 0 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ pub trait ArgMatchesExt {
fn workspace<'a>(&self, gctx: &'a GlobalContext) -> CargoResult<Workspace<'a>> {
let root = self.root_manifest(gctx)?;
let mut ws = Workspace::new(&root, gctx)?;
ws.set_honor_rust_version(self.honor_rust_version());
if gctx.cli_unstable().avoid_dev_deps {
ws.set_require_optional_deps(false);
}
Expand Down
12 changes: 4 additions & 8 deletions tests/testsuite/rust_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,13 @@ fn dependency_rust_version_older_and_newer_than_package() {
p.cargo("check --ignore-rust-version")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
// This should pick 1.6.0
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages
[ADDING] bar v1.5.0 (latest: v1.6.0)
[DOWNLOADING] crates ...
[DOWNLOADED] bar v1.5.0 (registry `dummy-registry`)
[CHECKING] bar v1.5.0
[DOWNLOADED] bar v1.6.0 (registry `dummy-registry`)
[CHECKING] bar v1.6.0
[CHECKING] [..]
[FINISHED] [..]
",
Expand Down Expand Up @@ -483,15 +481,13 @@ fn workspace_with_mixed_rust_version() {
p.cargo("check --ignore-rust-version")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
// This should pick 1.6.0
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 3 packages
[ADDING] bar v1.4.0 (latest: v1.6.0)
[DOWNLOADING] crates ...
[DOWNLOADED] bar v1.4.0 (registry `dummy-registry`)
[CHECKING] bar v1.4.0
[DOWNLOADED] bar v1.6.0 (registry `dummy-registry`)
[CHECKING] bar v1.6.0
[CHECKING] [..]
[FINISHED] [..]
",
Expand Down

0 comments on commit cd3d31b

Please sign in to comment.