aconfig: add support for changing flag value based on build
Teach aconfig about build IDs (continuously increasing integers). Extend
the aconfig file format to allow flags to say "by default, my value is
X, but starting from build ID A, it's Y, and from build ID B, it's Z".
Bug: 279485059
Test: atest aconfig.test
Change-Id: Idde03dee06f6cb9041c0dd4ca917c8b2f2faafdd
diff --git a/tools/aconfig/src/commands.rs b/tools/aconfig/src/commands.rs
index 0e377aa..76b853b 100644
--- a/tools/aconfig/src/commands.rs
+++ b/tools/aconfig/src/commands.rs
@@ -44,8 +44,8 @@
pub reader: Box<dyn Read>,
}
-pub fn create_cache(aconfigs: Vec<Input>, overrides: Vec<Input>) -> Result<Cache> {
- let mut cache = Cache::new();
+pub fn create_cache(build_id: u32, aconfigs: Vec<Input>, overrides: Vec<Input>) -> Result<Cache> {
+ let mut cache = Cache::new(build_id);
for mut input in aconfigs {
let mut contents = String::new();
@@ -80,15 +80,12 @@
match format {
Format::Text => {
for item in cache.iter() {
- println!("{}: {}", item.id, item.value());
+ println!("{}: {}", item.id, item.value);
}
}
Format::Debug => {
for item in cache.iter() {
- println!("{}: {}", item.id, item.value());
- for value in &item.values {
- println!(" {}: {}", value.source, value.value);
- }
+ println!("{}: {} ({:?})", item.id, item.value, item.debug);
}
}
}
@@ -105,7 +102,9 @@
flag {
id: "a"
description: "Description of a"
- value: true
+ value {
+ value: true
+ }
}
"#;
let aconfigs = vec![Input { source: Source::Memory, reader: Box::new(s.as_bytes()) }];
@@ -116,8 +115,8 @@
}
"#;
let overrides = vec![Input { source: Source::Memory, reader: Box::new(o.as_bytes()) }];
- let cache = create_cache(aconfigs, overrides).unwrap();
- let value = cache.iter().find(|&item| item.id == "a").unwrap().value();
+ let cache = create_cache(1, aconfigs, overrides).unwrap();
+ let value = cache.iter().find(|&item| item.id == "a").unwrap().value;
assert!(!value);
}
}