Skip to content

Commit

Permalink
Run with biggest feature combination early if --all-features case is …
Browse files Browse the repository at this point in the history
…skipped
  • Loading branch information
taiki-e committed Apr 2, 2024
1 parent aa0d0f6 commit b671f8b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 47 deletions.
12 changes: 12 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,18 @@ fn exec_on_package(
}
}
Kind::Powerset { features } => {
let features =
if exclude_all_features && features.len() > 1 && cx.depth.unwrap_or(usize::MAX) > 1
{
// If --all-features case is skipped, run with the biggest feature combination early (first or second): https://github.com/taiki-e/cargo-hack/issues/246
// TODO: The last combination is usually the biggest feature combination,
// but in some cases this is not the case due to deduplication of the powerset.
let last = features.last().unwrap();
exec_cargo_with_features(cx, id, &line, progress, keep_going, last)?;
&features[..features.len() - 1]
} else {
features
};
for f in features {
exec_cargo_with_features(cx, id, &line, progress, keep_going, f)?;
}
Expand Down
95 changes: 48 additions & 47 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,22 +603,23 @@ fn powerset_deduplication() {
// with --optional-deps
cargo_hack(["check", "--feature-powerset", "--optional-deps"])
.assert_success2("powerset_deduplication", require)
// TODO: c,e is actual biggest feature combination here
.stderr_contains(
"
running `cargo check --no-default-features` on deduplication (1/14)
running `cargo check --no-default-features --features a` on deduplication (2/14)
running `cargo check --no-default-features --features b` on deduplication (3/14)
running `cargo check --no-default-features --features c` on deduplication (4/14)
running `cargo check --no-default-features --features d` on deduplication (5/14)
running `cargo check --no-default-features --features a,d` on deduplication (6/14)
running `cargo check --no-default-features --features b,d` on deduplication (7/14)
running `cargo check --no-default-features --features c,d` on deduplication (8/14)
running `cargo check --no-default-features --features e` on deduplication (9/14)
running `cargo check --no-default-features --features c,e` on deduplication (10/14)
running `cargo check --no-default-features --features member1` on deduplication (11/14)
running `cargo check --no-default-features --features a,member1` on deduplication (12/14)
running `cargo check --no-default-features --features b,member1` on deduplication (13/14)
running `cargo check --no-default-features --features c,member1` on deduplication (14/14)
running `cargo check --no-default-features --features c,member1` on deduplication (2/14)
running `cargo check --no-default-features --features a` on deduplication (3/14)
running `cargo check --no-default-features --features b` on deduplication (4/14)
running `cargo check --no-default-features --features c` on deduplication (5/14)
running `cargo check --no-default-features --features d` on deduplication (6/14)
running `cargo check --no-default-features --features a,d` on deduplication (7/14)
running `cargo check --no-default-features --features b,d` on deduplication (8/14)
running `cargo check --no-default-features --features c,d` on deduplication (9/14)
running `cargo check --no-default-features --features e` on deduplication (10/14)
running `cargo check --no-default-features --features c,e` on deduplication (11/14)
running `cargo check --no-default-features --features member1` on deduplication (12/14)
running `cargo check --no-default-features --features a,member1` on deduplication (13/14)
running `cargo check --no-default-features --features b,member1` on deduplication (14/14)
",
)
.stderr_not_contains(
Expand Down Expand Up @@ -688,15 +689,15 @@ fn powerset_deduplication() {
.stderr_contains(
"
running `cargo check --no-default-features` on deduplication (1/10)
running `cargo check --no-default-features --features a` on deduplication (2/10)
running `cargo check --no-default-features --features c` on deduplication (3/10)
running `cargo check --no-default-features --features e` on deduplication (4/10)
running `cargo check --no-default-features --features c,e` on deduplication (5/10)
running `cargo check --no-default-features --features member1` on deduplication (6/10)
running `cargo check --no-default-features --features a,member1` on deduplication (7/10)
running `cargo check --no-default-features --features c,member1` on deduplication (8/10)
running `cargo check --no-default-features --features b,d` on deduplication (9/10)
running `cargo check --no-default-features --features c,b,d` on deduplication (10/10)
running `cargo check --no-default-features --features c,b,d` on deduplication (2/10)
running `cargo check --no-default-features --features a` on deduplication (3/10)
running `cargo check --no-default-features --features c` on deduplication (4/10)
running `cargo check --no-default-features --features e` on deduplication (5/10)
running `cargo check --no-default-features --features c,e` on deduplication (6/10)
running `cargo check --no-default-features --features member1` on deduplication (7/10)
running `cargo check --no-default-features --features a,member1` on deduplication (8/10)
running `cargo check --no-default-features --features c,member1` on deduplication (9/10)
running `cargo check --no-default-features --features b,d` on deduplication (10/10)
",
)
.stderr_not_contains(
Expand Down Expand Up @@ -899,9 +900,9 @@ fn include_features() {
.assert_success("real")
.stderr_contains(
"
running `cargo check --no-default-features --features a` on real (1/3)
running `cargo check --no-default-features --features b` on real (2/3)
running `cargo check --no-default-features --features a,b` on real (3/3)
running `cargo check --no-default-features --features a,b` on real (1/3)
running `cargo check --no-default-features --features a` on real (2/3)
running `cargo check --no-default-features --features b` on real (3/3)
",
);
}
Expand Down Expand Up @@ -1001,13 +1002,13 @@ fn powerset_skip_success() {
.stderr_contains(
"
running `cargo check --no-default-features` on real (1/8)
running `cargo check --no-default-features --features b` on real (2/8)
running `cargo check --no-default-features --features c` on real (3/8)
running `cargo check --no-default-features --features b,c` on real (4/8)
running `cargo check --no-default-features --features default` on real (5/8)
running `cargo check --no-default-features --features b,default` on real (6/8)
running `cargo check --no-default-features --features c,default` on real (7/8)
running `cargo check --no-default-features --features b,c,default` on real (8/8)
running `cargo check --no-default-features --features b,c,default` on real (2/8)
running `cargo check --no-default-features --features b` on real (3/8)
running `cargo check --no-default-features --features c` on real (4/8)
running `cargo check --no-default-features --features b,c` on real (5/8)
running `cargo check --no-default-features --features default` on real (6/8)
running `cargo check --no-default-features --features b,default` on real (7/8)
running `cargo check --no-default-features --features c,default` on real (8/8)
",
)
.stderr_not_contains(
Expand Down Expand Up @@ -1814,19 +1815,19 @@ fn weak_dep_features() {
.stderr_contains(
"
running `cargo check --no-default-features` on weak_dep_features (1/4)
running `cargo check --no-default-features --features default` on weak_dep_features (2/4)
running `cargo check --no-default-features --features easytime` on weak_dep_features (3/4)
running `cargo check --no-default-features --features default,easytime` on weak_dep_features (4/4)
running `cargo check --no-default-features --features default,easytime` on weak_dep_features (2/4)
running `cargo check --no-default-features --features default` on weak_dep_features (3/4)
running `cargo check --no-default-features --features easytime` on weak_dep_features (4/4)
",
);
cargo_hack(["check", "--feature-powerset", "--optional-deps"])
.assert_success2("weak_dep_features", require)
.stderr_contains(
"
running `cargo check --no-default-features` on weak_dep_features (1/4)
running `cargo check --no-default-features --features default` on weak_dep_features (2/4)
running `cargo check --no-default-features --features easytime` on weak_dep_features (3/4)
running `cargo check --no-default-features --features default,easytime` on weak_dep_features (4/4)
running `cargo check --no-default-features --features default,easytime` on weak_dep_features (2/4)
running `cargo check --no-default-features --features default` on weak_dep_features (3/4)
running `cargo check --no-default-features --features easytime` on weak_dep_features (4/4)
",
);

Expand All @@ -1835,19 +1836,19 @@ fn weak_dep_features() {
.stderr_contains(
"
running `cargo check --no-default-features` on weak_dep_features_namespaced (1/4)
running `cargo check --no-default-features --features default` on weak_dep_features_namespaced (2/4)
running `cargo check --no-default-features --features easytime` on weak_dep_features_namespaced (3/4)
running `cargo check --no-default-features --features default,easytime` on weak_dep_features_namespaced (4/4)
running `cargo check --no-default-features --features default,easytime` on weak_dep_features_namespaced (2/4)
running `cargo check --no-default-features --features default` on weak_dep_features_namespaced (3/4)
running `cargo check --no-default-features --features easytime` on weak_dep_features_namespaced (4/4)
",
);
cargo_hack(["check", "--feature-powerset", "--optional-deps"])
.assert_success2("weak_dep_features_namespaced", require)
.stderr_contains(
"
running `cargo check --no-default-features` on weak_dep_features_namespaced (1/4)
running `cargo check --no-default-features --features default` on weak_dep_features_namespaced (2/4)
running `cargo check --no-default-features --features easytime` on weak_dep_features_namespaced (3/4)
running `cargo check --no-default-features --features default,easytime` on weak_dep_features_namespaced (4/4)
running `cargo check --no-default-features --features default,easytime` on weak_dep_features_namespaced (2/4)
running `cargo check --no-default-features --features default` on weak_dep_features_namespaced (3/4)
running `cargo check --no-default-features --features easytime` on weak_dep_features_namespaced (4/4)
",
);

Expand All @@ -1865,9 +1866,9 @@ fn weak_dep_features() {
.stderr_contains(
"
running `cargo check --no-default-features` on weak_dep_features_implicit (1/4)
running `cargo check --no-default-features --features default` on weak_dep_features_implicit (2/4)
running `cargo check --no-default-features --features easytime` on weak_dep_features_implicit (3/4)
running `cargo check --no-default-features --features default,easytime` on weak_dep_features_implicit (4/4)
running `cargo check --no-default-features --features default,easytime` on weak_dep_features_implicit (2/4)
running `cargo check --no-default-features --features default` on weak_dep_features_implicit (3/4)
running `cargo check --no-default-features --features easytime` on weak_dep_features_implicit (4/4)
",
);
}
Expand Down

0 comments on commit b671f8b

Please sign in to comment.