From 3d6e609f03c1551e60b235490b8e8e5860d3e40e Mon Sep 17 00:00:00 2001 From: Frederick Mayle Date: Wed, 10 May 2023 14:47:25 -0700 Subject: [PATCH] cargo_embargo: dedup output modules This is needed because of https://crrev.com/c/4517945. The new resolver causes there to be multiple `rustc` invocations for some libraries. They are only trivially different though, so dedup'ing the final output is sufficient for now. Bug: 280489895 Test: m cargo_embargo && ./android-merge-2-cargo-embargo.sh Change-Id: If4a36e4f3847d18d03f76bad63bab6c45a9aef97 --- tools/cargo_embargo/src/bp.rs | 5 +++-- tools/cargo_embargo/src/main.rs | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) 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)?;