Skip to content

Commit

Permalink
preserve dependency features order
Browse files Browse the repository at this point in the history
  • Loading branch information
Flowrey committed Apr 1, 2024
1 parent 5b90c4b commit 318072f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/cargo/util/toml_mut/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ use std::fmt::{Display, Formatter};
use std::path::{Path, PathBuf};

use indexmap::IndexSet;
use itertools::Itertools;
use toml_edit::KeyMut;

use super::manifest::str_or_1_len_table;
use crate::core::GitReference;
use crate::core::SourceId;
use crate::core::Summary;
use crate::util::toml_mut::is_sorted;
use crate::CargoResult;
use crate::GlobalContext;

Expand Down Expand Up @@ -588,8 +590,13 @@ impl Dependency {
.collect::<Option<IndexSet<_>>>()
})
.unwrap_or_default();
let is_already_sorted = is_sorted(features.iter());
features.extend(new_features.iter().map(|s| s.as_str()));
let features = features.into_iter().collect::<toml_edit::Value>();
let features = if is_already_sorted {
features.into_iter().sorted().collect::<toml_edit::Value>()
} else {
features.into_iter().collect::<toml_edit::Value>()
};
table.set_dotted(false);
overwrite_value(table, "features", features);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ edition = "2015"
[dependencies]
unrelateed-crate = "99999.0.0"
# Before your-face
your-face = { version = "99999.0.0", features = ["eyes", "nose", "mouth", "ears"] } # After your-face
your-face = { version = "99999.0.0", features = ["ears", "eyes", "mouth", "nose"] } # After your-face
# End
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ version = "0.0.0"
edition = "2015"

[dependencies]
my-package = { version = "99999.0.0", features = ["a", "b", "c", "e", "d"] }
my-package = { version = "99999.0.0", features = ["a", "b", "c", "d", "e"] }

0 comments on commit 318072f

Please sign in to comment.