Skip to content

Commit

Permalink
Only override published resolver when the workspace is different
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo157 committed Aug 9, 2022
1 parent df0c64e commit 8b0a3ff
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 16 deletions.
21 changes: 19 additions & 2 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt;
use std::marker::PhantomData;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::str;
use std::str::{self, FromStr};

use anyhow::{anyhow, bail, Context as _};
use cargo_platform::Platform;
Expand Down Expand Up @@ -1342,7 +1342,24 @@ impl TomlManifest {
.unwrap()
.clone();
package.workspace = None;
package.resolver = Some(ws.resolve_behavior().to_manifest());
let current_resolver = package
.resolver
.as_ref()
.map(|r| ResolveBehavior::from_manifest(r))
.unwrap_or_else(|| {
package
.edition
.as_ref()
.and_then(|e| e.as_defined())
.map(|e| Edition::from_str(e))
.unwrap_or(Ok(Edition::Edition2015))
.map(|e| e.default_resolve_behavior())
})?;
if ws.resolve_behavior() != current_resolver {
// This ensures the published crate if built as a root (e.g. `cargo install`) will
// use the same resolver behavior it was tested with in the workspace.
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
2 changes: 0 additions & 2 deletions tests/testsuite/features_namespaced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,6 @@ version = "0.1.0"
description = "foo"
homepage = "https://example.com/"
license = "MIT"
resolver = "1"
[dependencies.opt-dep1]
version = "1.0"
Expand Down Expand Up @@ -1059,7 +1058,6 @@ version = "0.1.0"
description = "foo"
homepage = "https://example.com/"
license = "MIT"
resolver = "1"
[dependencies.bar]
version = "1.0"
Expand Down
5 changes: 0 additions & 5 deletions tests/testsuite/inheritable_workspace_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ keywords = ["cli"]
categories = ["development-tools"]
license = "MIT"
repository = "https://github.com/example/example"
resolver = "1"
[badges.gitlab]
branch = "master"
Expand Down Expand Up @@ -349,7 +348,6 @@ fn inherit_own_dependencies() {
name = "bar"
version = "0.2.0"
authors = []
resolver = "1"
[dependencies.dep]
version = "0.1"
Expand Down Expand Up @@ -454,7 +452,6 @@ fn inherit_own_detailed_dependencies() {
name = "bar"
version = "0.2.0"
authors = []
resolver = "1"
[dependencies.dep]
version = "0.1.2"
Expand Down Expand Up @@ -691,7 +688,6 @@ categories = ["development-tools"]
license = "MIT"
license-file = "LICENSE"
repository = "https://github.com/example/example"
resolver = "1"
[badges.gitlab]
branch = "master"
Expand Down Expand Up @@ -823,7 +819,6 @@ fn inherit_dependencies() {
name = "bar"
version = "0.2.0"
authors = []
resolver = "1"
[dependencies.dep]
version = "0.1"
Expand Down
34 changes: 30 additions & 4 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,6 @@ authors = []
exclude = ["*.txt"]
description = "foo"
license = "MIT"
resolver = "1"
[package.metadata]
foo = "bar"
Expand Down Expand Up @@ -1190,7 +1189,6 @@ fn ignore_workspace_specifier() {
name = "bar"
version = "0.1.0"
authors = []
resolver = "1"
"#,
cargo::core::package::MANIFEST_PREAMBLE
);
Expand Down Expand Up @@ -2341,7 +2339,7 @@ fn workspace_overrides_resolver() {
"Cargo.toml",
r#"
[workspace]
members = ["bar"]
members = ["bar", "baz"]
"#,
)
.file(
Expand All @@ -2354,9 +2352,19 @@ fn workspace_overrides_resolver() {
"#,
)
.file("bar/src/lib.rs", "")
.file(
"baz/Cargo.toml",
r#"
[package]
name = "baz"
version = "0.1.0"
edition = "2015"
"#,
)
.file("baz/src/lib.rs", "")
.build();

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

let f = File::open(&p.root().join("target/package/bar-0.1.0.crate")).unwrap();
let rewritten_toml = format!(
Expand All @@ -2375,4 +2383,22 @@ resolver = "1"
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
&[("Cargo.toml", &rewritten_toml)],
);

// When the crate has the same implicit resolver as the workspace it is not overridden
let f = File::open(&p.root().join("target/package/baz-0.1.0.crate")).unwrap();
let rewritten_toml = format!(
r#"{}
[package]
edition = "2015"
name = "baz"
version = "0.1.0"
"#,
cargo::core::package::MANIFEST_PREAMBLE
);
validate_crate_contents(
f,
"baz-0.1.0.crate",
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
&[("Cargo.toml", &rewritten_toml)],
);
}
2 changes: 0 additions & 2 deletions tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,6 @@ fn publish_git_with_version() {
authors = []\n\
description = \"foo\"\n\
license = \"MIT\"\n\
resolver = \"1\"\n\
\n\
[dependencies.dep1]\n\
version = \"1.0\"\n\
Expand Down Expand Up @@ -1285,7 +1284,6 @@ homepage = "foo"
documentation = "foo"
license = "MIT"
repository = "foo"
resolver = "1"
[dev-dependencies]
"#,
Expand Down
1 change: 0 additions & 1 deletion tests/testsuite/weak_dep_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,6 @@ version = "0.1.0"
description = "foo"
homepage = "https://example.com/"
license = "MIT"
resolver = "1"
[dependencies.bar]
version = "1.0"
Expand Down

0 comments on commit 8b0a3ff

Please sign in to comment.