Skip to content

Commit 59929a5

Browse files
committed
fix(vendor): Ensure sort happens for vendor
1 parent 6e346a2 commit 59929a5

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
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/package.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3351,8 +3351,8 @@ See [..]
33513351
[WARNING] ignoring `package.build` as `build.rs` is not included in the published package
33523352
[WARNING] ignoring binary `foo` as `src/main.rs` is not included in the published package
33533353
[WARNING] ignoring example `ExampleFoo` as `examples/ExampleFoo.rs` is not included in the published package
3354-
[WARNING] ignoring test `explicitpath` as `tests/explicitpath.rs` is not included in the published package
33553354
[WARNING] ignoring test `ExplicitPath` as `tests/ExplicitPath.rs` is not included in the published package
3355+
[WARNING] ignoring test `explicitpath` as `tests/explicitpath.rs` is not included in the published package
33563356
[VERIFYING] foo v0.0.1 ([CWD])
33573357
[COMPILING] foo v0.0.1 ([CWD][..])
33583358
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
@@ -3384,8 +3384,8 @@ See [..]
33843384
[WARNING] ignoring `package.build` as `build.rs` is not included in the published package
33853385
[WARNING] ignoring binary `foo` as `src/main.rs` is not included in the published package
33863386
[WARNING] ignoring example `ExampleFoo` as `examples/ExampleFoo.rs` is not included in the published package
3387-
[WARNING] ignoring test `explicitpath` as `tests/explicitpath.rs` is not included in the published package
33883387
[WARNING] ignoring test `ExplicitPath` as `tests/ExplicitPath.rs` is not included in the published package
3388+
[WARNING] ignoring test `explicitpath` as `tests/explicitpath.rs` is not included in the published package
33893389
[VERIFYING] foo v0.0.1 ([CWD])
33903390
[COMPILING] foo v0.0.1 ([CWD][..])
33913391
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -962,27 +962,27 @@ name = "git_dep"
962962
path = [..]
963963
964964
[[example]]
965-
name = "c"
965+
name = "a"
966966
path = [..]
967967
968968
[[example]]
969969
name = "b"
970970
path = [..]
971971
972972
[[example]]
973-
name = "a"
973+
name = "c"
974974
path = [..]
975975
976976
[[example]]
977-
name = "z"
977+
name = "x"
978978
path = [..]
979979
980980
[[example]]
981-
name = "x"
981+
name = "y"
982982
path = [..]
983983
984984
[[example]]
985-
name = "y"
985+
name = "z"
986986
path = [..]
987987
988988
"##]],

0 commit comments

Comments
 (0)