Merge changes from topic "aconfig-improve-dump-formats" into main

* changes:
  aconfig: add 'verbose' dump format
  aconfig: improve the 'text' dump format
  aconfig: remove the 'debug' dump format
This commit is contained in:
Treehugger Robot
2023-07-20 12:35:57 +00:00
committed by Gerrit Code Review

View File

@@ -213,7 +213,7 @@ pub fn create_device_config_sysprops(mut input: Input) -> Result<Vec<u8>> {
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)] #[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
pub enum DumpFormat { pub enum DumpFormat {
Text, Text,
Debug, Verbose,
Protobuf, Protobuf,
Textproto, Textproto,
} }
@@ -229,18 +229,27 @@ pub fn dump_parsed_flags(mut input: Vec<Input>, format: DumpFormat) -> Result<Ve
DumpFormat::Text => { DumpFormat::Text => {
for parsed_flag in parsed_flags.parsed_flag.into_iter() { for parsed_flag in parsed_flags.parsed_flag.into_iter() {
let line = format!( let line = format!(
"{}/{}: {:?} {:?}\n", "{}/{}: {:?} + {:?}\n",
parsed_flag.package(), parsed_flag.package(),
parsed_flag.name(), parsed_flag.name(),
parsed_flag.state(), parsed_flag.permission(),
parsed_flag.permission() parsed_flag.state()
); );
output.extend_from_slice(line.as_bytes()); output.extend_from_slice(line.as_bytes());
} }
} }
DumpFormat::Debug => { DumpFormat::Verbose => {
for parsed_flag in parsed_flags.parsed_flag.into_iter() { for parsed_flag in parsed_flags.parsed_flag.into_iter() {
let line = format!("{:#?}\n", parsed_flag); let sources: Vec<_> =
parsed_flag.trace.iter().map(|tracepoint| tracepoint.source()).collect();
let line = format!(
"{}/{}: {:?} + {:?} ({})\n",
parsed_flag.package(),
parsed_flag.name(),
parsed_flag.permission(),
parsed_flag.state(),
sources.join(", ")
);
output.extend_from_slice(line.as_bytes()); output.extend_from_slice(line.as_bytes());
} }
} }
@@ -326,7 +335,7 @@ mod tests {
let input = parse_test_flags_as_input(); let input = parse_test_flags_as_input();
let bytes = dump_parsed_flags(vec![input], DumpFormat::Text).unwrap(); let bytes = dump_parsed_flags(vec![input], DumpFormat::Text).unwrap();
let text = std::str::from_utf8(&bytes).unwrap(); let text = std::str::from_utf8(&bytes).unwrap();
assert!(text.contains("com.android.aconfig.test/disabled_ro: DISABLED READ_ONLY")); assert!(text.contains("com.android.aconfig.test/disabled_ro: READ_ONLY + DISABLED"));
} }
#[test] #[test]