Automatically generate section_list.cpp file from incident.proto
with the SectionFlags field annotations

Bug: 64728679
Test: tested manually on device
Change-Id: I5b067b09cd6ccc3528f0845d7290cc9e2bc63a07
diff --git a/cmds/incidentd/Android.mk b/cmds/incidentd/Android.mk
index 3b15634..835a7b9 100644
--- a/cmds/incidentd/Android.mk
+++ b/cmds/incidentd/Android.mk
@@ -29,8 +29,7 @@
         src/Section.cpp \
         src/main.cpp \
         src/protobuf.cpp \
-        src/report_directory.cpp \
-        src/section_list.cpp \
+        src/report_directory.cpp
 
 LOCAL_CFLAGS += \
         -Wall -Werror -Wno-missing-field-initializers -Wno-unused-variable -Wunused-parameter
@@ -44,6 +43,8 @@
             -Os
 endif
 
+LOCAL_C_INCLUDES += $(LOCAL_PATH)/src
+
 LOCAL_SHARED_LIBRARIES := \
         libbase \
         libbinder \
@@ -54,6 +55,20 @@
         libservices \
         libutils
 
+LOCAL_MODULE_CLASS := EXECUTABLES
+gen_src_dir := $(local-generated-sources-dir)
+
+GEN := $(gen_src_dir)/src/section_list.cpp
+$(GEN): $(HOST_OUT_EXECUTABLES)/incident-section-gen
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+    $(HOST_OUT_EXECUTABLES)/incident-section-gen incidentd > $@
+$(GEN): $(HOST_OUT_EXECUTABLES)/incident-section-gen
+	$(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+gen_src_dir:=
+GEN:=
+
 LOCAL_INIT_RC := incidentd.rc
 
 include $(BUILD_EXECUTABLE)
@@ -78,7 +93,7 @@
     src/Section.cpp \
     src/protobuf.cpp \
     src/report_directory.cpp \
-    src/section_list.cpp \
+    tests/section_list.cpp \
     tests/FdBuffer_test.cpp \
     tests/Reporter_test.cpp \
     tests/Section_test.cpp \