Skip to content

Commit 2396488

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

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

src/cargo/util/toml/mod.rs

-5
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

+8-2
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

+1-1
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

+8-8
Original file line numberDiff line numberDiff line change
@@ -960,20 +960,16 @@ name = "git_dep"
960960
path = "src/lib.rs"
961961
962962
[[example]]
963-
name = "c"
964-
path = "examples/c.rs"
963+
name = "a"
964+
path = "examples/a.rs"
965965
966966
[[example]]
967967
name = "b"
968968
path = "examples/b.rs"
969969
970970
[[example]]
971-
name = "a"
972-
path = "examples/a.rs"
973-
974-
[[example]]
975-
name = "z"
976-
path = "examples/z.rs"
971+
name = "c"
972+
path = "examples/c.rs"
977973
978974
[[example]]
979975
name = "x"
@@ -983,6 +979,10 @@ path = "examples/x.rs"
983979
name = "y"
984980
path = "examples/y.rs"
985981
982+
[[example]]
983+
name = "z"
984+
path = "examples/z.rs"
985+
986986
"##]]);
987987
}
988988

0 commit comments

Comments
 (0)