Pretty print metadata xml file to make it easier to read

The process_compat_config.py script can generate two separate XML
files. One for consumption by the device and a separate metadata XML
file that are merged together and used for various tools and tests.

In preparation for including the metadata into the sdk snapshot, which
will be checked into git this change pretty prints the metadata to make
it easier to read and review the differences.

Forces the binary and test to use python3 as ElementTree.indent was
only added in 3.9.

Bug: 232401814
Test: atest --host process-compat-config-test CtsAppCompatHostTestCases
Change-Id: I2c7efc68722eefeca397f7b4d257d5b0c0679920
diff --git a/build/Android.bp b/build/Android.bp
index 445718e..29131b6 100644
--- a/build/Android.bp
+++ b/build/Android.bp
@@ -22,6 +22,15 @@
     name: "process-compat-config",
     main: "process_compat_config.py",
     srcs: ["process_compat_config.py"],
+    version: {
+        py2: {
+            enabled: false,
+        },
+        py3: {
+            enabled: true,
+            embedded_launcher: true,
+        },
+    },
 }
 
 python_test_host {
@@ -31,6 +40,15 @@
         "process_compat_config.py",
         "process-compat-config-test.py",
     ],
+    version: {
+        py2: {
+            enabled: false,
+        },
+        py3: {
+            enabled: true,
+            embedded_launcher: true,
+        },
+    },
     test_options: {
         unit_test: true,
     },
diff --git a/build/process-compat-config-test.py b/build/process-compat-config-test.py
index c7b4ac8..fc0f04a 100644
--- a/build/process-compat-config-test.py
+++ b/build/process-compat-config-test.py
@@ -36,9 +36,31 @@
         self.merger.write_errors_to = self.stderr
         self.xml = io.BytesIO()
 
+    def remove_white_space_text_nodes(self, node):
+        remove = []
+        # Find any child nodes that are just white space, and add them to a list
+        # to remove. Do not remove the child while iterating as that prevents
+        # the following node from being seen.
+        for child in node.childNodes:
+            if child.nodeType == node.ELEMENT_NODE:
+                self.remove_white_space_text_nodes(child)
+            elif child.nodeType == node.TEXT_NODE:
+                if str.isspace(child.data):
+                    remove.append(child)
+        # Remove any child nodes that were just white space.
+        for child in remove:
+            node.removeChild(child)
+            child.unlink()
+
+    def parse_xml(self, text):
+        node = xml.dom.minidom.parseString(text)
+        # Remove any white space text nodes as they are irrelevant.
+        self.remove_white_space_text_nodes(node)
+        return node.toprettyxml()
+
     def assert_same_xml(self, got, expected):
-        got = xml.dom.minidom.parseString(got).toprettyxml()
-        expected = xml.dom.minidom.parseString(expected).toprettyxml()
+        got = self.parse_xml(got)
+        expected = self.parse_xml(expected)
         diffs = [diff for diff in difflib.ndiff(got.split('\n'), expected.split('\n')) if not diff.startswith(" ")]
         self.assertEqual("", "\n".join(diffs), msg="Got unexpected diffs in XML")
 
diff --git a/build/process_compat_config.py b/build/process_compat_config.py
index f884092..e17b745 100755
--- a/build/process_compat_config.py
+++ b/build/process_compat_config.py
@@ -91,6 +91,7 @@
 
     def write(self, filename):
         self._check_error()
+        ET.indent(self.tree)
         self.tree.write(filename, encoding='utf-8', xml_declaration=True)
 
     def write_device_config(self, filename):