From beda56ad5cc275e5df895844439545fcd7232b5b Mon Sep 17 00:00:00 2001 From: Hsin-Yi Chen Date: Mon, 28 Aug 2023 15:52:29 +0800 Subject: [PATCH] Rename Target to Arch in header-checker utils.py "target" refers to a target arch, a build target, or a make target. This commit renames the class and the variables to avoid ambiguity. Test: development/vndk/tools/header-checker/utils/create_reference_dumps.py \ -products aosp_x86_64 -release trunk_staging Bug: 297542516 Change-Id: Icfb06e18333d56af802c74494c1d158f367026c9 --- .../utils/create_reference_dumps.py | 44 +++++++++---------- vndk/tools/header-checker/utils/utils.py | 41 ++++++++--------- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/vndk/tools/header-checker/utils/create_reference_dumps.py b/vndk/tools/header-checker/utils/create_reference_dumps.py index aa4c9b22b..2a6e5f56f 100755 --- a/vndk/tools/header-checker/utils/create_reference_dumps.py +++ b/vndk/tools/header-checker/utils/create_reference_dumps.py @@ -5,7 +5,7 @@ import os import time 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, make_libraries, make_tree, read_lsdump_paths) @@ -23,8 +23,8 @@ class GetRefDumpDirStem: def __init__(self, ref_dump_dir): self.ref_dump_dir = ref_dump_dir - def __call__(self, subdir, arch): - return os.path.join(self.ref_dump_dir, arch) + def __call__(self, subdir, arch_str): + return os.path.join(self.ref_dump_dir, arch_str) class GetVersionedRefDumpDirStem: @@ -34,7 +34,7 @@ class GetVersionedRefDumpDirStem: self.chosen_platform_version = chosen_platform_version self.binder_bitness = binder_bitness - def __call__(self, subdir, arch): + def __call__(self, subdir, arch_str): if subdir not in PREBUILTS_ABI_DUMPS_SUBDIRS: raise ValueError(f'"{subdir}" is not a valid dump directory under ' f'{PREBUILTS_ABI_DUMPS_DIR}.') @@ -42,14 +42,14 @@ class GetVersionedRefDumpDirStem: if subdir == 'vndk' else self.chosen_platform_version) 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): print('making libs for', '-'.join(filter(None, build_target))) if libs: - make_libraries(build_target, vndk_version, targets, libs, exclude_tags) + make_libraries(build_target, vndk_version, arches, libs, exclude_tags) else: make_tree(build_target) @@ -66,13 +66,13 @@ def tag_to_dir_name(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): - arch_lsdump_paths = find_lib_lsdumps(lsdump_paths, libs, target) + arch_lsdump_paths = find_lib_lsdumps(lsdump_paths, libs, arch) num_created = 0 for tag, path in arch_lsdump_paths: 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( path, os.path.join(ref_dump_dir_stem, 'source-based')) 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, - lsdump_paths, targets): + lsdump_paths, arches): num_libs_copied = 0 - for target in targets: - assert target.primary_arch != '' - print(f'Creating dumps for arch: {target.arch}, ' - f'primary arch: {target.primary_arch}') + for arch in arches: + assert arch.primary_arch != '' + print(f'Creating dumps for arch: {arch.arch}, ' + f'primary arch: {arch.primary_arch}') 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 @@ -125,9 +125,9 @@ def create_source_abi_reference_dumps_for_all_products(args): if platform_version_codename == 'REL' else 'current') - targets = [t for t in - (Target(True, build_target), Target(False, build_target)) - if t.arch] + arches = [arch for arch in + (Arch(True, build_target), Arch(False, build_target)) + if arch.arch] if 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 # `findlsdumps` if no libs are specified. make_libs_for_product(args.libs, build_target, - platform_vndk_version, targets, + platform_vndk_version, arches, exclude_tags) lsdump_paths = read_lsdump_paths(build_target, - platform_vndk_version, targets, + platform_vndk_version, arches, exclude_tags, build=False) 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: if args.libs or not args.ref_dump_dir: raise RuntimeError('Please check the lib name or specify ' diff --git a/vndk/tools/header-checker/utils/utils.py b/vndk/tools/header-checker/utils/utils.py index adf5891f7..890f36d54 100644 --- a/vndk/tools/header-checker/utils/utils.py +++ b/vndk/tools/header-checker/utils/utils.py @@ -40,7 +40,8 @@ BuildTarget = collections.namedtuple( 'BuildTarget', ['product', 'release', 'variant']) -class Target(object): +class Arch(object): + """A CPU architecture of a build target.""" def __init__(self, is_2nd, build_target): extra = '_2ND' if is_2nd else '' 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) -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()): """Link inputs, taking version_script into account""" cmd = ['header-abi-linker', '-o', output_path, '-v', version_script, - '-api', api, '-arch', arch] + '-api', api, '-arch', arch_str] cmd += flags if '-input-format' not in flags: 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) -def make_targets(build_target, targets): +def make_targets(build_target, args): make_cmd = ['build/soong/soong_ui.bash', '--make-mode', '-j', 'TARGET_PRODUCT=' + build_target.product, 'TARGET_BUILD_VARIANT=' + build_target.variant] if 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) @@ -169,9 +170,9 @@ def make_tree(build_target): 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.""" - lsdump_paths = read_lsdump_paths(build_target, vndk_version, targets, + lsdump_paths = read_lsdump_paths(build_target, vndk_version, arches, exclude_tags, build=True) make_target_paths = [] 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.') -def _read_lsdump_paths(lsdump_paths_file_path, vndk_version, targets, +def _read_lsdump_paths(lsdump_paths_file_path, vndk_version, arches, exclude_tags): """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) dirname = os.path.basename(dir_path) dirnames.append(dirname) - for target in targets: - arch_cpu = target.get_arch_cpu_str() + for arch in arches: + arch_cpu = arch.get_arch_cpu_str() prefix = _get_module_variant_dir_name(tag, vndk_version, arch_cpu) 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 -def read_lsdump_paths(build_target, vndk_version, targets, exclude_tags, +def read_lsdump_paths(build_target, vndk_version, arches, exclude_tags, build): """Build lsdump_paths.txt and read the paths.""" 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) make_targets(build_target, [lsdump_paths_file_path]) return _read_lsdump_paths(lsdump_paths_file_abspath, vndk_version, - targets, exclude_tags) + arches, exclude_tags) -def find_lib_lsdumps(lsdump_paths, libs, target): - """Find the lsdump corresponding to libs for the given target. +def find_lib_lsdumps(lsdump_paths, libs, arch): + """Find the lsdump corresponding to libs for the given architecture. This function returns a list of (tag, absolute_path). 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 = [] if 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] -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): 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] abi_diff_cmd += 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 -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()): with tempfile.TemporaryDirectory() as tmp: output_name = os.path.join(tmp, lib_name) + '.abidiff' - result = run_abi_diff(old_dump_path, new_dump_path, output_name, arch, - lib_name, flags) + result = run_abi_diff(old_dump_path, new_dump_path, output_name, + arch_str, lib_name, flags) with open(output_name, 'r') as output_file: return result, output_file.read()