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 handling of package spec #80

Merged
merged 1 commit into from
Aug 29, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
- [Improve heuristics around artifact cleanup.](https://github.com/taiki-e/cargo-llvm-cov/pull/79)
This removes the need to recompile dependencies in most cases.

- [Fix an issue where `--package` option could not handle package specifications containing the version such as `futures:0.3.16`.](https://github.com/taiki-e/cargo-llvm-cov/pull/80)

## [0.1.3] - 2021-08-26

- [Add `--verbose` option to `cargo llvm-cov clean` subcommand.](https://github.com/taiki-e/cargo-llvm-cov/pull/75)
Expand Down
16 changes: 5 additions & 11 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,23 +200,14 @@ pub(crate) struct WorkspaceMembers {

impl WorkspaceMembers {
fn new(args: &Args, metadata: &cargo_metadata::Metadata) -> Self {
for spec in &args.exclude {
// TODO: handle `package_name:version` format
if !metadata.workspace_members.iter().any(|id| metadata[id].name == *spec) {
warn!(
"excluded package `{}` not found in workspace `{}`",
spec, metadata.workspace_root
);
}
}

let workspace = args.workspace
|| (metadata.resolve.as_ref().unwrap().root.is_none() && args.package.is_empty());
let mut excluded = vec![];
let mut included = vec![];
if workspace {
// with --workspace
for id in &metadata.workspace_members {
// --exclude flag doesn't handle `name:version` format
if args.exclude.contains(&metadata[id].name) {
excluded.push(id.clone());
} else {
Expand All @@ -226,7 +217,10 @@ impl WorkspaceMembers {
} else if !args.package.is_empty() {
// with --package
for id in &metadata.workspace_members {
if args.package.contains(&metadata[id].name) {
let package = &metadata[id];
if args.package.contains(&package.name)
|| args.package.contains(&format!("{}:{}", &package.name, &package.version))
{
included.push(id.clone());
} else {
excluded.push(id.clone());
Expand Down