diff options
author | Jonas Schievink <[email protected]> | 2021-05-24 17:31:43 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2021-05-24 17:31:43 +0100 |
commit | 518d39cd2f1fde997b01acffe74e4a83fc906f86 (patch) | |
tree | d1e98737ea167d80b64a04931d2e952b0a5b4e59 /crates/project_model | |
parent | 01f8d40c5cb28854091d2081b7aa607ad9902930 (diff) |
Duplicate dependencies that have multiple DepKinds
Diffstat (limited to 'crates/project_model')
-rw-r--r-- | crates/project_model/src/cargo_workspace.rs | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/crates/project_model/src/cargo_workspace.rs b/crates/project_model/src/cargo_workspace.rs index ad705c752..a8fee4f08 100644 --- a/crates/project_model/src/cargo_workspace.rs +++ b/crates/project_model/src/cargo_workspace.rs | |||
@@ -121,7 +121,7 @@ pub struct PackageDependency { | |||
121 | pub kind: DepKind, | 121 | pub kind: DepKind, |
122 | } | 122 | } |
123 | 123 | ||
124 | #[derive(Debug, Clone, Eq, PartialEq)] | 124 | #[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord)] |
125 | pub enum DepKind { | 125 | pub enum DepKind { |
126 | /// Available to the library, binary, and dev targets in the package (but not the build script). | 126 | /// Available to the library, binary, and dev targets in the package (but not the build script). |
127 | Normal, | 127 | Normal, |
@@ -132,17 +132,23 @@ pub enum DepKind { | |||
132 | } | 132 | } |
133 | 133 | ||
134 | impl DepKind { | 134 | impl DepKind { |
135 | fn new(list: &[cargo_metadata::DepKindInfo]) -> Self { | 135 | fn iter(list: &[cargo_metadata::DepKindInfo]) -> impl Iterator<Item = Self> + '_ { |
136 | let mut dep_kinds = Vec::new(); | ||
137 | if list.is_empty() { | ||
138 | dep_kinds.push(Self::Normal); | ||
139 | } | ||
136 | for info in list { | 140 | for info in list { |
137 | match info.kind { | 141 | let kind = match info.kind { |
138 | cargo_metadata::DependencyKind::Normal => return Self::Normal, | 142 | cargo_metadata::DependencyKind::Normal => Self::Normal, |
139 | cargo_metadata::DependencyKind::Development => return Self::Dev, | 143 | cargo_metadata::DependencyKind::Development => Self::Dev, |
140 | cargo_metadata::DependencyKind::Build => return Self::Build, | 144 | cargo_metadata::DependencyKind::Build => Self::Build, |
141 | cargo_metadata::DependencyKind::Unknown => continue, | 145 | cargo_metadata::DependencyKind::Unknown => continue, |
142 | } | 146 | }; |
147 | dep_kinds.push(kind); | ||
143 | } | 148 | } |
144 | 149 | dep_kinds.sort_unstable(); | |
145 | Self::Normal | 150 | dep_kinds.dedup(); |
151 | dep_kinds.into_iter() | ||
146 | } | 152 | } |
147 | } | 153 | } |
148 | 154 | ||
@@ -317,7 +323,11 @@ impl CargoWorkspace { | |||
317 | } | 323 | } |
318 | }; | 324 | }; |
319 | node.deps.sort_by(|a, b| a.pkg.cmp(&b.pkg)); | 325 | node.deps.sort_by(|a, b| a.pkg.cmp(&b.pkg)); |
320 | for dep_node in node.deps { | 326 | for (dep_node, kind) in node |
327 | .deps | ||
328 | .iter() | ||
329 | .flat_map(|dep| DepKind::iter(&dep.dep_kinds).map(move |kind| (dep, kind))) | ||
330 | { | ||
321 | let pkg = match pkg_by_id.get(&dep_node.pkg) { | 331 | let pkg = match pkg_by_id.get(&dep_node.pkg) { |
322 | Some(&pkg) => pkg, | 332 | Some(&pkg) => pkg, |
323 | None => { | 333 | None => { |
@@ -328,11 +338,7 @@ impl CargoWorkspace { | |||
328 | continue; | 338 | continue; |
329 | } | 339 | } |
330 | }; | 340 | }; |
331 | let dep = PackageDependency { | 341 | let dep = PackageDependency { name: dep_node.name.clone(), pkg, kind }; |
332 | name: dep_node.name, | ||
333 | pkg, | ||
334 | kind: DepKind::new(&dep_node.dep_kinds), | ||
335 | }; | ||
336 | packages[source].dependencies.push(dep); | 342 | packages[source].dependencies.push(dep); |
337 | } | 343 | } |
338 | packages[source].active_features.extend(node.features); | 344 | packages[source].active_features.extend(node.features); |