Skip to content

Commit

Permalink
Fix dev-deps propagation for ws members (#1542)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciektr authored Aug 26, 2024
1 parent adc945a commit 2fc6baf
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
5 changes: 4 additions & 1 deletion scarb/src/core/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ impl Resolve {
/// * Asserts that `root_package` is a node in this graph.
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)| {
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())
});
Dfs::new(&filtered_graph, root_package)
Expand Down
66 changes: 66 additions & 0 deletions scarb/tests/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,72 @@ fn dev_deps_are_not_propagated() {
);
}

#[test]
fn dev_deps_are_not_propagated_for_ws_members() {
let t = assert_fs::TempDir::new().unwrap();

let dep1 = t.child("dep1");
ProjectBuilder::start()
.name("dep1")
.dep_cairo_test()
.build(&dep1);

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

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

WorkspaceBuilder::start()
.add_member("dep2")
.add_member("pkg")
.build(&t);

let metadata = Scarb::quick_snapbox()
.arg("--json")
.arg("metadata")
.arg("--format-version")
.arg("1")
.current_dir(&t)
.stdout_json::<Metadata>();

assert_eq!(
units_and_components(metadata),
BTreeMap::from_iter(vec![
(
"dep2".to_string(),
vec!["core".to_string(), "dep2".to_string()]
),
(
"dep2_unittest".to_string(),
vec!["core".to_string(), "dep1".to_string(), "dep2".to_string()]
),
(
"x".to_string(),
vec!["core".to_string(), "dep2".to_string(), "x".to_string()]
),
(
"x_unittest".to_string(),
vec![
"core".to_string(),
// With dev-deps propagation enabled, this would be included
// "dep1".to_string(),
"dep2".to_string(),
"x".to_string()
]
),
])
);
}

#[test]
fn no_dep() {
let t = assert_fs::TempDir::new().unwrap();
Expand Down

0 comments on commit 2fc6baf

Please sign in to comment.