Merge "Add support for product_available and vendor_available flags." into main
This commit is contained in:
@@ -23,7 +23,7 @@ use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Combined representation of --crate-type and --test flags.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum CrateType {
|
||||
// --crate-type types
|
||||
Bin,
|
||||
@@ -39,6 +39,13 @@ pub enum CrateType {
|
||||
TestNoHarness,
|
||||
}
|
||||
|
||||
impl CrateType {
|
||||
/// Returns whether the crate type is a kind of library.
|
||||
pub fn is_library(self) -> bool {
|
||||
matches!(self, Self::Lib | Self::RLib | Self::DyLib | Self::CDyLib | Self::StaticLib)
|
||||
}
|
||||
}
|
||||
|
||||
/// Info extracted from `CargoOut` for a crate.
|
||||
///
|
||||
/// Note that there is a 1-to-many relationship between a Cargo.toml file and these `Crate`
|
||||
|
||||
@@ -70,6 +70,10 @@ fn default_apex_available() -> Vec<String> {
|
||||
vec!["//apex_available:platform".to_string(), "//apex_available:anyapex".to_string()]
|
||||
}
|
||||
|
||||
fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// Options that apply to everything.
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
@@ -90,6 +94,12 @@ struct Config {
|
||||
/// Value to use for every generated library module's "apex_available" field.
|
||||
#[serde(default = "default_apex_available")]
|
||||
apex_available: Vec<String>,
|
||||
/// Value to use for every generated library module's `product_available` field.
|
||||
#[serde(default = "default_true")]
|
||||
product_available: bool,
|
||||
/// Value to use for every generated library module's `vendor_available` field.
|
||||
#[serde(default = "default_true")]
|
||||
vendor_available: bool,
|
||||
/// Map of renames for modules. For example, if a "libfoo" would be generated and there is an
|
||||
/// entry ("libfoo", "libbar"), the generated module will be called "libbar" instead.
|
||||
///
|
||||
@@ -583,17 +593,16 @@ fn crate_to_bp_modules(
|
||||
m.props.set("shared_libs", process_lib_deps(crate_.shared_libs.clone()));
|
||||
}
|
||||
|
||||
if !cfg.apex_available.is_empty()
|
||||
&& [
|
||||
CrateType::Lib,
|
||||
CrateType::RLib,
|
||||
CrateType::DyLib,
|
||||
CrateType::CDyLib,
|
||||
CrateType::StaticLib,
|
||||
]
|
||||
.contains(crate_type)
|
||||
{
|
||||
m.props.set("apex_available", cfg.apex_available.clone());
|
||||
if crate_type.is_library() {
|
||||
if !cfg.apex_available.is_empty() {
|
||||
m.props.set("apex_available", cfg.apex_available.clone());
|
||||
}
|
||||
if cfg.product_available {
|
||||
m.props.set("product_available", true);
|
||||
}
|
||||
if cfg.vendor_available {
|
||||
m.props.set("vendor_available", true);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(visibility) = cfg.module_visibility.get(module_name) {
|
||||
|
||||
Reference in New Issue
Block a user