Skip to content

Commit

Permalink
Override to resolver=1 in published package
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo157 committed Jul 29, 2022
1 parent 015143c commit 288f087
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/cargo/core/resolver/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ impl ResolveBehavior {
}
}

pub fn to_manifest(&self) -> Option<String> {
pub fn to_manifest(&self) -> String {
match self {
ResolveBehavior::V1 => None,
ResolveBehavior::V2 => Some("2".to_string()),
ResolveBehavior::V1 => "1",
ResolveBehavior::V2 => "2",
}
.to_owned()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ impl TomlManifest {
.unwrap()
.clone();
package.workspace = None;
package.resolver = ws.resolve_behavior().to_manifest();
package.resolver = Some(ws.resolve_behavior().to_manifest());
if let Some(license_file) = &package.license_file {
let license_file = license_file
.as_defined()
Expand Down
43 changes: 43 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2325,3 +2325,46 @@ See [..]
assert!(p.root().join("target/package/foo-0.0.1.crate").is_file());
assert!(p.root().join("target/package/bar-0.0.1.crate").is_file());
}

#[cargo_test]
fn workspace_overrides_resolver() {
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["bar"]
"#,
)
.file(
"bar/Cargo.toml",
r#"
[package]
name = "bar"
version = "0.1.0"
edition = "2021"
"#,
)
.file("bar/src/lib.rs", "")
.build();

p.cargo("package --no-verify").cwd("bar").run();

let f = File::open(&p.root().join("target/package/bar-0.1.0.crate")).unwrap();
let rewritten_toml = format!(
r#"{}
[package]
edition = "2021"
name = "bar"
version = "0.1.0"
resolver = "1"
"#,
cargo::core::package::MANIFEST_PREAMBLE
);
validate_crate_contents(
f,
"bar-0.1.0.crate",
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
&[("Cargo.toml", &rewritten_toml)],
);
}

0 comments on commit 288f087

Please sign in to comment.