// Copyright (C) 2022 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License.
use anyhow::{bail, Result}; use std::collections::BTreeMap; use std::path::PathBuf;
/// Properties of a build module, or of a nested object value. #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pubstruct BpProperties { pub map: BTreeMap<String, BpValue>, /// A raw block of text to append after the last key-value pair, but before the closing brace. /// For example, if you have the properties /// /// { /// name: "foo", /// srcs: ["main.rs"], /// } /// /// and add `raw_block = "some random text"`, you'll get /// /// { /// name: "foo", /// srcs: ["main.rs"], /// some random text /// } pub raw_block: Option<String>,
}
pubfn merge(&mutself, mut other: BpModule) -> Result<()> { // Dedup if *self == other { return Ok(());
}
// Attempt no_std merge ifself.no_std() && other.device_std_rlib() {
std::mem::swap(self, &mut other)
} ifself.device_std_rlib() && other.no_std() { letmut no_std_props = BpProperties::new();
no_std_props.set("enabled", true); // Normally, props are omitted if empty. If the std variant has a prop set, // and the no_std variant does not, we need to explicitly set it to the empty // list to maintain the semantics of the merged module. for prop in NO_STD_SUPPORTED_PROPS { ifself.props.map.contains_key(*prop) && !other.props.map.contains_key(*prop) {
no_std_props.set(prop, BpValue::List(Vec::new()))
}
} for (prop, val) in other.props.map.into_iter() { ifself.props.map.get(&prop) != Some(&val) { // For this specific value, we have a no_std equivalent. if prop == "defaults"
&& val == BpValue::List(vec![BpValue::from("rust_baremetal_defaults")])
{ letmut defaults = matchself.props.map.get(&prop) {
Some(BpValue::List(defaults)) => defaults.clone(),
None => Vec::new(),
bad => panic!("Invalid defaults: {bad:?}"),
}; if !defaults.contains(&BpValue::from(NO_STD_BAREMETAL_DEFAULTS)) {
defaults.push(BpValue::from(NO_STD_BAREMETAL_DEFAULTS));
} self.props.set("defaults", defaults); continue;
} if NO_STD_FILTERED_PROPS.contains(&prop.as_str()) { continue;
} if NO_STD_SUPPORTED_PROPS.contains(&prop.as_str()) {
no_std_props.set(&prop, val); continue;
}
bail!("Unsupported no_std property: {prop}")
}
} self.props.set("no_std", BpValue::Object(no_std_props)); return Ok(());
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.