Merge "aconfig: add c codegen" into main am: afd8b2d75b
Original change: https://android-review.googlesource.com/c/platform/build/+/2653700 Change-Id: Id128c68dfa1b48bcc0a15d85423cd04bc31b42ea Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -67,6 +67,16 @@ where
|
|||||||
},
|
},
|
||||||
dir: "",
|
dir: "",
|
||||||
},
|
},
|
||||||
|
FileSpec {
|
||||||
|
name: &format!("{}_c.h", header),
|
||||||
|
template: include_str!("../templates/c_exported_header.template"),
|
||||||
|
dir: "include",
|
||||||
|
},
|
||||||
|
FileSpec {
|
||||||
|
name: &format!("{}_c.cc", header),
|
||||||
|
template: include_str!("../templates/c_source_file.template"),
|
||||||
|
dir: "",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
files.iter().map(|file| generate_file(file, &context)).collect()
|
files.iter().map(|file| generate_file(file, &context)).collect()
|
||||||
}
|
}
|
||||||
@@ -387,6 +397,71 @@ namespace com::android::aconfig::test {
|
|||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
|
const C_EXPORTED_HEADER_EXPECTED: &str = r#"
|
||||||
|
#ifndef com_android_aconfig_test_c_HEADER_H
|
||||||
|
#define com_android_aconfig_test_c_HEADER_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern const char* com_android_aconfig_test_DISABLED_RO;
|
||||||
|
extern const char* com_android_aconfig_test_DISABLED_RW;
|
||||||
|
extern const char* com_android_aconfig_test_ENABLED_RO;
|
||||||
|
extern const char* com_android_aconfig_test_ENABLED_RW;
|
||||||
|
|
||||||
|
bool com_android_aconfig_test_disabled_ro();
|
||||||
|
|
||||||
|
bool com_android_aconfig_test_disabled_rw();
|
||||||
|
|
||||||
|
bool com_android_aconfig_test_enabled_ro();
|
||||||
|
|
||||||
|
bool com_android_aconfig_test_enabled_rw();
|
||||||
|
|
||||||
|
void com_android_aconfig_test_override_flag(const char* name, bool val);
|
||||||
|
|
||||||
|
void com_android_aconfig_test_reset_overrides();
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
"#;
|
||||||
|
|
||||||
|
const C_SOURCE_FILE_EXPECTED: &str = r#"
|
||||||
|
#include "com_android_aconfig_test_c.h"
|
||||||
|
#include "com_android_aconfig_test.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
const char* com_android_aconfig_test_DISABLED_RO = "com.android.aconfig.test.disabled_ro";
|
||||||
|
const char* com_android_aconfig_test_DISABLED_RW = "com.android.aconfig.test.disabled_rw";
|
||||||
|
const char* com_android_aconfig_test_ENABLED_RO = "com.android.aconfig.test.enabled_ro";
|
||||||
|
const char* com_android_aconfig_test_ENABLED_RW = "com.android.aconfig.test.enabled_rw";
|
||||||
|
|
||||||
|
bool com_android_aconfig_test_disabled_ro() {
|
||||||
|
return com::android::aconfig::test::disabled_ro();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool com_android_aconfig_test_disabled_rw() {
|
||||||
|
return com::android::aconfig::test::disabled_rw();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool com_android_aconfig_test_enabled_ro() {
|
||||||
|
return com::android::aconfig::test::enabled_ro();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool com_android_aconfig_test_enabled_rw() {
|
||||||
|
return com::android::aconfig::test::enabled_rw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void com_android_aconfig_test_override_flag(const char* name, bool val) {
|
||||||
|
com::android::aconfig::test::override_flag(std::string(name), val);
|
||||||
|
}
|
||||||
|
|
||||||
|
void com_android_aconfig_test_reset_overrides() {
|
||||||
|
com::android::aconfig::test::reset_overrides();
|
||||||
|
}
|
||||||
|
"#;
|
||||||
fn test_generate_cpp_code(mode: CodegenMode) {
|
fn test_generate_cpp_code(mode: CodegenMode) {
|
||||||
let parsed_flags = crate::test::parse_test_flags();
|
let parsed_flags = crate::test::parse_test_flags();
|
||||||
let generated =
|
let generated =
|
||||||
@@ -435,6 +510,26 @@ namespace com::android::aconfig::test {
|
|||||||
generated_files_map.get(&target_file_path).unwrap()
|
generated_files_map.get(&target_file_path).unwrap()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
target_file_path = String::from("include/com_android_aconfig_test_c.h");
|
||||||
|
assert!(generated_files_map.contains_key(&target_file_path));
|
||||||
|
assert_eq!(
|
||||||
|
None,
|
||||||
|
crate::test::first_significant_code_diff(
|
||||||
|
C_EXPORTED_HEADER_EXPECTED,
|
||||||
|
generated_files_map.get(&target_file_path).unwrap()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
target_file_path = String::from("com_android_aconfig_test_c.cc");
|
||||||
|
assert!(generated_files_map.contains_key(&target_file_path));
|
||||||
|
assert_eq!(
|
||||||
|
None,
|
||||||
|
crate::test::first_significant_code_diff(
|
||||||
|
C_SOURCE_FILE_EXPECTED,
|
||||||
|
generated_files_map.get(&target_file_path).unwrap()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
22
tools/aconfig/templates/c_exported_header.template
Normal file
22
tools/aconfig/templates/c_exported_header.template
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#ifndef {header}_c_HEADER_H
|
||||||
|
#define {header}_c_HEADER_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" \{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
{{ for item in class_elements}}
|
||||||
|
extern const char* {header}_{item.uppercase_flag_name};
|
||||||
|
{{ endfor -}}
|
||||||
|
|
||||||
|
{{ for item in class_elements}}
|
||||||
|
bool {header}_{item.flag_name}();{{ endfor }}
|
||||||
|
|
||||||
|
void {header}_override_flag(const char* name, bool val);
|
||||||
|
|
||||||
|
void {header}_reset_overrides();
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
21
tools/aconfig/templates/c_source_file.template
Normal file
21
tools/aconfig/templates/c_source_file.template
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void {header}_reset_overrides() \{
|
||||||
|
{cpp_namespace}::reset_overrides();
|
||||||
|
}
|
Reference in New Issue
Block a user