Skip to content

Commit

Permalink
Merge branch 'main' into sdist-build-dev-inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
messense authored Nov 11, 2022
2 parents 3b44e2f + 83d2e6f commit 092acea
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ fn rewrite_cargo_toml(
let mut workspace_dep = workspace_dep.clone();
// Merge optional and features from the current Cargo.toml
if table[&dep_name].get("optional").is_some() {
ensure_dep_is_inline_table(&mut workspace_dep);
workspace_dep["optional"] = table[&dep_name]["optional"].clone();
}
if let Some(features) =
table[&dep_name].get("features").and_then(|x| x.as_array())
{
ensure_dep_is_inline_table(&mut workspace_dep);
let existing_features = workspace_dep
.as_table_like_mut()
.unwrap()
Expand Down Expand Up @@ -239,6 +241,20 @@ fn rewrite_cargo_toml(
}
}

/// Make sure that the dep entry is an inline table
/// e.g. in the form of `{ version = "..." }`
/// so that we can add entries for `optional` and `features`
fn ensure_dep_is_inline_table(dep: &mut toml_edit::Item) {
if let Some(v) = dep.as_value_mut() {
if v.is_str() {
let val = std::mem::replace(v, toml_edit::Value::from(false));
let mut tab = toml_edit::InlineTable::new();
tab.insert("version", val);
*v = toml_edit::Value::InlineTable(tab);
}
}
}

/// Copies the files of a crate to a source distribution, recursively adding path dependencies
/// and rewriting path entries in Cargo.toml
///
Expand Down
54 changes: 54 additions & 0 deletions test-crates/workspace-inheritance/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test-crates/workspace-inheritance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ version = "0.1.0"
[workspace.dependencies]
cfg-if = "1.0.0"
libc = { version = "0.2", features = ["std"] }
rand = "0.8"
generic_lib = { path = "generic_lib" }
8 changes: 8 additions & 0 deletions test-crates/workspace-inheritance/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ cfg-if.workspace = true

[dev-dependencies]
cfg-if.workspace = true

[dependencies.cfg-if]
workspace = true
optional = true

[dependencies.rand]
workspace = true
features = ["small_rng"]

0 comments on commit 092acea

Please sign in to comment.