Skip to content

Commit 2807645

Browse files
committed
Auto merge of #14488 - tweag:package-filter-current, r=epage
Don't automatically include the current crate when packaging This replicates some of the changes in #10677 while packaging. It was split off from #14433
2 parents ee6f1c8 + 4110b84 commit 2807645

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/cargo/ops/cargo_package.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,11 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Vec<Fi
187187
spec.query(member_ids)?;
188188
}
189189
}
190-
let pkgs = ws.members_with_features(specs, &opts.cli_features)?;
190+
let mut pkgs = ws.members_with_features(specs, &opts.cli_features)?;
191+
192+
// In `members_with_features_old`, it will add "current" package (determined by the cwd)
193+
// So we need filter
194+
pkgs.retain(|(pkg, _feats)| specs.iter().any(|spec| spec.matches(pkg.package_id())));
191195

192196
if ws
193197
.lock_root()

tests/testsuite/package.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6500,3 +6500,44 @@ Caused by:
65006500
"#]])
65016501
.run();
65026502
}
6503+
6504+
#[cargo_test]
6505+
fn in_package_workspace_with_members_with_features_old() {
6506+
let p = project()
6507+
.file(
6508+
"Cargo.toml",
6509+
r#"
6510+
[package]
6511+
name = "foo"
6512+
version = "0.1.0"
6513+
edition = "2015"
6514+
[workspace]
6515+
members = ["li"]
6516+
"#,
6517+
)
6518+
.file("src/main.rs", "fn main() {}")
6519+
.file(
6520+
"li/Cargo.toml",
6521+
r#"
6522+
[package]
6523+
name = "li"
6524+
version = "0.0.1"
6525+
edition = "2015"
6526+
rust-version = "1.69"
6527+
description = "li"
6528+
license = "MIT"
6529+
"#,
6530+
)
6531+
.file("li/src/main.rs", "fn main() {}")
6532+
.build();
6533+
6534+
p.cargo("package -p li --no-verify")
6535+
.with_stderr_data(str![[r#"
6536+
[WARNING] manifest has no documentation, homepage or repository.
6537+
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
6538+
[PACKAGING] li v0.0.1 ([ROOT]/foo/li)
6539+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
6540+
6541+
"#]])
6542+
.run();
6543+
}

0 commit comments

Comments
 (0)