Default device_supported and host_supported to true in serde.
This is cleaner than using .unwrap_or(true) wherever they are used. Bug: 293289578 Test: atest cargo_embargo.test Change-Id: I763adf0cc51721408adf55b966ed4304e2766c00
This commit is contained in:
@@ -75,15 +75,15 @@ pub struct Config {
|
||||
|
||||
/// Options that apply to everything in a package (i.e. everything associated with a particular
|
||||
/// Cargo.toml file).
|
||||
#[derive(Deserialize, Default)]
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct PackageConfig {
|
||||
/// Whether to compile for device. Defaults to true.
|
||||
#[serde(default)]
|
||||
pub device_supported: Option<bool>,
|
||||
#[serde(default = "default_true")]
|
||||
pub device_supported: bool,
|
||||
/// Whether to compile for host. Defaults to true.
|
||||
#[serde(default)]
|
||||
pub host_supported: Option<bool>,
|
||||
#[serde(default = "default_true")]
|
||||
pub host_supported: bool,
|
||||
/// Generate "rust_library_rlib" instead of "rust_library".
|
||||
#[serde(default)]
|
||||
pub force_rlib: bool,
|
||||
@@ -107,3 +107,19 @@ pub struct PackageConfig {
|
||||
#[serde(default)]
|
||||
pub copy_out: bool,
|
||||
}
|
||||
|
||||
impl Default for PackageConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
device_supported: true,
|
||||
host_supported: true,
|
||||
force_rlib: false,
|
||||
no_presubmit: false,
|
||||
add_toplevel_block: None,
|
||||
add_module_block: None,
|
||||
dep_blocklist: Default::default(),
|
||||
patch: None,
|
||||
copy_out: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -403,7 +403,7 @@ fn crate_to_bp_modules(
|
||||
) -> Result<Vec<BpModule>> {
|
||||
let mut modules = Vec::new();
|
||||
for crate_type in &crate_.types {
|
||||
let host = if package_cfg.device_supported.unwrap_or(true) { "" } else { "_host" };
|
||||
let host = if package_cfg.device_supported { "" } else { "_host" };
|
||||
let rlib = if package_cfg.force_rlib { "_rlib" } else { "" };
|
||||
let (module_type, module_name, stem) = match crate_type {
|
||||
CrateType::Bin => {
|
||||
@@ -458,8 +458,8 @@ fn crate_to_bp_modules(
|
||||
m.props.set("defaults", vec![defaults.clone()]);
|
||||
}
|
||||
|
||||
if package_cfg.host_supported.unwrap_or(true)
|
||||
&& package_cfg.device_supported.unwrap_or(true)
|
||||
if package_cfg.host_supported
|
||||
&& package_cfg.device_supported
|
||||
&& module_type != "rust_proc_macro"
|
||||
{
|
||||
m.props.set("host_supported", true);
|
||||
@@ -475,7 +475,7 @@ fn crate_to_bp_modules(
|
||||
if crate_.types.contains(&CrateType::Test) {
|
||||
m.props.set("test_suites", vec!["general-tests"]);
|
||||
m.props.set("auto_gen_config", true);
|
||||
if package_cfg.host_supported.unwrap_or(true) {
|
||||
if package_cfg.host_supported {
|
||||
m.props.object("test_options").set("unit_test", !package_cfg.no_presubmit);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user