Skip to content

Commit

Permalink
fix(vendor): Ensure sort happens for vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jun 3, 2024
1 parent d5938cc commit 150461c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
5 changes: 0 additions & 5 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2777,11 +2777,6 @@ fn prepare_targets_for_publish(
};
prepared.push(target);
}
// Ensure target order is deterministic, particularly for `cargo vendor` where re-vendoring
// should not cause changes.
//
// `unstable` should be deterministic because we enforce that `t.name` is unique
prepared.sort_unstable_by_key(|t| t.name.clone());

if prepared.is_empty() {
Ok(None)
Expand Down
10 changes: 8 additions & 2 deletions src/cargo/util/toml/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ fn toml_targets_and_inferred(
autodiscover_flag_name: &str,
) -> Vec<TomlTarget> {
let inferred_targets = inferred_to_toml_targets(inferred);
match toml_targets {
let mut toml_targets = match toml_targets {
None => {
if let Some(false) = autodiscover {
vec![]
Expand Down Expand Up @@ -819,7 +819,13 @@ https://github.com/rust-lang/cargo/issues/5330",

targets
}
}
};
// Ensure target order is deterministic, particularly for `cargo vendor` where re-vendoring
// should not cause changes.
//
// `unstable` should be deterministic because we enforce that `t.name` is unique
toml_targets.sort_unstable_by_key(|t| t.name.clone());
toml_targets
}

fn inferred_to_toml_targets(inferred: &[(String, PathBuf)]) -> Vec<TomlTarget> {
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3351,8 +3351,8 @@ See [..]
[WARNING] ignoring `package.build` as `build.rs` is not included in the published package
[WARNING] ignoring binary `foo` as `src/main.rs` is not included in the published package
[WARNING] ignoring example `ExampleFoo` as `examples/ExampleFoo.rs` is not included in the published package
[WARNING] ignoring test `explicitpath` as `tests/explicitpath.rs` is not included in the published package
[WARNING] ignoring test `ExplicitPath` as `tests/ExplicitPath.rs` is not included in the published package
[WARNING] ignoring test `explicitpath` as `tests/explicitpath.rs` is not included in the published package
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
Expand Down Expand Up @@ -3384,8 +3384,8 @@ See [..]
[WARNING] ignoring `package.build` as `build.rs` is not included in the published package
[WARNING] ignoring binary `foo` as `src/main.rs` is not included in the published package
[WARNING] ignoring example `ExampleFoo` as `examples/ExampleFoo.rs` is not included in the published package
[WARNING] ignoring test `explicitpath` as `tests/explicitpath.rs` is not included in the published package
[WARNING] ignoring test `ExplicitPath` as `tests/ExplicitPath.rs` is not included in the published package
[WARNING] ignoring test `explicitpath` as `tests/explicitpath.rs` is not included in the published package
[VERIFYING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([CWD][..])
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/required_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,12 +1474,12 @@ fn truncated_install_warning_message() {
[FINISHED] `release` profile [optimized] target(s) in [..]
[WARNING] none of the package's binaries are available for install using the selected features
bin \"foo1\" requires the features: `feature1`, `feature2`, `feature3`
bin \"foo10\" requires the features: `feature1`, `feature2`, `feature3`, `feature4`, `feature5`
bin \"foo2\" requires the features: `feature2`
bin \"foo3\" requires the features: `feature3`
bin \"foo4\" requires the features: `feature4`, `feature1`
bin \"foo5\" requires the features: `feature1`, `feature2`, `feature3`, `feature4`, `feature5`
bin \"foo6\" requires the features: `feature1`, `feature2`, `feature3`, `feature4`, `feature5`
bin \"foo7\" requires the features: `feature1`, `feature2`, `feature3`, `feature4`, `feature5`
4 more targets also requires features not enabled. See them in the Cargo.toml file.
Consider enabling some of the needed features by passing, e.g., `--features=\"feature1 feature2 feature3\"`").run();
}
10 changes: 5 additions & 5 deletions tests/testsuite/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,27 +962,27 @@ name = "git_dep"
path = [..]
[[example]]
name = "c"
name = "a"
path = [..]
[[example]]
name = "b"
path = [..]
[[example]]
name = "a"
name = "c"
path = [..]
[[example]]
name = "z"
name = "x"
path = [..]
[[example]]
name = "x"
name = "y"
path = [..]
[[example]]
name = "y"
name = "z"
path = [..]
"##]],
Expand Down

0 comments on commit 150461c

Please sign in to comment.