Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dev-deps propagation for ws members #1542

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading