diff --git a/CHANGELOG.md b/CHANGELOG.md index 979ecff5..43fc29e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * **Breaking**: dropped compatibility for Nix versions below 2.18.1 * **Breaking**: dropped compatibility for nixpkgs-23.05. +### Fixed +* Workspace inheritance of `lints` in git dependencies is now correctly handled + ## [0.15.1] - 2023-11-30 ### Changed diff --git a/pkgs/crane-utils/src/bin/crane-resolve-workspace-inheritance.rs b/pkgs/crane-utils/src/bin/crane-resolve-workspace-inheritance.rs index 147d7e11..5ad4fdc6 100644 --- a/pkgs/crane-utils/src/bin/crane-resolve-workspace-inheritance.rs +++ b/pkgs/crane-utils/src/bin/crane-resolve-workspace-inheritance.rs @@ -90,20 +90,29 @@ fn merge(cargo_toml: &mut toml_edit::Document, root: &toml_edit::Document) { }; // https://doc.rust-lang.org/cargo/reference/workspaces.html#workspaces - for (key, ws_key) in [ - ("package", "package"), - ("dependencies", "dependencies"), - ("dev-dependencies", "dependencies"), - ("build-dependencies", "dependencies"), + for (key, ws_key, inherit) in [ + ("package", "package", false), + ("dependencies", "dependencies", false), + ("dev-dependencies", "dependencies", false), + ("build-dependencies", "dependencies", false), + ("lints", "lints", true), ] { if let Some((cargo_toml, root)) = cargo_toml.get_mut(key).zip(w.get(ws_key)) { - try_merge_cargo_tables(cargo_toml, root); + if inherit { + try_inherit_cargo_table(cargo_toml, root); + } else { + try_merge_cargo_tables(cargo_toml, root); + } }; if let Some(targets) = cargo_toml.get_mut("target").and_then(try_as_table_like_mut) { for (_, tp) in targets.iter_mut() { if let Some((cargo_toml, root)) = tp.get_mut(key).zip(w.get(ws_key)) { - try_merge_cargo_tables(cargo_toml, root); + if inherit { + try_inherit_cargo_table(cargo_toml, root); + } else { + try_merge_cargo_tables(cargo_toml, root); + } } } } @@ -128,6 +137,21 @@ fn try_as_table_like_mut(item: &mut Item) -> Option<&mut dyn toml_edit::TableLik } } +/// Inherit the specified `cargo_toml` from workspace `root` if the former is a table +fn try_inherit_cargo_table(cargo_toml: &mut Item, root: &Item) { + let Some(t) = try_as_table_like_mut(cargo_toml) else { + return; + }; + if t.get("workspace") + .and_then(Item::as_bool) + .unwrap_or_default() + { + t.remove("workspace"); + let orig_val = mem::replace(cargo_toml, root.clone()); + merge_items(cargo_toml, orig_val); + } +} + /// Merge the specified `cargo_toml` and workspace `root` if both are tables fn try_merge_cargo_tables(cargo_toml: &mut Item, root: &Item) { let cargo_toml = try_as_table_like_mut(cargo_toml); @@ -346,6 +370,9 @@ mod tests { [features] # this feature is a demonstration that comments are preserved my_feature = [] + + [lints] + workspace = true "#, ) .unwrap(); @@ -381,6 +408,11 @@ mod tests { waldo = { version = "waldo-workspace-vers" } unix = { version = "unix-vers" } + [workspace.lints.rust] + unused_extern_crates = 'warn' + + [workspace.lints.clippy] + all = 'allow' "#, ) .unwrap(); @@ -420,6 +452,9 @@ mod tests { [target.'cfg(unix)'.dependencies] unix = { version = "unix-vers" , features = ["some"] } + [lints.rust] + unused_extern_crates = 'warn' + [dev-dependencies] foo= { version = "foo-vers" } bar= { version = "bar-vers", default-features = false } @@ -430,6 +465,9 @@ mod tests { garply = "garply-vers" waldo = "waldo-vers" + [lints.clippy] + all = 'allow' + [build-dependencies] foo= { version = "foo-vers" } bar= { version = "bar-vers", default-features = false }