Merge "cargo_embargo: dedup output modules"

This commit is contained in:
Treehugger Robot
2023-05-15 23:49:52 +00:00
committed by Gerrit Code Review
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)?;