Merge "aconfig: add default-permission argument for create-cache command" into main am: 5f81b7dc96
am: 22419904dd
Original change: https://android-review.googlesource.com/c/platform/build/+/2704155 Change-Id: I9eea7a97f1d7643556ffc09017715230296f6267 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
8ef7492eb0
5 changed files with 73 additions and 6 deletions
|
@ -320,6 +320,7 @@ $(call add_json_list, BuildVersionTags, $(BUILD_VERSION_TAGS))
|
|||
|
||||
$(call add_json_str, ReleaseVersion, $(_RELEASE_VERSION))
|
||||
$(call add_json_list, ReleaseAconfigValueSets, $(RELEASE_ACONFIG_VALUE_SETS))
|
||||
$(call add_json_str, ReleaseAconfigFlagDefaultPermission, $(RELEASE_ACONFIG_FLAG_DEFAULT_PERMISSION))
|
||||
|
||||
$(call add_json_bool, KeepVndk, $(filter true,$(KEEP_VNDK)))
|
||||
|
||||
|
|
|
@ -52,10 +52,15 @@ pub struct OutputFile {
|
|||
pub contents: Vec<u8>,
|
||||
}
|
||||
|
||||
const DEFAULT_FLAG_STATE: ProtoFlagState = ProtoFlagState::DISABLED;
|
||||
const DEFAULT_FLAG_PERMISSION: ProtoFlagPermission = ProtoFlagPermission::READ_WRITE;
|
||||
pub const DEFAULT_FLAG_STATE: ProtoFlagState = ProtoFlagState::DISABLED;
|
||||
pub const DEFAULT_FLAG_PERMISSION: ProtoFlagPermission = ProtoFlagPermission::READ_WRITE;
|
||||
|
||||
pub fn parse_flags(package: &str, declarations: Vec<Input>, values: Vec<Input>) -> Result<Vec<u8>> {
|
||||
pub fn parse_flags(
|
||||
package: &str,
|
||||
declarations: Vec<Input>,
|
||||
values: Vec<Input>,
|
||||
default_permission: ProtoFlagPermission,
|
||||
) -> Result<Vec<u8>> {
|
||||
let mut parsed_flags = ProtoParsedFlags::new();
|
||||
|
||||
for mut input in declarations {
|
||||
|
@ -86,11 +91,11 @@ pub fn parse_flags(package: &str, declarations: Vec<Input>, values: Vec<Input>)
|
|||
parsed_flag.set_description(flag_declaration.take_description());
|
||||
parsed_flag.bug.append(&mut flag_declaration.bug);
|
||||
parsed_flag.set_state(DEFAULT_FLAG_STATE);
|
||||
parsed_flag.set_permission(DEFAULT_FLAG_PERMISSION);
|
||||
parsed_flag.set_permission(default_permission);
|
||||
let mut tracepoint = ProtoTracepoint::new();
|
||||
tracepoint.set_source(input.source.clone());
|
||||
tracepoint.set_state(DEFAULT_FLAG_STATE);
|
||||
tracepoint.set_permission(DEFAULT_FLAG_PERMISSION);
|
||||
tracepoint.set_permission(default_permission);
|
||||
parsed_flag.trace.push(tracepoint);
|
||||
|
||||
// verify ParsedFlag looks reasonable
|
||||
|
@ -327,6 +332,36 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_flags_setting_default() {
|
||||
let first_flag = r#"
|
||||
package: "com.first"
|
||||
flag {
|
||||
name: "first"
|
||||
namespace: "first_ns"
|
||||
description: "This is the description of the first flag."
|
||||
bug: "123"
|
||||
}
|
||||
"#;
|
||||
let declaration =
|
||||
vec![Input { source: "momery".to_string(), reader: Box::new(first_flag.as_bytes()) }];
|
||||
let value: Vec<Input> = vec![];
|
||||
|
||||
let flags_bytes = crate::commands::parse_flags(
|
||||
"com.first",
|
||||
declaration,
|
||||
value,
|
||||
ProtoFlagPermission::READ_ONLY,
|
||||
)
|
||||
.unwrap();
|
||||
let parsed_flags =
|
||||
crate::protos::parsed_flags::try_from_binary_proto(&flags_bytes).unwrap();
|
||||
assert_eq!(1, parsed_flags.parsed_flag.len());
|
||||
let parsed_flag = parsed_flags.parsed_flag.first().unwrap();
|
||||
assert_eq!(ProtoFlagState::DISABLED, parsed_flag.state());
|
||||
assert_eq!(ProtoFlagPermission::READ_ONLY, parsed_flag.permission());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_device_config_defaults() {
|
||||
let input = parse_test_flags_as_input();
|
||||
|
|
|
@ -44,6 +44,14 @@ fn cli() -> Command {
|
|||
.arg(Arg::new("package").long("package").required(true))
|
||||
.arg(Arg::new("declarations").long("declarations").action(ArgAction::Append))
|
||||
.arg(Arg::new("values").long("values").action(ArgAction::Append))
|
||||
.arg(
|
||||
Arg::new("default-permission")
|
||||
.long("default-permission")
|
||||
.value_parser(protos::flag_permission::parse_from_str)
|
||||
.default_value(protos::flag_permission::to_string(
|
||||
&commands::DEFAULT_FLAG_PERMISSION,
|
||||
)),
|
||||
)
|
||||
.arg(Arg::new("cache").long("cache").required(true)),
|
||||
)
|
||||
.subcommand(
|
||||
|
@ -161,7 +169,9 @@ fn main() -> Result<()> {
|
|||
let package = get_required_arg::<String>(sub_matches, "package")?;
|
||||
let declarations = open_zero_or_more_files(sub_matches, "declarations")?;
|
||||
let values = open_zero_or_more_files(sub_matches, "values")?;
|
||||
let output = commands::parse_flags(package, declarations, values)
|
||||
let default_permission =
|
||||
get_required_arg::<protos::ProtoFlagPermission>(sub_matches, "default-permission")?;
|
||||
let output = commands::parse_flags(package, declarations, values, *default_permission)
|
||||
.context("failed to create cache")?;
|
||||
let path = get_required_arg::<String>(sub_matches, "cache")?;
|
||||
write_output_to_file_or_stdout(path, &output)?;
|
||||
|
|
|
@ -156,6 +156,26 @@ pub mod flag_values {
|
|||
}
|
||||
}
|
||||
|
||||
pub mod flag_permission {
|
||||
use super::*;
|
||||
use anyhow::bail;
|
||||
|
||||
pub fn parse_from_str(permission: &str) -> Result<ProtoFlagPermission> {
|
||||
match permission.to_ascii_lowercase().as_str() {
|
||||
"read_write" => Ok(ProtoFlagPermission::READ_WRITE),
|
||||
"read_only" => Ok(ProtoFlagPermission::READ_ONLY),
|
||||
_ => bail!("Permission needs to be read_only or read_write."),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_string(permission: &ProtoFlagPermission) -> &str {
|
||||
match permission {
|
||||
ProtoFlagPermission::READ_WRITE => "read_write",
|
||||
ProtoFlagPermission::READ_ONLY => "read_only",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod tracepoint {
|
||||
use super::*;
|
||||
use anyhow::ensure;
|
||||
|
|
|
@ -118,6 +118,7 @@ parsed_flag {
|
|||
reader: Box::new(include_bytes!("../tests/second.values").as_slice()),
|
||||
},
|
||||
],
|
||||
crate::commands::DEFAULT_FLAG_PERMISSION,
|
||||
)
|
||||
.unwrap();
|
||||
crate::protos::parsed_flags::try_from_binary_proto(&bytes).unwrap()
|
||||
|
|
Loading…
Reference in a new issue