Loading tools/aconfig/aconfig/src/codegen/rust.rs +267 −286 Original line number Diff line number Diff line Loading @@ -113,6 +113,7 @@ mod tests { use aconfig_storage_read_api::{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context}; use std::path::Path; use std::io::Write; use std::sync::LazyLock; use log::{log, LevelFilter, Level}; static STORAGE_MIGRATION_MARKER_FILE: &str = Loading @@ -123,36 +124,28 @@ static MIGRATION_LOG_TAG: &str = "AconfigTestMission1"; pub struct FlagProvider; /// flag value cache for disabled_rw lazy_static::lazy_static! { static ref CACHED_disabled_rw: bool = flags_rust::GetServerConfigurableFlag( static CACHED_disabled_rw: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag( "aconfig_flags.aconfig_test", "com.android.aconfig.test.disabled_rw", "false") == "true"; } "false") == "true"); /// flag value cache for disabled_rw_exported lazy_static::lazy_static! { static ref CACHED_disabled_rw_exported: bool = flags_rust::GetServerConfigurableFlag( static CACHED_disabled_rw_exported: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag( "aconfig_flags.aconfig_test", "com.android.aconfig.test.disabled_rw_exported", "false") == "true"; } "false") == "true"); /// flag value cache for disabled_rw_in_other_namespace lazy_static::lazy_static! { static ref CACHED_disabled_rw_in_other_namespace: bool = flags_rust::GetServerConfigurableFlag( static CACHED_disabled_rw_in_other_namespace: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag( "aconfig_flags.other_namespace", "com.android.aconfig.test.disabled_rw_in_other_namespace", "false") == "true"; } "false") == "true"); /// flag value cache for enabled_rw lazy_static::lazy_static! { static ref CACHED_enabled_rw: bool = flags_rust::GetServerConfigurableFlag( static CACHED_enabled_rw: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag( "aconfig_flags.aconfig_test", "com.android.aconfig.test.enabled_rw", "true") == "true"; } "true") == "true"); impl FlagProvider { /// query flag disabled_ro Loading Loading @@ -264,6 +257,7 @@ pub fn enabled_rw() -> bool { use aconfig_storage_read_api::{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context}; use std::path::Path; use std::io::Write; use std::sync::LazyLock; use log::{log, LevelFilter, Level}; static STORAGE_MIGRATION_MARKER_FILE: &str = Loading @@ -273,21 +267,18 @@ static MIGRATION_LOG_TAG: &str = "AconfigTestMission1"; /// flag provider pub struct FlagProvider; lazy_static::lazy_static! { static ref PACKAGE_OFFSET: Result<Option<u32>, AconfigStorageError> = unsafe { static PACKAGE_OFFSET: LazyLock<Result<Option<u32>, AconfigStorageError>> = LazyLock::new(|| unsafe { get_mapped_storage_file("system", StorageFileType::PackageMap) .and_then(|package_map| get_package_read_context(&package_map, "com.android.aconfig.test")) .map(|context| context.map(|c| c.boolean_start_index)) }; }); static ref FLAG_VAL_MAP: Result<Mmap, AconfigStorageError> = unsafe { static FLAG_VAL_MAP: LazyLock<Result<Mmap, AconfigStorageError>> = LazyLock::new(|| unsafe { get_mapped_storage_file("system", StorageFileType::FlagVal) }; } }); /// flag value cache for disabled_rw lazy_static::lazy_static! { static ref CACHED_disabled_rw: bool = { static CACHED_disabled_rw: LazyLock<bool> = LazyLock::new(|| { let result = flags_rust::GetServerConfigurableFlag( "aconfig_flags.aconfig_test", "com.android.aconfig.test.disabled_rw", Loading Loading @@ -349,12 +340,10 @@ lazy_static::lazy_static! { } result }; } }); /// flag value cache for disabled_rw_exported lazy_static::lazy_static! { static ref CACHED_disabled_rw_exported: bool = { static CACHED_disabled_rw_exported: LazyLock<bool> = LazyLock::new(|| { let result = flags_rust::GetServerConfigurableFlag( "aconfig_flags.aconfig_test", "com.android.aconfig.test.disabled_rw_exported", Loading Loading @@ -416,12 +405,10 @@ lazy_static::lazy_static! { } result }; } }); /// flag value cache for disabled_rw_in_other_namespace lazy_static::lazy_static! { static ref CACHED_disabled_rw_in_other_namespace: bool = { static CACHED_disabled_rw_in_other_namespace: LazyLock<bool> = LazyLock::new(|| { let result = flags_rust::GetServerConfigurableFlag( "aconfig_flags.other_namespace", "com.android.aconfig.test.disabled_rw_in_other_namespace", Loading Loading @@ -483,12 +470,11 @@ lazy_static::lazy_static! { } result }; } }); /// flag value cache for enabled_rw lazy_static::lazy_static! { static ref CACHED_enabled_rw: bool = { static CACHED_enabled_rw: LazyLock<bool> = LazyLock::new(|| { let result = flags_rust::GetServerConfigurableFlag( "aconfig_flags.aconfig_test", "com.android.aconfig.test.enabled_rw", Loading Loading @@ -550,8 +536,7 @@ lazy_static::lazy_static! { } result }; } }); impl FlagProvider { Loading Loading @@ -1215,6 +1200,7 @@ pub fn reset_flags() { use aconfig_storage_read_api::{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context}; use std::path::Path; use std::io::Write; use std::sync::LazyLock; use log::{log, LevelFilter, Level}; static STORAGE_MIGRATION_MARKER_FILE: &str = Loading @@ -1225,28 +1211,22 @@ static MIGRATION_LOG_TAG: &str = "AconfigTestMission1"; pub struct FlagProvider; /// flag value cache for disabled_rw_exported lazy_static::lazy_static! { static ref CACHED_disabled_rw_exported: bool = flags_rust::GetServerConfigurableFlag( static CACHED_disabled_rw_exported: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag( "aconfig_flags.aconfig_test", "com.android.aconfig.test.disabled_rw_exported", "false") == "true"; } "false") == "true"); /// flag value cache for enabled_fixed_ro_exported lazy_static::lazy_static! { static ref CACHED_enabled_fixed_ro_exported: bool = flags_rust::GetServerConfigurableFlag( static CACHED_enabled_fixed_ro_exported: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag( "aconfig_flags.aconfig_test", "com.android.aconfig.test.enabled_fixed_ro_exported", "false") == "true"; } "false") == "true"); /// flag value cache for enabled_ro_exported lazy_static::lazy_static! { static ref CACHED_enabled_ro_exported: bool = flags_rust::GetServerConfigurableFlag( static CACHED_enabled_ro_exported: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag( "aconfig_flags.aconfig_test", "com.android.aconfig.test.enabled_ro_exported", "false") == "true"; } "false") == "true"); impl FlagProvider { /// query flag disabled_rw_exported Loading Loading @@ -1292,6 +1272,7 @@ pub fn enabled_ro_exported() -> bool { use aconfig_storage_read_api::{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context}; use std::path::Path; use std::io::Write; use std::sync::LazyLock; use log::{log, LevelFilter, Level}; static STORAGE_MIGRATION_MARKER_FILE: &str = Loading tools/aconfig/aconfig/templates/rust.template +73 −78 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ use aconfig_storage_read_api::\{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context}; use std::path::Path; use std::io::Write; use std::sync::LazyLock; use log::\{log, LevelFilter, Level}; static STORAGE_MIGRATION_MARKER_FILE: &str = Loading @@ -13,25 +14,22 @@ pub struct FlagProvider; {{ if has_readwrite- }} {{ if allow_instrumentation }} lazy_static::lazy_static! \{ static ref PACKAGE_OFFSET: Result<Option<u32>, AconfigStorageError> = unsafe \{ static PACKAGE_OFFSET: LazyLock<Result<Option<u32>, AconfigStorageError>> = LazyLock::new(|| unsafe \{ get_mapped_storage_file("{container}", StorageFileType::PackageMap) .and_then(|package_map| get_package_read_context(&package_map, "{package}")) .map(|context| context.map(|c| c.boolean_start_index)) }; }); static ref FLAG_VAL_MAP: Result<Mmap, AconfigStorageError> = unsafe \{ static FLAG_VAL_MAP: LazyLock<Result<Mmap, AconfigStorageError>> = LazyLock::new(|| unsafe \{ get_mapped_storage_file("{container}", StorageFileType::FlagVal) }; } }); {{ -endif }} {{ -for flag in template_flags }} {{ -if flag.readwrite }} /// flag value cache for {flag.name} {{ if allow_instrumentation }} lazy_static::lazy_static! \{ static ref CACHED_{flag.name}: bool = \{ static CACHED_{flag.name}: LazyLock<bool> = LazyLock::new(|| \{ let result = flags_rust::GetServerConfigurableFlag( "aconfig_flags.{flag.device_config_namespace}", "{flag.device_config_flag}", Loading Loading @@ -93,15 +91,12 @@ lazy_static::lazy_static! \{ } result }; } }); {{ else }} lazy_static::lazy_static! \{ static ref CACHED_{flag.name}: bool = flags_rust::GetServerConfigurableFlag( static CACHED_{flag.name}: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag( "aconfig_flags.{flag.device_config_namespace}", "{flag.device_config_flag}", "{flag.default_value}") == "true"; } "{flag.default_value}") == "true"); {{ endif }} {{ -endif }} {{ -endfor }} Loading Loading
tools/aconfig/aconfig/src/codegen/rust.rs +267 −286 Original line number Diff line number Diff line Loading @@ -113,6 +113,7 @@ mod tests { use aconfig_storage_read_api::{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context}; use std::path::Path; use std::io::Write; use std::sync::LazyLock; use log::{log, LevelFilter, Level}; static STORAGE_MIGRATION_MARKER_FILE: &str = Loading @@ -123,36 +124,28 @@ static MIGRATION_LOG_TAG: &str = "AconfigTestMission1"; pub struct FlagProvider; /// flag value cache for disabled_rw lazy_static::lazy_static! { static ref CACHED_disabled_rw: bool = flags_rust::GetServerConfigurableFlag( static CACHED_disabled_rw: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag( "aconfig_flags.aconfig_test", "com.android.aconfig.test.disabled_rw", "false") == "true"; } "false") == "true"); /// flag value cache for disabled_rw_exported lazy_static::lazy_static! { static ref CACHED_disabled_rw_exported: bool = flags_rust::GetServerConfigurableFlag( static CACHED_disabled_rw_exported: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag( "aconfig_flags.aconfig_test", "com.android.aconfig.test.disabled_rw_exported", "false") == "true"; } "false") == "true"); /// flag value cache for disabled_rw_in_other_namespace lazy_static::lazy_static! { static ref CACHED_disabled_rw_in_other_namespace: bool = flags_rust::GetServerConfigurableFlag( static CACHED_disabled_rw_in_other_namespace: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag( "aconfig_flags.other_namespace", "com.android.aconfig.test.disabled_rw_in_other_namespace", "false") == "true"; } "false") == "true"); /// flag value cache for enabled_rw lazy_static::lazy_static! { static ref CACHED_enabled_rw: bool = flags_rust::GetServerConfigurableFlag( static CACHED_enabled_rw: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag( "aconfig_flags.aconfig_test", "com.android.aconfig.test.enabled_rw", "true") == "true"; } "true") == "true"); impl FlagProvider { /// query flag disabled_ro Loading Loading @@ -264,6 +257,7 @@ pub fn enabled_rw() -> bool { use aconfig_storage_read_api::{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context}; use std::path::Path; use std::io::Write; use std::sync::LazyLock; use log::{log, LevelFilter, Level}; static STORAGE_MIGRATION_MARKER_FILE: &str = Loading @@ -273,21 +267,18 @@ static MIGRATION_LOG_TAG: &str = "AconfigTestMission1"; /// flag provider pub struct FlagProvider; lazy_static::lazy_static! { static ref PACKAGE_OFFSET: Result<Option<u32>, AconfigStorageError> = unsafe { static PACKAGE_OFFSET: LazyLock<Result<Option<u32>, AconfigStorageError>> = LazyLock::new(|| unsafe { get_mapped_storage_file("system", StorageFileType::PackageMap) .and_then(|package_map| get_package_read_context(&package_map, "com.android.aconfig.test")) .map(|context| context.map(|c| c.boolean_start_index)) }; }); static ref FLAG_VAL_MAP: Result<Mmap, AconfigStorageError> = unsafe { static FLAG_VAL_MAP: LazyLock<Result<Mmap, AconfigStorageError>> = LazyLock::new(|| unsafe { get_mapped_storage_file("system", StorageFileType::FlagVal) }; } }); /// flag value cache for disabled_rw lazy_static::lazy_static! { static ref CACHED_disabled_rw: bool = { static CACHED_disabled_rw: LazyLock<bool> = LazyLock::new(|| { let result = flags_rust::GetServerConfigurableFlag( "aconfig_flags.aconfig_test", "com.android.aconfig.test.disabled_rw", Loading Loading @@ -349,12 +340,10 @@ lazy_static::lazy_static! { } result }; } }); /// flag value cache for disabled_rw_exported lazy_static::lazy_static! { static ref CACHED_disabled_rw_exported: bool = { static CACHED_disabled_rw_exported: LazyLock<bool> = LazyLock::new(|| { let result = flags_rust::GetServerConfigurableFlag( "aconfig_flags.aconfig_test", "com.android.aconfig.test.disabled_rw_exported", Loading Loading @@ -416,12 +405,10 @@ lazy_static::lazy_static! { } result }; } }); /// flag value cache for disabled_rw_in_other_namespace lazy_static::lazy_static! { static ref CACHED_disabled_rw_in_other_namespace: bool = { static CACHED_disabled_rw_in_other_namespace: LazyLock<bool> = LazyLock::new(|| { let result = flags_rust::GetServerConfigurableFlag( "aconfig_flags.other_namespace", "com.android.aconfig.test.disabled_rw_in_other_namespace", Loading Loading @@ -483,12 +470,11 @@ lazy_static::lazy_static! { } result }; } }); /// flag value cache for enabled_rw lazy_static::lazy_static! { static ref CACHED_enabled_rw: bool = { static CACHED_enabled_rw: LazyLock<bool> = LazyLock::new(|| { let result = flags_rust::GetServerConfigurableFlag( "aconfig_flags.aconfig_test", "com.android.aconfig.test.enabled_rw", Loading Loading @@ -550,8 +536,7 @@ lazy_static::lazy_static! { } result }; } }); impl FlagProvider { Loading Loading @@ -1215,6 +1200,7 @@ pub fn reset_flags() { use aconfig_storage_read_api::{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context}; use std::path::Path; use std::io::Write; use std::sync::LazyLock; use log::{log, LevelFilter, Level}; static STORAGE_MIGRATION_MARKER_FILE: &str = Loading @@ -1225,28 +1211,22 @@ static MIGRATION_LOG_TAG: &str = "AconfigTestMission1"; pub struct FlagProvider; /// flag value cache for disabled_rw_exported lazy_static::lazy_static! { static ref CACHED_disabled_rw_exported: bool = flags_rust::GetServerConfigurableFlag( static CACHED_disabled_rw_exported: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag( "aconfig_flags.aconfig_test", "com.android.aconfig.test.disabled_rw_exported", "false") == "true"; } "false") == "true"); /// flag value cache for enabled_fixed_ro_exported lazy_static::lazy_static! { static ref CACHED_enabled_fixed_ro_exported: bool = flags_rust::GetServerConfigurableFlag( static CACHED_enabled_fixed_ro_exported: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag( "aconfig_flags.aconfig_test", "com.android.aconfig.test.enabled_fixed_ro_exported", "false") == "true"; } "false") == "true"); /// flag value cache for enabled_ro_exported lazy_static::lazy_static! { static ref CACHED_enabled_ro_exported: bool = flags_rust::GetServerConfigurableFlag( static CACHED_enabled_ro_exported: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag( "aconfig_flags.aconfig_test", "com.android.aconfig.test.enabled_ro_exported", "false") == "true"; } "false") == "true"); impl FlagProvider { /// query flag disabled_rw_exported Loading Loading @@ -1292,6 +1272,7 @@ pub fn enabled_ro_exported() -> bool { use aconfig_storage_read_api::{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context}; use std::path::Path; use std::io::Write; use std::sync::LazyLock; use log::{log, LevelFilter, Level}; static STORAGE_MIGRATION_MARKER_FILE: &str = Loading
tools/aconfig/aconfig/templates/rust.template +73 −78 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ use aconfig_storage_read_api::\{Mmap, AconfigStorageError, StorageFileType, PackageReadContext, get_mapped_storage_file, get_boolean_flag_value, get_package_read_context}; use std::path::Path; use std::io::Write; use std::sync::LazyLock; use log::\{log, LevelFilter, Level}; static STORAGE_MIGRATION_MARKER_FILE: &str = Loading @@ -13,25 +14,22 @@ pub struct FlagProvider; {{ if has_readwrite- }} {{ if allow_instrumentation }} lazy_static::lazy_static! \{ static ref PACKAGE_OFFSET: Result<Option<u32>, AconfigStorageError> = unsafe \{ static PACKAGE_OFFSET: LazyLock<Result<Option<u32>, AconfigStorageError>> = LazyLock::new(|| unsafe \{ get_mapped_storage_file("{container}", StorageFileType::PackageMap) .and_then(|package_map| get_package_read_context(&package_map, "{package}")) .map(|context| context.map(|c| c.boolean_start_index)) }; }); static ref FLAG_VAL_MAP: Result<Mmap, AconfigStorageError> = unsafe \{ static FLAG_VAL_MAP: LazyLock<Result<Mmap, AconfigStorageError>> = LazyLock::new(|| unsafe \{ get_mapped_storage_file("{container}", StorageFileType::FlagVal) }; } }); {{ -endif }} {{ -for flag in template_flags }} {{ -if flag.readwrite }} /// flag value cache for {flag.name} {{ if allow_instrumentation }} lazy_static::lazy_static! \{ static ref CACHED_{flag.name}: bool = \{ static CACHED_{flag.name}: LazyLock<bool> = LazyLock::new(|| \{ let result = flags_rust::GetServerConfigurableFlag( "aconfig_flags.{flag.device_config_namespace}", "{flag.device_config_flag}", Loading Loading @@ -93,15 +91,12 @@ lazy_static::lazy_static! \{ } result }; } }); {{ else }} lazy_static::lazy_static! \{ static ref CACHED_{flag.name}: bool = flags_rust::GetServerConfigurableFlag( static CACHED_{flag.name}: LazyLock<bool> = LazyLock::new(|| flags_rust::GetServerConfigurableFlag( "aconfig_flags.{flag.device_config_namespace}", "{flag.device_config_flag}", "{flag.default_value}") == "true"; } "{flag.default_value}") == "true"); {{ endif }} {{ -endif }} {{ -endfor }} Loading