aconfig: update c/c++ codegen
Two major changes to c/c++ codegen
(1) explicit setter for each flag instead of a generic flag setter
void override_flag(std::string name, bool val) is replaced with
void <flag name>(bool val) for each flag name
This has several advantages:
(a) generated code is more c++ idomatic
(b) no longer need to create flag name string constants
(c) any typo in the code is caught early in the build time
(2) remove flag setter and flag override reset methods/functions when
generating code targets for production. If developers want to update
their main function to take command line arg for flag overrides, they
can use compile time macros to decide if the flag override code should
be included.
Bug: b/279483801
Test: atest aconfig.test
Change-Id: I6141f7f979b32fe0426154d578edeb997ae5ff7c
diff --git a/tools/aconfig/templates/c_source_file.template b/tools/aconfig/templates/c_source_file.template
index 18da299..3d2482d 100644
--- a/tools/aconfig/templates/c_source_file.template
+++ b/tools/aconfig/templates/c_source_file.template
@@ -1,21 +1,20 @@
#include "{header}_c.h"
#include "{header}.h"
-#include <string>
-
-{{ for item in class_elements}}
-const char* {header}_{item.uppercase_flag_name} = "{item.device_config_flag}";
-{{ endfor - }}
{{ for item in class_elements}}
bool {header}_{item.flag_name}() \{
return {cpp_namespace}::{item.flag_name}();
}
-{{ endfor }}
-void {header}_override_flag(const char* name, bool val) \{
- {cpp_namespace}::override_flag(std::string(name), val);
+{{ if for_test }}
+void set_{header}_{item.flag_name}(bool val) \{
+ {cpp_namespace}::{item.flag_name}(val);
}
+{{ -endif }}
+{{ endfor -}}
-void {header}_reset_overrides() \{
- {cpp_namespace}::reset_overrides();
+{{ if for_test }}
+void {header}_reset_flags() \{
+ {cpp_namespace}::reset_flags();
}
+{{ -endif }}