Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Part 1 of RFC2906 - Packages can inherit fields from their root workspace #10497

Merged
merged 3 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 100 additions & 31 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::path::{Path, PathBuf};
use std::rc::Rc;

use anyhow::{bail, Context as _};
use anyhow::{anyhow, bail, Context as _};
use glob::glob;
use itertools::Itertools;
use log::debug;
Expand Down Expand Up @@ -1712,63 +1712,132 @@ impl InheritableFields {
}
}

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

pub fn version(&self) -> Option<semver::Version> {
self.version.clone()
pub fn get_dependency(&self, name: &str) -> CargoResult<TomlDependency> {
self.dependencies.clone().map_or(
Err(anyhow!("[workspace.dependencies] was not defined")),
|deps| {
deps.get(name).map_or(
Err(anyhow!(
"dependency {} was not found in [workspace.dependencies]",
name
)),
|dep| Ok(dep.clone()),
)
},
)
}

pub fn authors(&self) -> Option<Vec<String>> {
self.authors.clone()
pub fn version(&self) -> CargoResult<semver::Version> {
self.version
.clone()
.map_or(Err(anyhow!("[workspace.version] was not defined")), |d| {
epage marked this conversation as resolved.
Show resolved Hide resolved
Ok(d)
})
}

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

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

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

pub fn readme(&self) -> Option<StringOrBool> {
self.readme.clone()
pub fn documentation(&self) -> CargoResult<String> {
self.documentation.clone().map_or(
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| {
Ok(d)
})
}

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

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

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

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

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

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

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

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