summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHsin-Yi Chen <hsinyichen@google.com>2020-06-23 12:02:07 +0800
committerHsin-Yi Chen <hsinyichen@google.com>2020-06-23 06:02:33 +0000
commit97e65cac9fab46b50fb3d1ff6c5e8aacd942a61e (patch)
tree454a69f6f6dbefa152a49d94e4435008e26af893
parent9a9537112ba71c5412b14d0d05c32feff67f65bd (diff)
downloadvndk-97e65cac9fab46b50fb3d1ff6c5e8aacd942a61e.tar.gz
Convert extract_lsdump to python3android-r-beta-3android-r-beta-2
This commit converts extract_lsdump to a python3 host binary, and corrects the shebang of utils.py and vts_vndk_dependency_test.py. Test: LD_LIBRARY_PATH=out/host/linux-x86/lib64 atest vts_vndk_abi_test Test: ./extract_lsdump.py libc++.so.lsdump test.json Bug: 149175823 Change-Id: Iff8d9134fac3f955ea2740ab46c3bf628230ca33
-rw-r--r--dependency/vts_vndk_dependency_test.py2
-rw-r--r--golden/Android.bp6
-rwxr-xr-xgolden/extract_lsdump.py33
-rw-r--r--utils.py2
4 files changed, 22 insertions, 21 deletions
diff --git a/dependency/vts_vndk_dependency_test.py b/dependency/vts_vndk_dependency_test.py
index fb0431a..4e37c90 100644
--- a/dependency/vts_vndk_dependency_test.py
+++ b/dependency/vts_vndk_dependency_test.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# Copyright (C) 2020 The Android Open Source Project
#
diff --git a/golden/Android.bp b/golden/Android.bp
index c9abdaa..f5230f4 100644
--- a/golden/Android.bp
+++ b/golden/Android.bp
@@ -18,11 +18,11 @@ python_binary_host {
srcs: ["extract_lsdump.py"],
version: {
py2: {
- enabled: true,
- embedded_launcher: true,
+ enabled: false,
},
py3: {
- enabled: false,
+ enabled: true,
+ embedded_launcher: true,
},
}
}
diff --git a/golden/extract_lsdump.py b/golden/extract_lsdump.py
index fd42be6..8849d48 100755
--- a/golden/extract_lsdump.py
+++ b/golden/extract_lsdump.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# Copyright (C) 2018 The Android Open Source Project
#
@@ -19,6 +19,7 @@ import argparse
import gzip
import json
import os
+import sys
import zipfile
@@ -45,27 +46,27 @@ class AttrDict(dict):
def _GetTypeSymbol(record_type):
"""Gets the mangled name of a record type.
- Before Android R, unique_id was mangled name starting with "_ZTS".
+ Before Android R, unique_id was mangled name starting with '_ZTS'.
linker_set_key was unmangled.
Since Android R, unique_id has been removed, and linker_set_key has
- been changed to mangled name starting with "_ZTI".
+ been changed to mangled name starting with '_ZTI'.
Args:
record_type: An AttrDict, a record type in lsdump.
Returns:
- A string, the mangled name starting with "_ZTI".
+ A string, the mangled name starting with '_ZTI'.
"""
- if "unique_id" in record_type:
- return record_type["unique_id"].replace("_ZTS", "_ZTI", 1)
- return record_type["linker_set_key"]
+ if 'unique_id' in record_type:
+ return record_type['unique_id'].replace('_ZTS', '_ZTI', 1)
+ return record_type['linker_set_key']
def _OpenFileOrGzipped(file_name):
"""Opens a file that is either in gzip or uncompressed format.
- If file_name ends with '.gz' then return gzip.open(file_name, 'rb'),
- else return open(file_name, 'rb').
+ If file_name ends with '.gz' then an opened gzip text file, else return an
+ opened text file.
Args:
file_name: The file name to open.
@@ -77,8 +78,8 @@ def _OpenFileOrGzipped(file_name):
IOError if fails to open.
"""
if file_name.endswith('.gz'):
- return gzip.open(file_name, 'rb')
- return open(file_name, 'rb')
+ return gzip.open(file_name, 'rt')
+ return open(file_name, 'r')
def _ConsumeOffset(tok, beg=0):
@@ -235,8 +236,8 @@ def _ParseLsdumpFileObject(lsdump_file):
def _ParseLsdumpZipFile(lsdump_zip, output_zip):
"""Converts zipped lsdump files to the dump files for ABI test."""
for name in lsdump_zip.namelist():
- if name.endswith(".lsdump"):
- with lsdump_zip.open(name, mode="r") as lsdump_file:
+ if name.endswith('.lsdump'):
+ with lsdump_zip.open(name, mode='r') as lsdump_file:
output_dump = _ParseLsdumpFileObject(lsdump_file)
output_str = json.dumps(output_dump, indent=1,
separators=(',', ':'))
@@ -262,7 +263,7 @@ def ParseLsdumpFile(input_path, output_path):
with _OpenFileOrGzipped(input_path) as lsdump_file:
output_dump = _ParseLsdumpFileObject(lsdump_file)
- with open(output_path, 'wb') as output_file:
+ with open(output_path, 'w') as output_file:
json.dump(output_dump, output_file,
indent=1, separators=(',', ':'))
except (IOError, OSError) as e:
@@ -288,13 +289,13 @@ def main():
with zipfile.ZipFile(args.output_path, mode='w',
compression=zipfile.ZIP_STORED) as output_zip:
_ParseLsdumpZipFile(input_zip, output_zip)
- exit(0)
+ sys.exit(0)
try:
ParseLsdumpFile(args.input_path, args.output_path)
except LsdumpError as e:
print(e)
- exit(1)
+ sys.exit(1)
if __name__ == '__main__':
diff --git a/utils.py b/utils.py
index 65b2eee..b5cc47d 100644
--- a/utils.py
+++ b/utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# Copyright (C) 2020 The Android Open Source Project
#