Support manifest fragments.

LOCAL_VINTF_FRAGMENTS/vintf_fragments are
used to specify what manifest fragments should be installed
by a target.

Test: fragments get installed to the right location
Test: broken fragment gets detected
Test: boot device and verify service is working and manifest is updated
Test: verify OTA package contains fragments
Bug: 66917623
Change-Id: I21abe65a31b8c3d255c8ccd80e102ff3acb23105
diff --git a/core/definitions.mk b/core/definitions.mk
index e259e19..de157e6 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -99,6 +99,9 @@
 # All installed initrc files
 ALL_INIT_RC_INSTALLED_PAIRS :=
 
+# All installed vintf manifest fragments for a partition at
+ALL_VINTF_MANIFEST_FRAGMENTS_LIST:=
+
 ###########################################################
 ## Debugging; prints a variable list to stdout
 ###########################################################
@@ -2662,6 +2665,28 @@
 	$$(copy-file-to-target)
 endef
 
+# Copy the file only if it is a well-formed manifest file. For use viea $(eval)
+# $(1): source file
+# $(2): destination file
+define copy-vintf-manifest-checked
+$(2): $(1) $(HOST_OUT_EXECUTABLES)/assemble_vintf
+	@echo "Copy xml: $$@"
+	$(hide) $(HOST_OUT_EXECUTABLES)/assemble_vintf -i $$< >/dev/null  # Don't print the xml file to stdout.
+	$$(copy-file-to-target)
+endef
+
+# Copies many vintf manifest files checked.
+# $(1): The files to copy.  Each entry is a ':' separated src:dst pair
+# Evaluates to the list of the dst files (ie suitable for a dependency list)
+define copy-many-vintf-manifest-files-checked
+$(foreach f, $(1), $(strip \
+    $(eval _cmf_tuple := $(subst :, ,$(f))) \
+    $(eval _cmf_src := $(word 1,$(_cmf_tuple))) \
+    $(eval _cmf_dest := $(word 2,$(_cmf_tuple))) \
+    $(eval $(call copy-vintf-manifest-checked,$(_cmf_src),$(_cmf_dest))) \
+    $(_cmf_dest)))
+endef
+
 # The -t option to acp and the -p option to cp is
 # required for OSX.  OSX has a ridiculous restriction
 # where it's an error for a .a file's modification time