Skip to content

Commit dba5baf

Browse files
committed
Auto merge of #10564 - Muscraft:rfc2906-part6, r=epage
Part 6 of RFC2906 - Switch the inheritance source from `workspace` to… Tracking issue: #8415 RFC: rust-lang/rfcs#2906 Part 1: #10497 Part 2: #10517 Part 3: #10538 Part 4: #10548 Part 5: #10563 This PR focuses on switching the inheritance source from `workspace` to `workspace.package`. The RFC specified `workspace` but it was decided that it should be changed to `workspace.package` per [epage's comment](#8415 (comment)). - Moved fields that can be inherited to ` package: Option<InheritableFields>` in `TomlWorkspace` - Making `package` `Option<InheritableFields>` was done to remove duplication of types and better signify what fields you can inherit from in one place - Added `#[serde(skip)]` to `ws_root` and `dependencies` in `InheritableFields` since they will never be present when deserializing and we don't want them present when serializing - Added a method to update `ws_root` and `dependencies` in `InheritableFields` - Added for `ws_root` since it will never be present in a `Cargo.toml` and is needed to resolve relative paths - Added for `dependencies` since they are under `workspace.dependencies` not `workspace.package.dependencies` - `workspace.dependencies` was left out of `workspace.package` to better match `package` and `package.dependencies` - Updated error messages from `workspace._` to `workspace.package._` - Updated `unstable.md` to reflect change to `workspace.package` - Updated tests to use `workspace.package` Remaining implementation work for the RFC - Add `include` and `exclude` now that `workspace.package` is done, see [epage's comment](#8415 (comment)) - `cargo-add` support, see [epage's comment](#8415 (comment)) - Optimizations, as needed
2 parents de4bd68 + 494eb29 commit dba5baf

File tree

5 files changed

+189
-270
lines changed

5 files changed

+189
-270
lines changed

src/cargo/core/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ pub use self::shell::{Shell, Verbosity};
1111
pub use self::source::{GitReference, Source, SourceId, SourceMap};
1212
pub use self::summary::{FeatureMap, FeatureValue, Summary};
1313
pub use self::workspace::{
14-
find_workspace_root, resolve_relative_path, InheritableFields, MaybePackage, Workspace,
15-
WorkspaceConfig, WorkspaceRootConfig,
14+
find_workspace_root, resolve_relative_path, MaybePackage, Workspace, WorkspaceConfig,
15+
WorkspaceRootConfig,
1616
};
17+
pub use crate::util::toml::InheritableFields;
1718

1819
pub mod compiler;
1920
pub mod dependency;

src/cargo/core/workspace.rs

+1-210
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ use crate::sources::{PathSource, CRATES_IO_INDEX, CRATES_IO_REGISTRY};
2323
use crate::util::errors::{CargoResult, ManifestError};
2424
use crate::util::interning::InternedString;
2525
use crate::util::lev_distance;
26-
use crate::util::toml::{
27-
read_manifest, readme_for_project, StringOrBool, TomlDependency, TomlProfiles, VecStringOrBool,
28-
};
26+
use crate::util::toml::{read_manifest, InheritableFields, TomlDependency, TomlProfiles};
2927
use crate::util::{config::ConfigRelativePath, Config, Filesystem, IntoUrl};
3028
use cargo_util::paths;
3129
use cargo_util::paths::normalize_path;
@@ -1644,213 +1642,6 @@ impl WorkspaceRootConfig {
16441642
}
16451643
}
16461644

