diff options
Diffstat (limited to 'tools/record-finalized-flags/src/flag_report.rs')
| -rw-r--r-- | tools/record-finalized-flags/src/flag_report.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tools/record-finalized-flags/src/flag_report.rs b/tools/record-finalized-flags/src/flag_report.rs new file mode 100644 index 0000000000..ab2643231e --- /dev/null +++ b/tools/record-finalized-flags/src/flag_report.rs @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +use anyhow::Result; +use std::{collections::HashSet, io::Read}; + +use crate::FlagId; + +/// Read a flag report generated by `metalava flag-report` representing all flags known by the +/// build, and filter out the flags in the report that metalava has marked as finalized. +pub(crate) fn read_and_filter_flag_report<R: Read>(mut reader: R) -> Result<HashSet<FlagId>> { + let mut contents = String::new(); + reader.read_to_string(&mut contents)?; + let iter = + contents.lines().filter(|s| s.ends_with(",finalized") || s.ends_with(",kept")).map(|s| { + let (flag, _) = + s.split_once(",").expect("previous filter guarantees at least one comma"); + flag.to_owned() + }); + Ok(HashSet::from_iter(iter)) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test() { + let input = include_bytes!("../tests/flag-report.csv"); + let flags = read_and_filter_flag_report(&input[..]).unwrap(); + assert_eq!(flags, HashSet::from_iter(["com.foo".to_string(), "com.baz".to_string(),])); + } +} |
