Skip to content

Commit 8bb95d8

Browse files
committed
HACK: Pull missing package from default-members
This is not actually the right way, the filter should also be able to look at the name specified in `--example <the example>` to find the right crate inside the workspace instead.
1 parent 271f898 commit 8bb95d8

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/utils.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,27 @@ pub fn find_package_manifest_in_workspace(
8080
}
8181
// Otherwise use the manifest we just found, as long as it contains `[package]`
8282
None => {
83+
// TODO: If the user didn't specify a package, but specified a specific bin/test/example target,
84+
// it should be found in the available workspace members instead
85+
86+
// If there was a default member (or members), try getting that instead
87+
if let Some(ws) = &workspace_manifest.workspace {
88+
// >1 only works for build, not for run
89+
if let [single_member] = ws.default_members.as_slice() {
90+
// TODO: Could be glob
91+
let path = workspace_manifest_dir.join(single_member);
92+
let m = workspace_members
93+
.get(&path)
94+
// TODO: Unwrap here already
95+
.filter(|(_p, m)| m.package.is_some())
96+
.ok_or(
97+
// TODO: append /Cargo.toml
98+
Error::NoPackageInManifest(path),
99+
)?;
100+
return Ok(m.clone());
101+
}
102+
}
103+
83104
if potential_manifest.package.is_none() {
84105
return Err(Error::NoPackageInManifest(potential_manifest_path));
85106
}

0 commit comments

Comments
 (0)