mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Preserve order of build scripts
This commit is contained in:
parent
8be51ef2d6
commit
aca513a24b
@ -30,7 +30,9 @@ use crate::core::dependency::{Artifact, ArtifactKind, ArtifactTarget, DepKind};
|
||||
use crate::core::profiles::{Profile, Profiles, UnitFor};
|
||||
use crate::core::resolver::Resolve;
|
||||
use crate::core::resolver::features::{FeaturesFor, ResolvedFeatures};
|
||||
use crate::core::{Dependency, Package, PackageId, PackageSet, Target, TargetKind, Workspace};
|
||||
use crate::core::{
|
||||
Dependency, Feature, Package, PackageId, PackageSet, Target, TargetKind, Workspace,
|
||||
};
|
||||
use crate::ops::resolve_all_features;
|
||||
use crate::util::GlobalContext;
|
||||
use crate::util::interning::InternedString;
|
||||
@ -142,8 +144,27 @@ pub fn build_unit_dependencies<'a, 'gctx>(
|
||||
// which affect the determinism of the build itself. As a result be sure
|
||||
// that dependency lists are always sorted to ensure we've always got a
|
||||
// deterministic output.
|
||||
for list in state.unit_dependencies.values_mut() {
|
||||
list.sort();
|
||||
for (unit, list) in &mut state.unit_dependencies {
|
||||
let is_multiple_build_scripts_enabled = unit
|
||||
.pkg
|
||||
.manifest()
|
||||
.unstable_features()
|
||||
.require(Feature::multiple_build_scripts())
|
||||
.is_ok();
|
||||
|
||||
if is_multiple_build_scripts_enabled {
|
||||
list.sort_by_key(|unit_dep| {
|
||||
if unit_dep.unit.target.is_custom_build() {
|
||||
// We do not sort build scripts to preserve the user-defined order.
|
||||
// In terms of determinism, we are assuming nothing interferes with order from when the user set it in `Cargo.toml` to here
|
||||
(0, None)
|
||||
} else {
|
||||
(1, Some(unit_dep.clone()))
|
||||
}
|
||||
});
|
||||
} else {
|
||||
list.sort();
|
||||
}
|
||||
}
|
||||
trace!("ALL UNIT DEPENDENCIES {:#?}", state.unit_dependencies);
|
||||
|
||||
|
@ -681,7 +681,7 @@ fn build_script_with_conflicts_reverse_sorted() {
|
||||
.masquerade_as_nightly_cargo(&["multiple-build-scripts"])
|
||||
.with_status(0)
|
||||
.with_stdout_data(str![[r#"
|
||||
Hello, from Build Script 2!
|
||||
Hello, from Build Script 1!
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
|
Loading…
x
Reference in New Issue
Block a user