Skip to content

Commit

Permalink
Fix dev deps propagation (#1552)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciektr authored Aug 27, 2024
1 parent f663d4b commit 5aa9a7e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
18 changes: 10 additions & 8 deletions scarb/src/core/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ impl Resolve {
pub fn solution_of(&self, root_package: PackageId, target_kind: &TargetKind) -> Vec<PackageId> {
assert!(&self.graph.contains_node(root_package));
let filtered_graph = EdgeFiltered::from_fn(&self.graph, move |(node_a, _node_b, edge)| {
if target_kind == &TargetKind::TEST && node_a != root_package {
return false;
}
edge.accepts_target(target_kind.clone())
edge.accepts_target(target_kind.clone(), node_a == root_package)
});
Dfs::new(&filtered_graph, root_package)
.iter(&filtered_graph)
Expand All @@ -71,10 +68,15 @@ impl DependencyEdge {
Self::default()
}

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

pub fn extend(self, target_kind: Option<TargetKind>) -> Self {
Expand Down
20 changes: 18 additions & 2 deletions scarb/tests/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,18 @@ fn dev_deps_are_not_propagated() {
.dev_dep("dep1", &dep1)
.build(&dep2);

let dep3 = t.child("dep3");
ProjectBuilder::start()
.name("dep3")
.dep_cairo_test()
.dep("dep2", &dep2)
.build(&dep3);

let pkg = t.child("pkg");
ProjectBuilder::start()
.name("x")
.dep_cairo_test()
.dev_dep("dep2", &dep2)
.dev_dep("dep3", &dep3)
.build(&pkg);

let metadata = Scarb::quick_snapbox()
Expand All @@ -281,7 +288,7 @@ fn dev_deps_are_not_propagated() {
vec![
"cairo_test".to_string(),
"core".to_string(),
"dep2".to_string(),
"dep3".to_string(),
]
),
(
Expand All @@ -291,6 +298,14 @@ fn dev_deps_are_not_propagated() {
"core".to_string(),
"dep1".to_string(),
]
),
(
"dep3".to_string(),
vec![
"cairo_test".to_string(),
"core".to_string(),
"dep2".to_string(),
]
)
])
);
Expand All @@ -306,6 +321,7 @@ fn dev_deps_are_not_propagated() {
// With dev-deps propagation enabled, this would be included
// "dep1".to_string(),
"dep2".to_string(),
"dep3".to_string(),
"x".to_string()
]
),
Expand Down

0 comments on commit 5aa9a7e

Please sign in to comment.