aconfig: allow dots in package fields
Allow package fields to include dots.
Update the generated code based on the package name: if the package name
is com.android.example:
- java: package com.android.example; ...
- C++: namespace com::android::example { ... }
- Rust: mod com { mod android { mod example { ... } } }
Also, update examples to use dots in the package fields.
Also, remove unnecessary #include from the auto-generated C++ code: the
header should not include itself.
Bug: 285000854
Test: atest aconfig.test
Change-Id: I8a5352e25c64c34dee0725202a1b7c9957819de8
diff --git a/tools/aconfig/src/commands.rs b/tools/aconfig/src/commands.rs
index bc392e8..d252bc4 100644
--- a/tools/aconfig/src/commands.rs
+++ b/tools/aconfig/src/commands.rs
@@ -186,9 +186,9 @@
use super::*;
use crate::aconfig::{FlagState, Permission};
- fn create_test_cache_ns1() -> Cache {
+ fn create_test_cache_com_example() -> Cache {
let s = r#"
- package: "ns1"
+ package: "com.example"
flag {
name: "a"
description: "Description of a"
@@ -201,19 +201,19 @@
let declarations = vec![Input { source: Source::Memory, reader: Box::new(s.as_bytes()) }];
let o = r#"
flag_value {
- package: "ns1"
+ package: "com.example"
name: "a"
state: DISABLED
permission: READ_ONLY
}
"#;
let values = vec![Input { source: Source::Memory, reader: Box::new(o.as_bytes()) }];
- create_cache("ns1", declarations, values).unwrap()
+ create_cache("com.example", declarations, values).unwrap()
}
- fn create_test_cache_ns2() -> Cache {
+ fn create_test_cache_com_other() -> Cache {
let s = r#"
- package: "ns2"
+ package: "com.other"
flag {
name: "c"
description: "Description of c"
@@ -222,19 +222,19 @@
let declarations = vec![Input { source: Source::Memory, reader: Box::new(s.as_bytes()) }];
let o = r#"
flag_value {
- package: "ns2"
+ package: "com.other"
name: "c"
state: DISABLED
permission: READ_ONLY
}
"#;
let values = vec![Input { source: Source::Memory, reader: Box::new(o.as_bytes()) }];
- create_cache("ns2", declarations, values).unwrap()
+ create_cache("com.other", declarations, values).unwrap()
}
#[test]
fn test_create_cache() {
- let caches = create_test_cache_ns1(); // calls create_cache
+ let caches = create_test_cache_com_example(); // calls create_cache
let item = caches.iter().find(|&item| item.name == "a").unwrap();
assert_eq!(FlagState::Disabled, item.state);
assert_eq!(Permission::ReadOnly, item.permission);
@@ -245,7 +245,7 @@
let caches = vec![crate::test::create_cache()];
let bytes = create_device_config_defaults(caches).unwrap();
let text = std::str::from_utf8(&bytes).unwrap();
- assert_eq!("test/disabled_rw:disabled\ntest/enabled_rw:enabled\n", text);
+ assert_eq!("com.android.aconfig.test/disabled_rw:disabled\ncom.android.aconfig.test/enabled_rw:enabled\n", text);
}
#[test]
@@ -253,12 +253,12 @@
let caches = vec![crate::test::create_cache()];
let bytes = create_device_config_sysprops(caches).unwrap();
let text = std::str::from_utf8(&bytes).unwrap();
- assert_eq!("persist.device_config.test.disabled_rw=false\npersist.device_config.test.enabled_rw=true\n", text);
+ assert_eq!("persist.device_config.com.android.aconfig.test.disabled_rw=false\npersist.device_config.com.android.aconfig.test.enabled_rw=true\n", text);
}
#[test]
fn test_dump_text_format() {
- let caches = vec![create_test_cache_ns1()];
+ let caches = vec![create_test_cache_com_example()];
let bytes = dump_cache(caches, DumpFormat::Text).unwrap();
let text = std::str::from_utf8(&bytes).unwrap();
assert!(text.contains("a: Disabled"));
@@ -269,7 +269,7 @@
use crate::protos::{ProtoFlagPermission, ProtoFlagState, ProtoTracepoint};
use protobuf::Message;
- let caches = vec![create_test_cache_ns1()];
+ let caches = vec![create_test_cache_com_example()];
let bytes = dump_cache(caches, DumpFormat::Protobuf).unwrap();
let actual = ProtoParsedFlags::parse_from_bytes(&bytes).unwrap();
@@ -280,7 +280,7 @@
let item =
actual.parsed_flag.iter().find(|item| item.name == Some("b".to_string())).unwrap();
- assert_eq!(item.package(), "ns1");
+ assert_eq!(item.package(), "com.example");
assert_eq!(item.name(), "b");
assert_eq!(item.description(), "Description of b");
assert_eq!(item.state(), ProtoFlagState::DISABLED);
@@ -294,7 +294,7 @@
#[test]
fn test_dump_multiple_caches() {
- let caches = vec![create_test_cache_ns1(), create_test_cache_ns2()];
+ let caches = vec![create_test_cache_com_example(), create_test_cache_com_other()];
let bytes = dump_cache(caches, DumpFormat::Protobuf).unwrap();
let dump = ProtoParsedFlags::parse_from_bytes(&bytes).unwrap();
assert_eq!(
@@ -302,10 +302,14 @@
.iter()
.map(|parsed_flag| format!("{}/{}", parsed_flag.package(), parsed_flag.name()))
.collect::<Vec<_>>(),
- vec!["ns1/a".to_string(), "ns1/b".to_string(), "ns2/c".to_string()]
+ vec![
+ "com.example/a".to_string(),
+ "com.example/b".to_string(),
+ "com.other/c".to_string()
+ ]
);
- let caches = vec![create_test_cache_ns2(), create_test_cache_ns1()];
+ let caches = vec![create_test_cache_com_other(), create_test_cache_com_example()];
let bytes = dump_cache(caches, DumpFormat::Protobuf).unwrap();
let dump_reversed_input = ProtoParsedFlags::parse_from_bytes(&bytes).unwrap();
assert_eq!(dump, dump_reversed_input);