Skip to content

Commit f44ab08

Browse files
committed
Rework WorkspaceMembers::new
1 parent eac9449 commit f44ab08

File tree

12 files changed

+420
-208
lines changed

12 files changed

+420
-208
lines changed

.github/.cspell/project-dictionary.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ microkernel
1616
MSYSTEM
1717
nextest
1818
notcovered
19+
pkgid
20+
pkgname
1921
profdata
2022
profraw
2123
rmeta

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
1212

1313
## [Unreleased]
1414

15+
- Support glob pattern, versioned name with partial version or `<name>@<version>` syntax, and package spec in `--package`. Previously, only package name and versioned package name with `<name>:<full_version>` are supported. ([#476](https://github.com/taiki-e/cargo-llvm-cov/pull/476))
16+
17+
This also fixes regression introduced in 0.7.0 where causing packages specified with `--package` are wrongly excluded from report/test when package is specified with the above syntaxes.
18+
19+
- Support glob pattern, versioned name, and package spec in `--exclude`. When we tested it previously, Cargo did not support this, but the current version of Cargo does support it. ([#476](https://github.com/taiki-e/cargo-llvm-cov/pull/476))
20+
21+
- Align the exclusion behavior in reports when cargo-llvm-cov is performed in a sub-crate directory of a workspace or in the root crate of a non-virtual workspace without using `--workspace` or `--package`, to match the behavior when `--workspace` or `--package` is used (by default, only show the tested crates). ([#476](https://github.com/taiki-e/cargo-llvm-cov/pull/476))
22+
23+
Compatibility Note: When `--workspace` or `--package` is not used, this will exclude other untested workspace members from the report that were previously implicitly included.
24+
25+
If you want to test other workspace members, consider using `--workspace` or `--package`. If you don't want to test other workspace members but still want to include them in the report, consider using `--workspace` or `--exclude-from-test`.
26+
1527
## [0.7.1] - 2026-01-24
1628

1729
- Fix regression introduced in 0.7.0 where causing coverage test failure in nextest's CI. ([6e30e6f](https://github.com/taiki-e/cargo-llvm-cov/commit/6e30e6f691e44a718fcb8dad7edb8bef3ab24307))

src/cargo.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
cli::{ManifestOptions, Subcommand},
1111
context::Context,
1212
env,
13-
metadata::Metadata,
13+
metadata::{Metadata, PackageId},
1414
process::ProcessBuilder,
1515
};
1616

@@ -19,6 +19,7 @@ pub(crate) struct Workspace {
1919
pub(crate) config: Config,
2020
pub(crate) metadata: Metadata,
2121
pub(crate) current_manifest: Utf8PathBuf,
22+
pub(crate) current_package: Option<PackageId>,
2223

2324
pub(crate) target_dir: Utf8PathBuf,
2425
pub(crate) build_dir: Option<Utf8PathBuf>,
@@ -49,7 +50,7 @@ impl Workspace {
4950
) -> Result<Self> {
5051
// Metadata and config
5152
let config = Config::load()?;
52-
let current_manifest = package_root(config.cargo(), options.manifest_path.as_deref())?;
53+
let current_manifest = locate_project(config.cargo(), options.manifest_path.as_deref())?;
5354
let metadata = Metadata::new(current_manifest.as_std_path(), config.cargo())?;
5455
let mut target_for_config = config.build_target_for_config(target)?;
5556
if target_for_config.len() != 1 {
@@ -65,6 +66,16 @@ impl Workspace {
6566
rustc_version.nightly =
6667
rustc_version.nightly || env::var_os("RUSTC_BOOTSTRAP").unwrap_or_default() == "1";
6768

69+
let mut current_package = None;
70+
for &id in &metadata.workspace_members {
71+
let manifest_path = &*metadata[id].manifest_path;
72+
// no need to use same_file as cargo-metadata and cargo-locate-project
73+
// as they return absolute paths resolved in the same way.
74+
if manifest_path == current_manifest {
75+
current_package = Some(id);
76+
}
77+
}
78+
6879
if doctests && !rustc_version.nightly {
6980
warn!(
7081
"--doctests flag requires nightly toolchain; consider using `cargo +nightly llvm-cov`"
@@ -132,6 +143,7 @@ impl Workspace {
132143
config,
133144
metadata,
134145
current_manifest,
146+
current_package,
135147
target_dir,
136148
build_dir,
137149
output_dir,
@@ -182,18 +194,14 @@ impl Workspace {
182194
}
183195
}
184196

185-
fn package_root(cargo: &OsStr, manifest_path: Option<&Utf8Path>) -> Result<Utf8PathBuf> {
186-
let package_root = if let Some(manifest_path) = manifest_path {
187-
manifest_path.to_owned()
188-
} else {
189-
locate_project(cargo)?.into()
190-
};
191-
Ok(package_root)
192-
}
193-
194197
// https://doc.rust-lang.org/nightly/cargo/commands/cargo-locate-project.html
195-
fn locate_project(cargo: &OsStr) -> Result<String> {
196-
cmd!(cargo, "locate-project", "--message-format", "plain").read()
198+
fn locate_project(cargo: &OsStr, manifest_path: Option<&Utf8Path>) -> Result<Utf8PathBuf> {
199+
let mut cmd = cmd!(cargo, "locate-project");
200+
if let Some(manifest_path) = manifest_path {
201+
cmd.arg("--manifest-path");
202+
cmd.arg(manifest_path);
203+
}
204+
Ok(cmd.args(["--message-format", "plain"]).read()?.into())
197205
}
198206

199207
// https://doc.rust-lang.org/nightly/cargo/commands/cargo-test.html

src/cli.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ pub(crate) struct Args {
7878
pub(crate) package: Vec<String>,
7979
/// Test all packages in the workspace
8080
pub(crate) workspace: bool,
81-
/// Exclude packages from both the test and report
82-
pub(crate) exclude: Vec<String>,
83-
/// Exclude packages from the test (but not from the report)
81+
/// Packages additional excluded from the test (--exclude-from-test)
82+
///
83+
/// (--exclude is already contained in `cargo_args` field.)
8484
pub(crate) exclude_from_test: Vec<String>,
85-
/// Exclude packages from the report (but not from the test)
85+
/// Packages from the report (--exclude and --exclude-from-report)
8686
pub(crate) exclude_from_report: Vec<String>,
8787

8888
// /// Number of parallel jobs, defaults to # of CPUs
@@ -637,7 +637,7 @@ impl Args {
637637
let mut archive_file = None;
638638
let mut nextest_archive_file = None;
639639

640-
let mut parser = lexopt::Parser::from_args(args.clone());
640+
let mut parser = lexopt::Parser::from_args(args);
641641
while let Some(arg) = parser.next()? {
642642
macro_rules! parse_opt {
643643
($opt:tt $(,)?) => {{
@@ -1343,6 +1343,23 @@ impl Args {
13431343
bail!("empty string is not allowed in --output-dir")
13441344
}
13451345

1346+
for e in exclude {
1347+
if exclude_from_test.contains(&e) {
1348+
info!(
1349+
"--exclude-from-test {e} is needless because it is also specified by --exclude"
1350+
);
1351+
} else {
1352+
// No need to push to exclude_from_test because already contained in cargo_args
1353+
}
1354+
if exclude_from_report.contains(&e) {
1355+
info!(
1356+
"--exclude-from-report {e} is needless because it is also specified by --exclude"
1357+
);
1358+
} else {
1359+
exclude_from_report.push(e);
1360+
}
1361+
}
1362+
13461363
// If `-vv` is passed, propagate `-v` to cargo.
13471364
if verbose > 1 {
13481365
cargo_args.push(format!("-{}", "v".repeat(verbose - 1)));
@@ -1411,7 +1428,6 @@ impl Args {
14111428
all_targets,
14121429
doc,
14131430
workspace,
1414-
exclude,
14151431
exclude_from_test,
14161432
exclude_from_report,
14171433
package,

0 commit comments

Comments
 (0)