1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 02:00:45 +00:00

utils/android: Switch to using the lxml module

Using dexdump from versions 30.0.1-30.0.3 of Android build tools
does not produce valid XML caused by certain APKs
Use the lxml module for parsing xml as it is more robust and
better equipped to handle errors in input.
This commit is contained in:
Marc Bonnici 2021-01-05 16:55:48 +00:00 committed by setrofim
parent e251b158b2
commit e3da419e5b
2 changed files with 7 additions and 2 deletions

View File

@ -29,10 +29,11 @@ import sys
import tempfile import tempfile
import time import time
import uuid import uuid
import xml.etree.ElementTree
import zipfile import zipfile
from collections import defaultdict from collections import defaultdict
from io import StringIO
from lxml import etree
try: try:
from shlex import quote from shlex import quote
@ -228,7 +229,10 @@ class ApkInfo(object):
command = [dexdump, '-l', 'xml', extracted] command = [dexdump, '-l', 'xml', extracted]
dump = self._run(command) dump = self._run(command)
xml_tree = xml.etree.ElementTree.fromstring(dump) # Dexdump from build tools v30.0.X does not seem to produce
# valid xml from certain APKs so ignore errors and attempt to recover.
parser = etree.XMLParser(encoding='utf-8', recover=True)
xml_tree = etree.parse(StringIO(dump), parser)
package = next((i for i in xml_tree.iter('package') package = next((i for i in xml_tree.iter('package')
if i.attrib['name'] == self.package), None) if i.attrib['name'] == self.package), None)

View File

@ -92,6 +92,7 @@ params = dict(
'numpy; python_version>="3"', 'numpy; python_version>="3"',
'pandas<=0.24.2; python_version<"3"', 'pandas<=0.24.2; python_version<"3"',
'pandas; python_version>"3"', 'pandas; python_version>"3"',
'lxml', # More robust xml parsing
], ],
extras_require={ extras_require={
'daq': ['daqpower>=2'], 'daq': ['daqpower>=2'],