Skip to content

Commit 5aa9a7e

Browse files
authored
Fix dev deps propagation (#1552)
1 parent f663d4b commit 5aa9a7e

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

scarb/src/core/resolver.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ impl Resolve {
4242
pub fn solution_of(&self, root_package: PackageId, target_kind: &TargetKind) -> Vec<PackageId> {
4343
assert!(&self.graph.contains_node(root_package));
4444
let filtered_graph = EdgeFiltered::from_fn(&self.graph, move |(node_a, _node_b, edge)| {
45-
if target_kind == &TargetKind::TEST && node_a != root_package {
46-
return false;
47-
}
48-
edge.accepts_target(target_kind.clone())
45+
edge.accepts_target(target_kind.clone(), node_a == root_package)
4946
});
5047
Dfs::new(&filtered_graph, root_package)
5148
.iter(&filtered_graph)
@@ -71,10 +68,15 @@ impl DependencyEdge {
7168
Self::default()
7269
}
7370

74-
pub fn accepts_target(&self, target_kind: TargetKind) -> bool {
75-
// Empty target lists accepts all target kinds.
76-
// Represents `[dependencies]` table from manifest file.
77-
self.0.is_empty() || self.0.iter().any(|name| target_kind == *name)
71+
pub fn accepts_target(&self, target_kind: TargetKind, is_root: bool) -> bool {
72+
if self.0.is_empty() {
73+
// Empty target lists accepts all target kinds.
74+
// Represents `[dependencies]` table from manifest file.
75+
return true;
76+
}
77+
// For `TargetKind::TEST`, we should not consider the root package dependencies.
78+
(is_root || target_kind != TargetKind::TEST)
79+
&& self.0.iter().any(|name| target_kind == *name)
7880
}
7981

8082
pub fn extend(self, target_kind: Option<TargetKind>) -> Self {

scarb/tests/metadata.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,18 @@ fn dev_deps_are_not_propagated() {
256256
.dev_dep("dep1", &dep1)
257257
.build(&dep2);
258258

259+
let dep3 = t.child("dep3");
260+
ProjectBuilder::start()
261+
.name("dep3")
262+
.dep_cairo_test()
263+
.dep("dep2", &dep2)
264+
.build(&dep3);
265+
259266
let pkg = t.child("pkg");
260267
ProjectBuilder::start()
261268
.name("x")
262269
.dep_cairo_test()
263-
.dev_dep("dep2", &dep2)
270+
.dev_dep("dep3", &dep3)
264271
.build(&pkg);
265272

266273
let metadata = Scarb::quick_snapbox()
@@ -281,7 +288,7 @@ fn dev_deps_are_not_propagated() {
281288
vec![
282289
"cairo_test".to_string(),
283290
"core".to_string(),
284-
"dep2".to_string(),
291+
"dep3".to_string(),
285292
]
286293
),
287294
(
@@ -291,6 +298,14 @@ fn dev_deps_are_not_propagated() {
291298
"core".to_string(),
292299
"dep1".to_string(),
293300
]
301+
),
302+
(
303+
"dep3".to_string(),
304+
vec![
305+
"cairo_test".to_string(),
306+
"core".to_string(),
307+
"dep2".to_string(),
308+
]
294309
)
295310
])
296311
);
@@ -306,6 +321,7 @@ fn dev_deps_are_not_propagated() {
306321
// With dev-deps propagation enabled, this would be included
307322
// "dep1".to_string(),
308323
"dep2".to_string(),
324+
"dep3".to_string(),
309325
"x".to_string()
310326
]
311327
),

0 commit comments

Comments
 (0)