aconfig: add java codegen test mode
Add java codegen test mode. The test mode will generate Flags.java and
FeatureFlagsImpl.java differently.
* Flags.java will have getter and setter function to switch the
FeatureFlagsImpl. Flags.java will not initialize the instance
of FeatureFlagsImpl during initialization, thus it will force the
user to set up the flag values for the tests.
* FeatureFlagsImpl removes the dependency on DeviceConfig, and
allows the caller to set the values of flags.
Command changes
This change adds a new parameter `mode` to `create-java-lib` subcommand.
The default value of `mode` is production, which will generate files for
production usage, and keeps the same behavior as before.
The new `mode` test is added to trigger the test mode. The command is
aconfig create-java-lib --cache=<path_to_cache> --out=<out_path>
--mode=test
Test: atest aconfig.test
Bug: 288632682
Change-Id: I7566464eb762f3107142fe787f56b17f5be631b7
diff --git a/tools/aconfig/src/commands.rs b/tools/aconfig/src/commands.rs
index 58831cc..dd2087b 100644
--- a/tools/aconfig/src/commands.rs
+++ b/tools/aconfig/src/commands.rs
@@ -129,12 +129,18 @@
Ok(output)
}
-pub fn create_java_lib(mut input: Input) -> Result<Vec<OutputFile>> {
+#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
+pub enum CodegenMode {
+ Production,
+ Test,
+}
+
+pub fn create_java_lib(mut input: Input, codegen_mode: CodegenMode) -> Result<Vec<OutputFile>> {
let parsed_flags = input.try_parse_flags()?;
let Some(package) = find_unique_package(&parsed_flags) else {
bail!("no parsed flags, or the parsed flags use different packages");
};
- generate_java_code(package, parsed_flags.parsed_flag.iter())
+ generate_java_code(package, parsed_flags.parsed_flag.iter(), codegen_mode)
}
pub fn create_cpp_lib(mut input: Input) -> Result<OutputFile> {