diff options
| author | 2023-11-29 15:44:24 +0000 | |
|---|---|---|
| committer | 2023-11-29 15:44:24 +0000 | |
| commit | 4a6af78b6905b90549686b0a107c80ea8533f76c (patch) | |
| tree | 2b59669e4630a3643335d8529256a476bc0e6c34 /tools/aconfig/src/codegen_rust.rs | |
| parent | 53084d3f9177a5f07eb7446a56759ae18497b575 (diff) | |
aconfig: Add exported mode to aconfig Java library generation.
This commit adds a third codegen mode, _exported_, in addition to
the existing modes, production and test.
When codegen mode is _exported_, getters are generated _only_ for
flags marked as exported as well. Also the getters always look
up DeviceConfig values at runtime, and have a default value of
false.
This only implements exported mode for Java codegen, follow-up CLs
will support Rust and C++.
Test: atest aconfig.test
Bug: 311152507
Change-Id: Ie39379b40de072180e05d84c76361b24cc0e0d83
Diffstat (limited to 'tools/aconfig/src/codegen_rust.rs')
| -rw-r--r-- | tools/aconfig/src/codegen_rust.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tools/aconfig/src/codegen_rust.rs b/tools/aconfig/src/codegen_rust.rs index d8675e7031..502cec8cd3 100644 --- a/tools/aconfig/src/codegen_rust.rs +++ b/tools/aconfig/src/codegen_rust.rs @@ -45,6 +45,9 @@ where match codegen_mode { CodegenMode::Production => include_str!("../templates/rust_prod.template"), CodegenMode::Test => include_str!("../templates/rust_test.template"), + CodegenMode::Exported => { + todo!("exported mode not yet supported for rust, see b/313894653.") + } }, )?; let contents = template.render("rust_code_gen", &context)?; @@ -104,6 +107,12 @@ lazy_static::lazy_static! { "com.android.aconfig.test.disabled_rw", "false") == "true"; + /// flag value cache for disabled_rw_exported + static ref CACHED_disabled_rw_exported: bool = flags_rust::GetServerConfigurableFlag( + "aconfig_flags.aconfig_test", + "com.android.aconfig.test.disabled_rw_exported", + "false") == "true"; + /// flag value cache for disabled_rw_in_other_namespace static ref CACHED_disabled_rw_in_other_namespace: bool = flags_rust::GetServerConfigurableFlag( "aconfig_flags.other_namespace", @@ -115,6 +124,7 @@ lazy_static::lazy_static! { "aconfig_flags.aconfig_test", "com.android.aconfig.test.enabled_rw", "true") == "true"; + } impl FlagProvider { @@ -128,6 +138,11 @@ impl FlagProvider { *CACHED_disabled_rw } + /// query flag disabled_rw_exported + pub fn disabled_rw_exported(&self) -> bool { + *CACHED_disabled_rw_exported + } + /// query flag disabled_rw_in_other_namespace pub fn disabled_rw_in_other_namespace(&self) -> bool { *CACHED_disabled_rw_in_other_namespace @@ -164,6 +179,12 @@ pub fn disabled_rw() -> bool { PROVIDER.disabled_rw() } +/// query flag disabled_rw_exported +#[inline(always)] +pub fn disabled_rw_exported() -> bool { + PROVIDER.disabled_rw_exported() +} + /// query flag disabled_rw_in_other_namespace #[inline(always)] pub fn disabled_rw_in_other_namespace() -> bool { @@ -228,6 +249,21 @@ impl FlagProvider { self.overrides.insert("disabled_rw", val); } + /// query flag disabled_rw_exported + pub fn disabled_rw_exported(&self) -> bool { + self.overrides.get("disabled_rw_exported").copied().unwrap_or( + flags_rust::GetServerConfigurableFlag( + "aconfig_flags.aconfig_test", + "com.android.aconfig.test.disabled_rw_exported", + "false") == "true" + ) + } + + /// set flag disabled_rw_exported + pub fn set_disabled_rw_exported(&mut self, val: bool) { + self.overrides.insert("disabled_rw_exported", val); + } + /// query flag disabled_rw_in_other_namespace pub fn disabled_rw_in_other_namespace(&self) -> bool { self.overrides.get("disabled_rw_in_other_namespace").copied().unwrap_or( @@ -317,6 +353,18 @@ pub fn set_disabled_rw(val: bool) { PROVIDER.lock().unwrap().set_disabled_rw(val); } +/// query flag disabled_rw_exported +#[inline(always)] +pub fn disabled_rw_exported() -> bool { + PROVIDER.lock().unwrap().disabled_rw_exported() +} + +/// set flag disabled_rw_exported +#[inline(always)] +pub fn set_disabled_rw_exported(val: bool) { + PROVIDER.lock().unwrap().set_disabled_rw_exported(val); +} + /// query flag disabled_rw_in_other_namespace #[inline(always)] pub fn disabled_rw_in_other_namespace() -> bool { @@ -383,6 +431,8 @@ pub fn reset_flags() { match mode { CodegenMode::Production => PROD_EXPECTED, CodegenMode::Test => TEST_EXPECTED, + CodegenMode::Exported => + todo!("exported mode not yet supported for rust, see b/313894653."), }, &String::from_utf8(generated.contents).unwrap() ) |