aconfig: define Aconfig proto
Fill in aconfig.proto. Define Aconfig definitions (for introducing flags
and setting their values) and Overrides (for overriding flags regardless
of what their definitions say). More changes to the proto schema are
expected when more of the aconfig project is outlined.
Use proto2 instead of proto3: this will cause the protobuf text parser
to error on missing fields instead of returning a default value which is
ambiguous, especially for booleans. (Also, the text protobuf parser
doesn't provide good error messages: if the input is missing a field,
the error is always "1:1: Message not initialized").
Unfortunately the generated Rust wrappers around the proto structs land
in an external crate, which prevents aconfig from adding new impl
blocks. Circumvent this by converting the data read from proto into
structs defined in the aconfig crate.
Change main.rs to parse (static) text proto.
Also add dependency on anyhow.
Bug: 279485059
Test: atest aconfig.test
Change-Id: I512e3b61ef20e2f55b7699a178d466d2a9a89eac
diff --git a/tools/aconfig/src/main.rs b/tools/aconfig/src/main.rs
index 5414f0e..9d87ca4 100644
--- a/tools/aconfig/src/main.rs
+++ b/tools/aconfig/src/main.rs
@@ -16,40 +16,23 @@
//! `aconfig` is a build time tool to manage build time configurations, such as feature flags.
-use protobuf::text_format::{parse_from_str, ParseError};
+use anyhow::Result;
+mod aconfig;
mod protos;
-use protos::Placeholder;
-fn foo() -> Result<String, ParseError> {
- let placeholder = parse_from_str::<Placeholder>(r#"name: "aconfig""#)?;
- Ok(placeholder.name)
-}
+use aconfig::{Flag, Override};
-fn main() {
- println!("{:?}", foo());
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn test_foo() {
- assert_eq!("aconfig", foo().unwrap());
- }
-
- #[test]
- fn test_binary_protobuf() {
- use protobuf::Message;
- let mut buffer = Vec::new();
-
- let mut original = Placeholder::new();
- original.name = "test".to_owned();
- original.write_to_writer(&mut buffer).unwrap();
-
- let copy = Placeholder::parse_from_reader(&mut buffer.as_slice()).unwrap();
-
- assert_eq!(original, copy);
- }
+fn main() -> Result<()> {
+ let flag = Flag::try_from_text_proto(r#"id: "a" description: "description of a" value: true"#)?;
+ println!("{:?}", flag);
+ let flags = Flag::try_from_text_proto_list(
+ r#"flag { id: "a" description: "description of a" value: true }"#,
+ )?;
+ println!("{:?}", flags);
+ let override_ = Override::try_from_text_proto(r#"id: "foo" value: true"#)?;
+ println!("{:?}", override_);
+ let overrides = Override::try_from_text_proto_list(r#"override { id: "foo" value: true }"#)?;
+ println!("{:?}", overrides);
+ Ok(())
}