aconfig: add exported mode in rust codegen
This commit adds exported mode to rust codegen.
When the codegen mode is exported
1. only flags with exported: true will be generated
2. the generated getter should be in a read_write format and with
default value as false, regardless the original permission and state
of the flag
This commit adds integration test for rust codegen exported mode.
Bug: 316357104
Test: atest aconfig.test aconfig.test_mode.test.rust aconfig.exported_mode.test.rust
Change-Id: Ib7dae666e13eb8898289b06d42a4f89326e175c4
diff --git a/tools/aconfig/templates/rust_exported.template b/tools/aconfig/templates/rust_exported.template
new file mode 100644
index 0000000..b31bcef
--- /dev/null
+++ b/tools/aconfig/templates/rust_exported.template
@@ -0,0 +1,36 @@
+//! codegenerated rust flag lib
+
+/// flag provider
+pub struct FlagProvider;
+
+lazy_static::lazy_static! \{
+ {{ for flag in template_flags }}
+ /// flag value cache for {flag.name}
+ static ref CACHED_{flag.name}: bool = flags_rust::GetServerConfigurableFlag(
+ "aconfig_flags.{flag.device_config_namespace}",
+ "{flag.device_config_flag}",
+ "false") == "true";
+ {{ endfor }}
+}
+
+impl FlagProvider \{
+
+ {{ for flag in template_flags }}
+ /// query flag {flag.name}
+ pub fn {flag.name}(&self) -> bool \{
+ *CACHED_{flag.name}
+ }
+ {{ endfor }}
+
+}
+
+/// flag provider
+pub static PROVIDER: FlagProvider = FlagProvider;
+
+{{ for flag in template_flags }}
+/// query flag {flag.name}
+#[inline(always)]
+pub fn {flag.name}() -> bool \{
+ PROVIDER.{flag.name}()
+}
+{{ endfor }}