Merge "cargo_embargo: dedup output modules" am: 32be457c7a am: c1058e7efc

Original change: https://android-review.googlesource.com/c/platform/development/+/2583718

Change-Id: I41c27c3826719f713c9062b33618ffda295aa76e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot
2023-05-16 01:02:27 +00:00
committed by Automerger Merge Worker
2 changed files with 9 additions and 2 deletions

View File

@@ -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<String, BpValue>,
/// 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<String>,
}
#[derive(Clone, PartialEq, Eq)]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum BpValue {
Object(BpProperties),
Bool(bool),

View File

@@ -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)?;