Merge "Add tests for crate_to_bp_modules." into main
This commit is contained in:
@@ -16,8 +16,8 @@ package {
|
|||||||
default_applicable_licenses: ["Android-Apache-2.0"],
|
default_applicable_licenses: ["Android-Apache-2.0"],
|
||||||
}
|
}
|
||||||
|
|
||||||
rust_binary_host {
|
rust_defaults {
|
||||||
name: "cargo_embargo",
|
name: "cargo_embargo.defaults",
|
||||||
srcs: ["src/main.rs"],
|
srcs: ["src/main.rs"],
|
||||||
// Disable LTO for faster builds. Don't need the performance here.
|
// Disable LTO for faster builds. Don't need the performance here.
|
||||||
flags: ["-C lto=off"],
|
flags: ["-C lto=off"],
|
||||||
@@ -31,3 +31,13 @@ rust_binary_host {
|
|||||||
"libserde_json",
|
"libserde_json",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rust_binary_host {
|
||||||
|
name: "cargo_embargo",
|
||||||
|
defaults: ["cargo_embargo.defaults"],
|
||||||
|
}
|
||||||
|
|
||||||
|
rust_test_host {
|
||||||
|
name: "cargo_embargo.test",
|
||||||
|
defaults: ["cargo_embargo.defaults"],
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,16 +16,16 @@ use anyhow::Result;
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
/// Build module.
|
/// Build module.
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct BpModule {
|
pub struct BpModule {
|
||||||
module_type: String,
|
pub module_type: String,
|
||||||
pub props: BpProperties,
|
pub props: BpProperties,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Properties of a build module, or of a nested object value.
|
/// Properties of a build module, or of a nested object value.
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct BpProperties {
|
pub struct BpProperties {
|
||||||
map: BTreeMap<String, BpValue>,
|
pub map: BTreeMap<String, BpValue>,
|
||||||
/// A raw block of text to append after the last key-value pair, but before the closing brace.
|
/// 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
|
/// For example, if you have the properties
|
||||||
///
|
///
|
||||||
@@ -44,7 +44,7 @@ pub struct BpProperties {
|
|||||||
pub raw_block: Option<String>,
|
pub raw_block: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum BpValue {
|
pub enum BpValue {
|
||||||
Object(BpProperties),
|
Object(BpProperties),
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ fn default_true() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Options that apply to everything.
|
/// Options that apply to everything.
|
||||||
#[derive(Deserialize)]
|
#[derive(Default, Deserialize)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
/// Whether to output "rust_test" modules.
|
/// Whether to output "rust_test" modules.
|
||||||
|
|||||||
@@ -535,3 +535,58 @@ fn crate_to_bp_modules(
|
|||||||
}
|
}
|
||||||
Ok(modules)
|
Ok(modules)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn crate_to_bp_empty() {
|
||||||
|
let c = Crate {
|
||||||
|
name: "name".to_string(),
|
||||||
|
package_name: "package_name".to_string(),
|
||||||
|
edition: "2021".to_string(),
|
||||||
|
types: vec![],
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let cfg = Config { ..Default::default() };
|
||||||
|
let package_cfg = PackageConfig { ..Default::default() };
|
||||||
|
let modules = crate_to_bp_modules(&c, &cfg, &package_cfg, &[]).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(modules, vec![]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn crate_to_bp_minimal() {
|
||||||
|
let c = Crate {
|
||||||
|
name: "name".to_string(),
|
||||||
|
package_name: "package_name".to_string(),
|
||||||
|
edition: "2021".to_string(),
|
||||||
|
types: vec![CrateType::Lib],
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let cfg = Config { ..Default::default() };
|
||||||
|
let package_cfg = PackageConfig { ..Default::default() };
|
||||||
|
let modules = crate_to_bp_modules(&c, &cfg, &package_cfg, &[]).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
modules,
|
||||||
|
vec![BpModule {
|
||||||
|
module_type: "rust_library".to_string(),
|
||||||
|
props: BpProperties {
|
||||||
|
map: [
|
||||||
|
("cargo_env_compat".to_string(), BpValue::Bool(true)),
|
||||||
|
("crate_name".to_string(), BpValue::String("name".to_string())),
|
||||||
|
("edition".to_string(), BpValue::String("2021".to_string())),
|
||||||
|
("host_supported".to_string(), BpValue::Bool(true)),
|
||||||
|
("name".to_string(), BpValue::String("libname".to_string())),
|
||||||
|
("srcs".to_string(), BpValue::List(vec![BpValue::String("".to_string())])),
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
raw_block: None
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user