Merge "Rename Target to Arch in header-checker utils.py" into main

This commit is contained in:
Hsin-Yi Chen
2023-08-29 10:06:40 +00:00
committed by Gerrit Code Review
2 changed files with 43 additions and 42 deletions

View File

@@ -5,7 +5,7 @@ import os
import time import time
from utils import ( from utils import (
AOSP_DIR, SOURCE_ABI_DUMP_EXT_END, SO_EXT, BuildTarget, Target, AOSP_DIR, SOURCE_ABI_DUMP_EXT_END, SO_EXT, BuildTarget, Arch,
copy_reference_dump, find_lib_lsdumps, get_build_vars, copy_reference_dump, find_lib_lsdumps, get_build_vars,
make_libraries, make_tree, read_lsdump_paths) make_libraries, make_tree, read_lsdump_paths)
@@ -23,8 +23,8 @@ class GetRefDumpDirStem:
def __init__(self, ref_dump_dir): def __init__(self, ref_dump_dir):
self.ref_dump_dir = ref_dump_dir self.ref_dump_dir = ref_dump_dir
def __call__(self, subdir, arch): def __call__(self, subdir, arch_str):
return os.path.join(self.ref_dump_dir, arch) return os.path.join(self.ref_dump_dir, arch_str)
class GetVersionedRefDumpDirStem: class GetVersionedRefDumpDirStem:
@@ -34,7 +34,7 @@ class GetVersionedRefDumpDirStem:
self.chosen_platform_version = chosen_platform_version self.chosen_platform_version = chosen_platform_version
self.binder_bitness = binder_bitness self.binder_bitness = binder_bitness
def __call__(self, subdir, arch): def __call__(self, subdir, arch_str):
if subdir not in PREBUILTS_ABI_DUMPS_SUBDIRS: if subdir not in PREBUILTS_ABI_DUMPS_SUBDIRS:
raise ValueError(f'"{subdir}" is not a valid dump directory under ' raise ValueError(f'"{subdir}" is not a valid dump directory under '
f'{PREBUILTS_ABI_DUMPS_DIR}.') f'{PREBUILTS_ABI_DUMPS_DIR}.')
@@ -42,14 +42,14 @@ class GetVersionedRefDumpDirStem:
if subdir == 'vndk' if subdir == 'vndk'
else self.chosen_platform_version) else self.chosen_platform_version)
return os.path.join(PREBUILTS_ABI_DUMPS_DIR, subdir, version_stem, return os.path.join(PREBUILTS_ABI_DUMPS_DIR, subdir, version_stem,
self.binder_bitness, arch) self.binder_bitness, arch_str)
def make_libs_for_product(libs, build_target, vndk_version, targets, def make_libs_for_product(libs, build_target, vndk_version, arches,
exclude_tags): exclude_tags):
print('making libs for', '-'.join(filter(None, build_target))) print('making libs for', '-'.join(filter(None, build_target)))
if libs: if libs:
make_libraries(build_target, vndk_version, targets, libs, exclude_tags) make_libraries(build_target, vndk_version, arches, libs, exclude_tags)
else: else:
make_tree(build_target) make_tree(build_target)
@@ -66,13 +66,13 @@ def tag_to_dir_name(tag):
raise ValueError(tag + ' is not a known tag.') raise ValueError(tag + ' is not a known tag.')
def find_and_copy_lib_lsdumps(get_ref_dump_dir_stem, target, libs, def find_and_copy_lib_lsdumps(get_ref_dump_dir_stem, arch, libs,
lsdump_paths): lsdump_paths):
arch_lsdump_paths = find_lib_lsdumps(lsdump_paths, libs, target) arch_lsdump_paths = find_lib_lsdumps(lsdump_paths, libs, arch)
num_created = 0 num_created = 0
for tag, path in arch_lsdump_paths: for tag, path in arch_lsdump_paths:
ref_dump_dir_stem = get_ref_dump_dir_stem(tag_to_dir_name(tag), ref_dump_dir_stem = get_ref_dump_dir_stem(tag_to_dir_name(tag),
target.get_arch_str()) arch.get_arch_str())
copy_reference_dump( copy_reference_dump(
path, os.path.join(ref_dump_dir_stem, 'source-based')) path, os.path.join(ref_dump_dir_stem, 'source-based'))
num_created += 1 num_created += 1
@@ -80,15 +80,15 @@ def find_and_copy_lib_lsdumps(get_ref_dump_dir_stem, target, libs,
def create_source_abi_reference_dumps(args, get_ref_dump_dir_stem, def create_source_abi_reference_dumps(args, get_ref_dump_dir_stem,
lsdump_paths, targets): lsdump_paths, arches):
num_libs_copied = 0 num_libs_copied = 0
for target in targets: for arch in arches:
assert target.primary_arch != '' assert arch.primary_arch != ''
print(f'Creating dumps for arch: {target.arch}, ' print(f'Creating dumps for arch: {arch.arch}, '
f'primary arch: {target.primary_arch}') f'primary arch: {arch.primary_arch}')
num_libs_copied += find_and_copy_lib_lsdumps( num_libs_copied += find_and_copy_lib_lsdumps(
get_ref_dump_dir_stem, target, args.libs, lsdump_paths) get_ref_dump_dir_stem, arch, args.libs, lsdump_paths)
return num_libs_copied return num_libs_copied
@@ -125,9 +125,9 @@ def create_source_abi_reference_dumps_for_all_products(args):
if platform_version_codename == 'REL' if platform_version_codename == 'REL'
else 'current') else 'current')
targets = [t for t in arches = [arch for arch in
(Target(True, build_target), Target(False, build_target)) (Arch(True, build_target), Arch(False, build_target))
if t.arch] if arch.arch]
if args.ref_dump_dir: if args.ref_dump_dir:
get_ref_dump_dir_stem = GetRefDumpDirStem(args.ref_dump_dir) get_ref_dump_dir_stem = GetRefDumpDirStem(args.ref_dump_dir)
@@ -144,15 +144,15 @@ def create_source_abi_reference_dumps_for_all_products(args):
# Build .lsdump for all the specified libs, or build # Build .lsdump for all the specified libs, or build
# `findlsdumps` if no libs are specified. # `findlsdumps` if no libs are specified.
make_libs_for_product(args.libs, build_target, make_libs_for_product(args.libs, build_target,
platform_vndk_version, targets, platform_vndk_version, arches,
exclude_tags) exclude_tags)
lsdump_paths = read_lsdump_paths(build_target, lsdump_paths = read_lsdump_paths(build_target,
platform_vndk_version, targets, platform_vndk_version, arches,
exclude_tags, build=False) exclude_tags, build=False)
num_processed += create_source_abi_reference_dumps( num_processed += create_source_abi_reference_dumps(
args, get_ref_dump_dir_stem, lsdump_paths, targets) args, get_ref_dump_dir_stem, lsdump_paths, arches)
except KeyError as e: except KeyError as e:
if args.libs or not args.ref_dump_dir: if args.libs or not args.ref_dump_dir:
raise RuntimeError('Please check the lib name or specify ' raise RuntimeError('Please check the lib name or specify '

View File

@@ -40,7 +40,8 @@ BuildTarget = collections.namedtuple(
'BuildTarget', ['product', 'release', 'variant']) 'BuildTarget', ['product', 'release', 'variant'])
class Target(object): class Arch(object):
"""A CPU architecture of a build target."""
def __init__(self, is_2nd, build_target): def __init__(self, is_2nd, build_target):
extra = '_2ND' if is_2nd else '' extra = '_2ND' if is_2nd else ''
build_vars_to_fetch = ['TARGET_ARCH', build_vars_to_fetch = ['TARGET_ARCH',
@@ -139,11 +140,11 @@ def run_header_abi_dumper(input_path, output_path, cflags=tuple(),
_validate_dump_content(output_path) _validate_dump_content(output_path)
def run_header_abi_linker(inputs, output_path, version_script, api, arch, def run_header_abi_linker(inputs, output_path, version_script, api, arch_str,
flags=tuple()): flags=tuple()):
"""Link inputs, taking version_script into account""" """Link inputs, taking version_script into account"""
cmd = ['header-abi-linker', '-o', output_path, '-v', version_script, cmd = ['header-abi-linker', '-o', output_path, '-v', version_script,
'-api', api, '-arch', arch] '-api', api, '-arch', arch_str]
cmd += flags cmd += flags
if '-input-format' not in flags: if '-input-format' not in flags:
cmd += ['-input-format', DEFAULT_FORMAT] cmd += ['-input-format', DEFAULT_FORMAT]
@@ -154,13 +155,13 @@ def run_header_abi_linker(inputs, output_path, version_script, api, arch,
_validate_dump_content(output_path) _validate_dump_content(output_path)
def make_targets(build_target, targets): def make_targets(build_target, args):
make_cmd = ['build/soong/soong_ui.bash', '--make-mode', '-j', make_cmd = ['build/soong/soong_ui.bash', '--make-mode', '-j',
'TARGET_PRODUCT=' + build_target.product, 'TARGET_PRODUCT=' + build_target.product,
'TARGET_BUILD_VARIANT=' + build_target.variant] 'TARGET_BUILD_VARIANT=' + build_target.variant]
if build_target.release: if build_target.release:
make_cmd.append('TARGET_RELEASE=' + build_target.release) make_cmd.append('TARGET_RELEASE=' + build_target.release)
make_cmd += targets make_cmd += args
subprocess.check_call(make_cmd, cwd=AOSP_DIR) subprocess.check_call(make_cmd, cwd=AOSP_DIR)
@@ -169,9 +170,9 @@ def make_tree(build_target):
return make_targets(build_target, ['findlsdumps']) return make_targets(build_target, ['findlsdumps'])
def make_libraries(build_target, vndk_version, targets, libs, exclude_tags): def make_libraries(build_target, vndk_version, arches, libs, exclude_tags):
"""Build lsdump files for specific libs.""" """Build lsdump files for specific libs."""
lsdump_paths = read_lsdump_paths(build_target, vndk_version, targets, lsdump_paths = read_lsdump_paths(build_target, vndk_version, arches,
exclude_tags, build=True) exclude_tags, build=True)
make_target_paths = [] make_target_paths = []
for name in libs: for name in libs:
@@ -210,7 +211,7 @@ def _get_module_variant_dir_name(tag, vndk_version, arch_cpu_str):
raise ValueError(tag + ' is not a known tag.') raise ValueError(tag + ' is not a known tag.')
def _read_lsdump_paths(lsdump_paths_file_path, vndk_version, targets, def _read_lsdump_paths(lsdump_paths_file_path, vndk_version, arches,
exclude_tags): exclude_tags):
"""Read lsdump paths from lsdump_paths.txt for each libname and variant. """Read lsdump paths from lsdump_paths.txt for each libname and variant.
@@ -248,8 +249,8 @@ def _read_lsdump_paths(lsdump_paths_file_path, vndk_version, targets,
dirnames.append(dirname) dirnames.append(dirname)
dirname = os.path.basename(dir_path) dirname = os.path.basename(dir_path)
dirnames.append(dirname) dirnames.append(dirname)
for target in targets: for arch in arches:
arch_cpu = target.get_arch_cpu_str() arch_cpu = arch.get_arch_cpu_str()
prefix = _get_module_variant_dir_name(tag, vndk_version, prefix = _get_module_variant_dir_name(tag, vndk_version,
arch_cpu) arch_cpu)
variant = next((d for d in dirnames if d.startswith(prefix)), variant = next((d for d in dirnames if d.startswith(prefix)),
@@ -266,7 +267,7 @@ def _read_lsdump_paths(lsdump_paths_file_path, vndk_version, targets,
return lsdump_paths return lsdump_paths
def read_lsdump_paths(build_target, vndk_version, targets, exclude_tags, def read_lsdump_paths(build_target, vndk_version, arches, exclude_tags,
build): build):
"""Build lsdump_paths.txt and read the paths.""" """Build lsdump_paths.txt and read the paths."""
lsdump_paths_file_path = get_lsdump_paths_file_path(build_target) lsdump_paths_file_path = get_lsdump_paths_file_path(build_target)
@@ -276,11 +277,11 @@ def read_lsdump_paths(build_target, vndk_version, targets, exclude_tags,
os.unlink(lsdump_paths_file_abspath) os.unlink(lsdump_paths_file_abspath)
make_targets(build_target, [lsdump_paths_file_path]) make_targets(build_target, [lsdump_paths_file_path])
return _read_lsdump_paths(lsdump_paths_file_abspath, vndk_version, return _read_lsdump_paths(lsdump_paths_file_abspath, vndk_version,
targets, exclude_tags) arches, exclude_tags)
def find_lib_lsdumps(lsdump_paths, libs, target): def find_lib_lsdumps(lsdump_paths, libs, arch):
"""Find the lsdump corresponding to libs for the given target. """Find the lsdump corresponding to libs for the given architecture.
This function returns a list of (tag, absolute_path). This function returns a list of (tag, absolute_path).
For example, For example,
@@ -291,7 +292,7 @@ def find_lib_lsdumps(lsdump_paths, libs, target):
) )
] ]
""" """
arch_cpu = target.get_arch_cpu_str() arch_cpu = arch.get_arch_cpu_str()
result = [] result = []
if libs: if libs:
for lib_name in libs: for lib_name in libs:
@@ -306,10 +307,10 @@ def find_lib_lsdumps(lsdump_paths, libs, target):
return [(tag, os.path.join(AOSP_DIR, path)) for tag, path in result] return [(tag, os.path.join(AOSP_DIR, path)) for tag, path in result]
def run_abi_diff(old_dump_path, new_dump_path, output_path, arch, lib_name, def run_abi_diff(old_dump_path, new_dump_path, output_path, arch_str, lib_name,
flags): flags):
abi_diff_cmd = ['header-abi-diff', '-new', new_dump_path, '-old', abi_diff_cmd = ['header-abi-diff', '-new', new_dump_path, '-old',
old_dump_path, '-arch', arch, '-lib', lib_name, old_dump_path, '-arch', arch_str, '-lib', lib_name,
'-o', output_path] '-o', output_path]
abi_diff_cmd += flags abi_diff_cmd += flags
if '-input-format-old' not in flags: if '-input-format-old' not in flags:
@@ -319,12 +320,12 @@ def run_abi_diff(old_dump_path, new_dump_path, output_path, arch, lib_name,
return subprocess.run(abi_diff_cmd).returncode return subprocess.run(abi_diff_cmd).returncode
def run_and_read_abi_diff(old_dump_path, new_dump_path, arch, lib_name, def run_and_read_abi_diff(old_dump_path, new_dump_path, arch_str, lib_name,
flags=tuple()): flags=tuple()):
with tempfile.TemporaryDirectory() as tmp: with tempfile.TemporaryDirectory() as tmp:
output_name = os.path.join(tmp, lib_name) + '.abidiff' output_name = os.path.join(tmp, lib_name) + '.abidiff'
result = run_abi_diff(old_dump_path, new_dump_path, output_name, arch, result = run_abi_diff(old_dump_path, new_dump_path, output_name,
lib_name, flags) arch_str, lib_name, flags)
with open(output_name, 'r') as output_file: with open(output_name, 'r') as output_file:
return result, output_file.read() return result, output_file.read()