diff --git a/tools/cargo_embargo/src/bp.rs b/tools/cargo_embargo/src/bp.rs index 5c661dc27..9364c5bb5 100644 --- a/tools/cargo_embargo/src/bp.rs +++ b/tools/cargo_embargo/src/bp.rs @@ -16,13 +16,14 @@ use anyhow::Result; use std::collections::BTreeMap; /// Build module. +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct BpModule { module_type: String, pub props: BpProperties, } /// Properties of a build module, or of a nested object value. -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct BpProperties { map: BTreeMap, /// A raw block of text to append after the last key-value pair, but before the closing brace. @@ -43,7 +44,7 @@ pub struct BpProperties { pub raw_block: Option, } -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)] pub enum BpValue { Object(BpProperties), Bool(bool), diff --git a/tools/cargo_embargo/src/main.rs b/tools/cargo_embargo/src/main.rs index dd2caf594..83ee8967c 100644 --- a/tools/cargo_embargo/src/main.rs +++ b/tools/cargo_embargo/src/main.rs @@ -373,6 +373,12 @@ fn write_android_bp( return Ok(()); } + // In some cases there are nearly identical rustc invocations that that get processed into + // identical BP modules. So far, dedup'ing them is a good enough fix. At some point we might + // need something more complex, maybe like cargo2android's logic for merging crates. + modules.sort(); + modules.dedup(); + modules.sort_by_key(|m| m.props.get_string("name").to_string()); for m in modules { m.write(&mut bp_contents)?;