Skip to content

Commit

Permalink
-- renamed deduplicate_workspace to inheritable_workspace_fields
Browse files Browse the repository at this point in the history
-- removed `[]` from error messages in favor of back-ticks
  • Loading branch information
Muscraft committed Mar 23, 2022
1 parent c4cd152 commit e6992d4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 33 deletions.
34 changes: 17 additions & 17 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1714,18 +1714,18 @@ impl InheritableFields {

pub fn dependencies(&self) -> CargoResult<BTreeMap<String, TomlDependency>> {
self.dependencies.clone().map_or(
Err(anyhow!("[workspace.dependencies] was not defined")),
Err(anyhow!("`workspace.dependencies` was not defined")),
|d| Ok(d),
)
}

pub fn get_dependency(&self, name: &str) -> CargoResult<TomlDependency> {
self.dependencies.clone().map_or(
Err(anyhow!("[workspace.dependencies] was not defined")),
Err(anyhow!("`workspace.dependencies` was not defined")),
|deps| {
deps.get(name).map_or(
Err(anyhow!(
"dependency {} was not found in [workspace.dependencies]",
"`dependency.{}` was not found in `workspace.dependencies`",
name
)),
|dep| Ok(dep.clone()),
Expand All @@ -1737,106 +1737,106 @@ impl InheritableFields {
pub fn version(&self) -> CargoResult<semver::Version> {
self.version
.clone()
.map_or(Err(anyhow!("[workspace.version] was not defined")), |d| {
.map_or(Err(anyhow!("`workspace.version` was not defined")), |d| {
Ok(d)
})
}

pub fn authors(&self) -> CargoResult<Vec<String>> {
self.authors
.clone()
.map_or(Err(anyhow!("[workspace.authors] was not defined")), |d| {
.map_or(Err(anyhow!("`workspace.authors` was not defined")), |d| {
Ok(d)
})
}

pub fn description(&self) -> CargoResult<String> {
self.description.clone().map_or(
Err(anyhow!("[workspace.description] was not defined")),
Err(anyhow!("`workspace.description` was not defined")),
|d| Ok(d),
)
}

pub fn homepage(&self) -> CargoResult<String> {
self.homepage
.clone()
.map_or(Err(anyhow!("[workspace.homepage] was not defined")), |d| {
.map_or(Err(anyhow!("`workspace.homepage` was not defined")), |d| {
Ok(d)
})
}

pub fn documentation(&self) -> CargoResult<String> {
self.documentation.clone().map_or(
Err(anyhow!("[workspace.documentation] was not defined")),
Err(anyhow!("`workspace.documentation` was not defined")),
|d| Ok(d),
)
}

pub fn readme(&self) -> CargoResult<StringOrBool> {
self.readme
.clone()
.map_or(Err(anyhow!("[workspace.readme] was not defined")), |d| {
.map_or(Err(anyhow!("`workspace.readme` was not defined")), |d| {
Ok(d)
})
}

pub fn keywords(&self) -> CargoResult<Vec<String>> {
self.keywords
.clone()
.map_or(Err(anyhow!("[workspace.keywords] was not defined")), |d| {
.map_or(Err(anyhow!("`workspace.keywords` was not defined")), |d| {
Ok(d)
})
}

pub fn categories(&self) -> CargoResult<Vec<String>> {
self.categories.clone().map_or(
Err(anyhow!("[workspace.categories] was not defined")),
Err(anyhow!("`workspace.categories` was not defined")),
|d| Ok(d),
)
}

pub fn license(&self) -> CargoResult<String> {
self.license
.clone()
.map_or(Err(anyhow!("[workspace.license] was not defined")), |d| {
.map_or(Err(anyhow!("`workspace.license` was not defined")), |d| {
Ok(d)
})
}

pub fn license_file(&self) -> CargoResult<String> {
self.license_file.clone().map_or(
Err(anyhow!("[workspace.license_file] was not defined")),
Err(anyhow!("`workspace.license_file` was not defined")),
|d| Ok(d),
)
}

pub fn repository(&self) -> CargoResult<String> {
self.repository.clone().map_or(
Err(anyhow!("[workspace.repository] was not defined")),
Err(anyhow!("`workspace.repository` was not defined")),
|d| Ok(d),
)
}

pub fn publish(&self) -> CargoResult<VecStringOrBool> {
self.publish
.clone()
.map_or(Err(anyhow!("[workspace.publish] was not defined")), |d| {
.map_or(Err(anyhow!("`workspace.publish` was not defined")), |d| {
Ok(d)
})
}

pub fn edition(&self) -> CargoResult<String> {
self.edition
.clone()
.map_or(Err(anyhow!("[workspace.edition] was not defined")), |d| {
.map_or(Err(anyhow!("`workspace.edition` was not defined")), |d| {
Ok(d)
})
}

pub fn badges(&self) -> CargoResult<BTreeMap<String, BTreeMap<String, String>>> {
self.badges
.clone()
.map_or(Err(anyhow!("[workspace.badges] was not defined")), |d| {
.map_or(Err(anyhow!("`workspace.badges` was not defined")), |d| {
Ok(d)
})
}
Expand Down
24 changes: 16 additions & 8 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ pub fn read_manifest_from_str(
}
if let TomlDependency::Workspace(_) = dep {
bail!(
"`dependencies.{}` specified `{{ workspace = true}}`, but workspace dependencies cannot do this",
"`workspace.dependencies.{}` specified `{{ workspace = true }}`, but \
workspace dependencies cannot do this",
name
);
}
Expand Down Expand Up @@ -1010,12 +1011,13 @@ impl<T> MaybeWorkspace<T> {
MaybeWorkspace::Workspace(TomlWorkspaceField { workspace: true }) => {
cargo_features.require(Feature::workspace_inheritance())?;
get_ws_field().context(format!(
"error reading `{}` from workspace root manifest's `[workspace.{}]`",
"error inheriting `{}` from workspace root manifest's `workspace.{}`",
label, label
))
}
MaybeWorkspace::Workspace(TomlWorkspaceField { workspace: false }) => Err(anyhow!(
"workspace cannot be false for key `package.{label}`",
"`workspace=false` is unsupported for `package.{}`",
label,
)),
}
}
Expand Down Expand Up @@ -2190,7 +2192,7 @@ impl<P: ResolveToPath + Clone> TomlDependency<P> {
}) => {
cargo_features.require(Feature::workspace_inheritance())?;
get_ws_dependency().context(format!(
"error reading `dependencies.{}` from workspace root manifest's `[workspace.dependencies.{}]`",
"error reading `dependencies.{}` from workspace root manifest's `workspace.dependencies.{}`",
label, label
)).map(|dep| {
match dep {
Expand All @@ -2200,16 +2202,22 @@ impl<P: ResolveToPath + Clone> TomlDependency<P> {
dep.add_features(features);
dep.update_optional(optional);
TomlDependency::Detailed(dep)
}
// We check for this when we parse a toml file
TomlDependency::Workspace(_) => unreachable!(),
},
TomlDependency::Workspace(_) => {
unreachable!(
"We check that no workspace defines dependencies with \
`{{ workspace = true }}` when we read a manifest from a string. \
this should not happen but did on {}",
label
)
},
}
})
}
TomlDependency::Workspace(TomlWorkspaceDependency {
workspace: false, ..
}) => Err(anyhow!(
"workspace cannot be false for key `dependencies.{}`",
"`workspace=false` is unsupported for `package.dependencies.{}`",
label,
)),
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Tests for deduplicating Cargo.toml fields with { workspace = true }
//! Tests for inheriting Cargo.toml fields with { workspace = true }
use cargo_test_support::registry::{Dependency, Package};
use cargo_test_support::{basic_lib_manifest, git, paths, project, publish, registry};

Expand Down Expand Up @@ -495,10 +495,10 @@ fn inherit_from_own_undefined_field() {
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
Caused by:
error reading `description` from workspace root manifest's `[workspace.description]`
error inheriting `description` from workspace root manifest's `workspace.description`
Caused by:
[workspace.description] was not defined
`workspace.description` was not defined
",
)
.run();
Expand Down Expand Up @@ -604,7 +604,7 @@ fn error_on_unimplemented_inheritance_fields() {
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
Caused by:
error reading `version` from workspace root manifest's `[workspace.version]`
error inheriting `version` from workspace root manifest's `workspace.version`
Caused by:
inheriting from a parent workspace is not implemented yet
Expand Down Expand Up @@ -677,7 +677,7 @@ Caused by:
failed to parse manifest at `[CWD]/bar/Cargo.toml`
Caused by:
error reading `dependencies.detailed` from workspace root manifest's `[workspace.dependencies.detailed]`
error reading `dependencies.detailed` from workspace root manifest's `workspace.dependencies.detailed`
Caused by:
inheriting from a parent workspace is not implemented yet
Expand Down Expand Up @@ -724,7 +724,7 @@ fn error_workspace_false() {
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
Caused by:
workspace cannot be false for key `package.description`
`workspace=false` is unsupported for `package.description`
",
)
.run();
Expand Down Expand Up @@ -768,7 +768,8 @@ fn error_workspace_dependency_looked_for_workspace_itself() {
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
Caused by:
`dependencies.dep` specified `{ workspace = true}`, but workspace dependencies cannot do this
`workspace.dependencies.dep` specified `{ workspace = true }`, but workspace dependencies \
cannot do this
",
)
.run();
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ mod cross_compile;
mod cross_publish;
mod custom_target;
mod death;
mod deduplicate_workspace;
mod dep_info;
mod directory;
mod doc;
Expand All @@ -58,6 +57,7 @@ mod git_auth;
mod git_gc;
mod glob_targets;
mod help;
mod inheritable_workspace_fields;
mod init;
mod install;
mod install_upgrade;
Expand Down

0 comments on commit e6992d4

Please sign in to comment.