Check the well-formedness of an xml file before copying.

Bug: 6491991
Change-Id: I3dbf9a7e1fefd9fea2636c78a85bae63ea8391b8
diff --git a/core/definitions.mk b/core/definitions.mk
index f82bfa5..f3e4966 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -1707,6 +1707,16 @@
 	$$(copy-file-to-target)
 endef
 
+# Copy the file only if it's a well-formed xml file. For use via $(eval).
+# $(1): source file
+# $(2): destination file, must end with .xml.
+define copy-xml-file-checked
+$(2): $(1) | $(ACP)
+	@echo "Copy xml: $$@"
+	$(hide) xmllint $$< >/dev/null  # Don't print the xml file to stdout.
+	$$(copy-file-to-target)
+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