Skip to content

Commit

Permalink
Support dependency inheritance from workspace manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Sep 22, 2022
1 parent 5b5eeea commit 4a8cf92
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub fn try_get_workspace_manifest(manifest_dir: &Directory) -> Result<WorkspaceM
let manifest_str = fs::read_to_string(cargo_toml_path)?;
let mut manifest: WorkspaceManifest = toml::from_str(&manifest_str)?;

fix_dependencies(&mut manifest.workspace.dependencies, manifest_dir);
fix_patches(&mut manifest.patch, manifest_dir);
fix_replacements(&mut manifest.replace, manifest_dir);

Expand Down Expand Up @@ -84,6 +85,8 @@ pub struct WorkspaceManifest {
pub struct WorkspaceWorkspace {
#[serde(default)]
pub package: WorkspacePackage,
#[serde(default)]
pub dependencies: Map<String, Dependency>,
}

#[derive(Deserialize, Default, Debug)]
Expand Down Expand Up @@ -142,6 +145,8 @@ pub struct Dependency {
pub tag: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rev: Option<String>,
#[serde(default, skip_serializing_if = "is_false")]
pub workspace: bool,
#[serde(flatten)]
pub rest: Map<String, Value>,
}
Expand Down Expand Up @@ -188,6 +193,10 @@ fn is_true(boolean: &bool) -> bool {
*boolean
}

fn is_false(boolean: &bool) -> bool {
!*boolean
}

impl Default for EditionOrInherit {
fn default() -> Self {
EditionOrInherit::Edition(Edition::default())
Expand Down Expand Up @@ -267,6 +276,7 @@ impl<'de> Deserialize<'de> for Dependency {
branch: None,
tag: None,
rev: None,
workspace: false,
rest: Map::new(),
})
}
Expand Down
5 changes: 4 additions & 1 deletion src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ pub struct Build {
}

#[derive(Serialize, Debug)]
pub struct Workspace {}
pub struct Workspace {
#[serde(skip_serializing_if = "Map::is_empty")]
pub dependencies: Map<String, Dependency>,
}

impl Default for Edition {
fn default() -> Self {
Expand Down
5 changes: 4 additions & 1 deletion src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ impl Runner {
dependencies: Map::new(),
target: source_manifest.target,
bins: Vec::new(),
workspace: Some(Workspace {}),
workspace: Some(Workspace {
dependencies: workspace_manifest.workspace.dependencies,
}),
// Within a workspace, only the [patch] and [replace] sections in
// the workspace root's Cargo.toml are applied by Cargo.
patch: workspace_manifest.patch,
Expand All @@ -267,6 +269,7 @@ impl Runner {
branch: None,
tag: None,
rev: None,
workspace: false,
rest: Map::new(),
},
);
Expand Down

0 comments on commit 4a8cf92

Please sign in to comment.