Skip to content

Commit 196f772

Browse files
committed
fix(vendor): Ensure sort happens for vendor
1 parent 7a05add commit 196f772

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,11 +2777,6 @@ fn prepare_targets_for_publish(
27772777
};
27782778
prepared.push(target);
27792779
}
2780-
// Ensure target order is deterministic, particularly for `cargo vendor` where re-vendoring
2781-
// should not cause changes.
2782-
//
2783-
// `unstable` should be deterministic because we enforce that `t.name` is unique
2784-
prepared.sort_unstable_by_key(|t| t.name.clone());
27852780

27862781
if prepared.is_empty() {
27872782
Ok(None)

src/cargo/util/toml/targets.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ fn toml_targets_and_inferred(
744744
autodiscover_flag_name: &str,
745745
) -> Vec<TomlTarget> {
746746
let inferred_targets = inferred_to_toml_targets(inferred);
747-
match toml_targets {
747+
let mut toml_targets = match toml_targets {
748748
None => {
749749
if let Some(false) = autodiscover {
750750
vec![]
@@ -819,7 +819,13 @@ https://github.com/rust-lang/cargo/issues/5330",
819819

820820
targets
821821
}
822-
}
822+
};
823+
// Ensure target order is deterministic, particularly for `cargo vendor` where re-vendoring
824+
// should not cause changes.
825+
//
826+
// `unstable` should be deterministic because we enforce that `t.name` is unique
827+
toml_targets.sort_unstable_by_key(|t| t.name.clone());
828+
toml_targets
823829
}
824830

825831
fn inferred_to_toml_targets(inferred: &[(String, PathBuf)]) -> Vec<TomlTarget> {

tests/testsuite/required_features.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,12 +1474,12 @@ fn truncated_install_warning_message() {
14741474
[FINISHED] `release` profile [optimized] target(s) in [..]
14751475
[WARNING] none of the package's binaries are available for install using the selected features
14761476
bin \"foo1\" requires the features: `feature1`, `feature2`, `feature3`
1477+
bin \"foo10\" requires the features: `feature1`, `feature2`, `feature3`, `feature4`, `feature5`
14771478
bin \"foo2\" requires the features: `feature2`
14781479
bin \"foo3\" requires the features: `feature3`
14791480
bin \"foo4\" requires the features: `feature4`, `feature1`
14801481
bin \"foo5\" requires the features: `feature1`, `feature2`, `feature3`, `feature4`, `feature5`
14811482
bin \"foo6\" requires the features: `feature1`, `feature2`, `feature3`, `feature4`, `feature5`
1482-
bin \"foo7\" requires the features: `feature1`, `feature2`, `feature3`, `feature4`, `feature5`
14831483
4 more targets also requires features not enabled. See them in the Cargo.toml file.
14841484
Consider enabling some of the needed features by passing, e.g., `--features=\"feature1 feature2 feature3\"`").run();
14851485
}

tests/testsuite/vendor.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,9 @@ fn git_deterministic() {
924924
p.change_file(".cargo/config.toml", &output);
925925

926926
let git_dep_manifest = p.read_file("vendor/git_dep/Cargo.toml");
927-
assert_e2e().eq(git_dep_manifest, str![[r##"
927+
assert_e2e().eq(
928+
git_dep_manifest,
929+
str![[r##"
928930
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
929931
#
930932
# When uploading crates to the registry Cargo will automatically
@@ -960,20 +962,16 @@ name = "git_dep"
960962
path = "src/lib.rs"
961963
962964
[[example]]
963-
name = "c"
964-
path = "examples/c.rs"
965+
name = "a"
966+
path = "examples/a.rs"
965967
966968
[[example]]
967969
name = "b"
968970
path = "examples/b.rs"
969971
970972
[[example]]
971-
name = "a"
972-
path = "examples/a.rs"
973-
974-
[[example]]
975-
name = "z"
976-
path = "examples/z.rs"
973+
name = "c"
974+
path = "examples/c.rs"
977975
978976
[[example]]
979977
name = "x"
@@ -983,7 +981,12 @@ path = "examples/x.rs"
983981
name = "y"
984982
path = "examples/y.rs"
985983
986-
"##]]);
984+
[[example]]
985+
name = "z"
986+
path = "examples/z.rs"
987+
988+
"##]],
989+
);
987990
}
988991

989992
#[cargo_test]

0 commit comments

Comments
 (0)