1647-
/// A group of fields that are inheritable by members of the workspace
1648-
#[derive(Clone, Debug, Default)]
1649-
pub struct InheritableFields {
1650-
dependencies: Option<BTreeMap<String, TomlDependency>>,
1651-
version: Option<semver::Version>,
1652-
authors: Option<Vec<String>>,
1653-
description: Option<String>,
1654-
homepage: Option<String>,
1655-
documentation: Option<String>,
1656-
readme: Option<StringOrBool>,
1657-
keywords: Option<Vec<String>>,
1658-
categories: Option<Vec<String>>,
1659-
license: Option<String>,
1660-
license_file: Option<String>,
1661-
repository: Option<String>,
1662-
publish: Option<VecStringOrBool>,
1663-
edition: Option<String>,
1664-
badges: Option<BTreeMap<String, BTreeMap<String, String>>>,
1665-
rust_version: Option<String>,
1666-
ws_root: PathBuf,
1667-
}
1668-
1669-
impl InheritableFields {
1670-
pub fn new(
1671-
dependencies: Option<BTreeMap<String, TomlDependency>>,
1672-
version: Option<semver::Version>,
1673-
authors: Option<Vec<String>>,
1674-
description: Option<String>,
1675-
homepage: Option<String>,
1676-
documentation: Option<String>,
1677-
readme: Option<StringOrBool>,
1678-
keywords: Option<Vec<String>>,
1679-
categories: Option<Vec<String>>,
1680-
license: Option<String>,
1681-
license_file: Option<String>,
1682-
repository: Option<String>,
1683-
publish: Option<VecStringOrBool>,
1684-
edition: Option<String>,
1685-
badges: Option<BTreeMap<String, BTreeMap<String, String>>>,
1686-
rust_version: Option<String>,
1687-
ws_root: PathBuf,
1688-
) -> InheritableFields {
1689-
Self {
1690-
dependencies,
1691-
version,
1692-
authors,
1693-
description,
1694-
homepage,
1695-
documentation,
1696-
readme,
1697-
keywords,
1698-
categories,
1699-
license,
1700-
license_file,
1701-
repository,
1702-
publish,
1703-
edition,
1704-
badges,
1705-
rust_version,
1706-
ws_root,
1707-
}
1708-
}
1709-
1710-
pub fn dependencies(&self) -> CargoResult<BTreeMap<String, TomlDependency>> {
1711-
self.dependencies.clone().map_or(
1712-
Err(anyhow!("`workspace.dependencies` was not defined")),
1713-
|d| Ok(d),
1714-
)
1715-
}
1716-
1717-
pub fn get_dependency(&self, name: &str) -> CargoResult<TomlDependency> {
1718-
self.dependencies.clone().map_or(
1719-
Err(anyhow!("`workspace.dependencies` was not defined")),
1720-
|deps| {
1721-
deps.get(name).map_or(
1722-
Err(anyhow!(
1723-
"`dependency.{}` was not found in `workspace.dependencies`",
1724-
name
1725-
)),
1726-
|dep| Ok(dep.clone()),
1727-
)
1728-
},
1729-
)
1730-
}
1731-
1732-
pub fn version(&self) -> CargoResult<semver::Version> {
1733-
self.version
1734-
.clone()
1735-
.map_or(Err(anyhow!("`workspace.version` was not defined")), |d| {
1736-
Ok(d)
1737-
})
1738-
}
1739-
1740-
pub fn authors(&self) -> CargoResult<Vec<String>> {
1741-
self.authors
1742-
.clone()
1743-
.map_or(Err(anyhow!("`workspace.authors` was not defined")), |d| {
1744-
Ok(d)
1745-
})
1746-
}
1747-
1748-
pub fn description(&self) -> CargoResult<String> {
1749-
self.description.clone().map_or(
1750-
Err(anyhow!("`workspace.description` was not defined")),
1751-
|d| Ok(d),
1752-
)
1753-
}
1754-
1755-
pub fn homepage(&self) -> CargoResult<String> {
1756-
self.homepage
1757-
.clone()
1758-
.map_or(Err(anyhow!("`workspace.homepage` was not defined")), |d| {
1759-
Ok(d)
1760-
})
1761-
}
1762-
1763-
pub fn documentation(&self) -> CargoResult<String> {
1764-
self.documentation.clone().map_or(
1765-
Err(anyhow!("`workspace.documentation` was not defined")),
1766-
|d| Ok(d),
1767-
)
1768-
}
1769-
1770-
pub fn readme(&self, package_root: &Path) -> CargoResult<StringOrBool> {
1771-
readme_for_project(self.ws_root.as_path(), self.readme.clone()).map_or(
1772-
Err(anyhow!("`workspace.readme` was not defined")),
1773-
|readme| {
1774-
let rel_path =
1775-
resolve_relative_path("readme", &self.ws_root, package_root, &readme)?;
1776-
Ok(StringOrBool::String(rel_path))
1777-
},
1778-
)
1779-
}
1780-
1781-
pub fn keywords(&self) -> CargoResult<Vec<String>> {
1782-
self.keywords
1783-
.clone()
1784-
.map_or(Err(anyhow!("`workspace.keywords` was not defined")), |d| {
1785-
Ok(d)
1786-
})
1787-
}
1788-
1789-
pub fn categories(&self) -> CargoResult<Vec<String>> {
1790-
self.categories.clone().map_or(
1791-
Err(anyhow!("`workspace.categories` was not defined")),
1792-
|d| Ok(d),
1793-
)
1794-
}
1795-
1796-
pub fn license(&self) -> CargoResult<String> {
1797-
self.license
1798-
.clone()
1799-
.map_or(Err(anyhow!("`workspace.license` was not defined")), |d| {
1800-
Ok(d)
1801-
})
1802-
}
1803-
1804-
pub fn license_file(&self, package_root: &Path) -> CargoResult<String> {
1805-
self.license_file.clone().map_or(
1806-
Err(anyhow!("`workspace.license_file` was not defined")),
1807-
|d| resolve_relative_path("license-file", &self.ws_root, package_root, &d),
1808-
)
1809-
}
1810-
1811-
pub fn repository(&self) -> CargoResult<String> {
1812-
self.repository.clone().map_or(
1813-
Err(anyhow!("`workspace.repository` was not defined")),
1814-
|d| Ok(d),
1815-
)
1816-
}
1817-
1818-
pub fn publish(&self) -> CargoResult<VecStringOrBool> {
1819-
self.publish
1820-
.clone()
1821-
.map_or(Err(anyhow!("`workspace.publish` was not defined")), |d| {
1822-
Ok(d)
1823-
})
1824-
}
1825-
1826-
pub fn edition(&self) -> CargoResult<String> {
1827-
self.edition
1828-
.clone()
1829-
.map_or(Err(anyhow!("`workspace.edition` was not defined")), |d| {
1830-
Ok(d)
1831-
})
1832-
}
1833-
1834-
pub fn rust_version(&self) -> CargoResult<String> {
1835-
self.rust_version.clone().map_or(
1836-
Err(anyhow!("`workspace.rust-version` was not defined")),
1837-
|d| Ok(d),
1838-
)
1839-
}
1840-
1841-
pub fn badges(&self) -> CargoResult<BTreeMap<String, BTreeMap<String, String>>> {
1842-
self.badges
1843-
.clone()
1844-
.map_or(Err(anyhow!("`workspace.badges` was not defined")), |d| {
1845-
Ok(d)
1846-
})
1847-
}
1848-
1849-
pub fn ws_root(&self) -> &PathBuf {
1850-
&self.ws_root
1851-
}
1852-
}
1853-
18541645
pub fn resolve_relative_path(
18551646
label: &str,
18561647
old_root: &Path,

0 commit comments

Comments
 (0)