diff options
author | Hsin-Yi Chen <hsinyichen@google.com> | 2024-02-08 00:28:51 +0800 |
---|---|---|
committer | Hsin-Yi Chen <hsinyichen@google.com> | 2024-02-19 18:59:55 +0800 |
commit | ac35807a29582a82bc5a0cf8b71f5a79a0bb0c14 (patch) | |
tree | 23194c389f247903c20e36d23178a78ac14148ef | |
parent | 035ccb9f9a0f137763095f72e946ff1afb8920bc (diff) | |
download | development-ac35807a29582a82bc5a0cf8b71f5a79a0bb0c14.tar.gz |
Add create_reference_dumps.py --lib-variant
The new parameter lets the caller finalize LLNDK separately from NDK
and PLATFORM. create_reference_dumps.py filters lsdump_paths.txt by
-libs --lib-variant. It builds and copies only the needed .lsdump.
Test: ./create_reference_dumps.py -libs libnativewindow \
--lib-variant LLNDK -products aosp_arm64 -release next
Bug: 314010764
Change-Id: I95fb382b90d4ebd12e1a587cd1b6bc2cb1035900
-rwxr-xr-x | vndk/tools/header-checker/utils/create_reference_dumps.py | 63 | ||||
-rw-r--r-- | vndk/tools/header-checker/utils/utils.py | 21 |
2 files changed, 57 insertions, 27 deletions
diff --git a/vndk/tools/header-checker/utils/create_reference_dumps.py b/vndk/tools/header-checker/utils/create_reference_dumps.py index a9b510331..6cba65ac8 100755 --- a/vndk/tools/header-checker/utils/create_reference_dumps.py +++ b/vndk/tools/header-checker/utils/create_reference_dumps.py @@ -7,13 +7,14 @@ import time from utils import ( 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) + make_libraries, make_targets, read_lsdump_paths) PRODUCTS_DEFAULT = ['aosp_arm', 'aosp_arm64', 'aosp_x86', 'aosp_x86_64'] PREBUILTS_ABI_DUMPS_DIR = os.path.join(AOSP_DIR, 'prebuilts', 'abi-dumps') PREBUILTS_ABI_DUMPS_SUBDIRS = ('ndk', 'platform', 'vndk') +KNOWN_TAGS = {'LLNDK', 'NDK', 'PLATFORM', 'VENDOR', 'PRODUCT'} NON_AOSP_TAGS = {'VENDOR', 'PRODUCT'} SOONG_DIR = os.path.join(AOSP_DIR, 'out', 'soong', '.intermediates') @@ -44,12 +45,24 @@ class GetVersionedRefDumpDirStem: self.binder_bitness, arch_str) -def make_libs_for_product(libs, build_target, arches, exclude_tags): - print('making libs for', '-'.join(filter(None, build_target))) - if libs: - make_libraries(build_target, arches, libs, exclude_tags) - else: - make_tree(build_target) +class LsdumpFilter: + def __init__(self, include_names, include_tags, exclude_tags): + self.include_names = include_names + self.include_tags = include_tags + self.exclude_tags = exclude_tags + + def __call__(self, tag, lib_name): + """Determine whether to dump the library. + + lib_name does not contain '.so'. + """ + if self.include_names and lib_name not in self.include_names: + return False + if self.include_tags and tag not in self.include_tags: + return False + if tag in self.exclude_tags: + return False + return True def tag_to_dir_name(tag): @@ -121,29 +134,38 @@ def create_source_abi_reference_dumps_for_all_products(args): if args.ref_dump_dir: get_ref_dump_dir_stem = GetRefDumpDirStem(args.ref_dump_dir) - exclude_tags = () + exclude_tags = set() else: get_ref_dump_dir_stem = GetVersionedRefDumpDirStem( release_board_api_level, chosen_platform_version, binder_bitness) exclude_tags = NON_AOSP_TAGS + lsdump_filter = LsdumpFilter(args.libs, args.include_tags, + exclude_tags) + try: if not args.no_make_lib: - # Build .lsdump for all the specified libs, or build - # `findlsdumps` if no libs are specified. - make_libs_for_product(args.libs, build_target, arches, - exclude_tags) + print('making libs for', '-'.join(filter(None, build_target))) + if args.libs: + make_libraries(build_target, arches, args.libs, + lsdump_filter) + elif args.include_tags: + make_targets( + build_target, + ['findlsdumps_' + tag for tag in args.include_tags]) + else: + make_targets(build_target, ['findlsdumps']) lsdump_paths = read_lsdump_paths(build_target, arches, - exclude_tags, build=False) + lsdump_filter, build=False) num_processed += create_source_abi_reference_dumps( 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 ' - '-ref-dump-dir if you are updating ' + raise RuntimeError('Please check the lib name, --lib-variant ' + 'and -ref-dump-dir if you are updating ' 'reference dumps for product or vendor ' 'libraries.') from e raise @@ -167,6 +189,9 @@ def _parse_args(): 'e.g., trunk_staging, next.') parser.add_argument('--build-variant', default='userdebug', help='build variant to create references for') + parser.add_argument('--lib-variant', action='append', dest='include_tags', + default=[], choices=KNOWN_TAGS, + help='library variant to create references for.') parser.add_argument('--compress', action='store_true', help=argparse.SUPPRESS) parser.add_argument('-ref-dump-dir', @@ -188,9 +213,17 @@ def _parse_args(): parser.error('-libs should be followed by a base name without ' 'file extension.') + if NON_AOSP_TAGS.intersection(args.include_tags) and not args.libs: + parser.error('-libs must be given if --lib-variant is any of ' + + str(NON_AOSP_TAGS)) + if args.ref_dump_dir and not args.libs: parser.error('-libs must be given if -ref-dump-dir is given.') + if args.ref_dump_dir and len(args.include_tags) != 1: + print('WARNING: Exactly one --lib-variant should be specified if ' + '-ref-dump-dir is given.') + if args.products is None: # If `args.products` is unspecified, generate reference ABI dumps for # all products. diff --git a/vndk/tools/header-checker/utils/utils.py b/vndk/tools/header-checker/utils/utils.py index 03e82554c..8d8a9b635 100644 --- a/vndk/tools/header-checker/utils/utils.py +++ b/vndk/tools/header-checker/utils/utils.py @@ -165,14 +165,9 @@ def make_targets(build_target, args): subprocess.check_call(make_cmd, cwd=AOSP_DIR) -def make_tree(build_target): - """Build all lsdump files.""" - return make_targets(build_target, ['findlsdumps']) - - -def make_libraries(build_target, arches, libs, exclude_tags): +def make_libraries(build_target, arches, libs, lsdump_filter): """Build lsdump files for specific libs.""" - lsdump_paths = read_lsdump_paths(build_target, arches, exclude_tags, + lsdump_paths = read_lsdump_paths(build_target, arches, lsdump_filter, build=True) make_target_paths = [] for name in libs: @@ -211,7 +206,7 @@ def _get_module_variant_dir_name(tag, arch_cpu_str): raise ValueError(tag + ' is not a known tag.') -def _read_lsdump_paths(lsdump_paths_file_path, arches, exclude_tags): +def _read_lsdump_paths(lsdump_paths_file_path, arches, lsdump_filter): """Read lsdump paths from lsdump_paths.txt for each libname and variant. This function returns a dictionary, {lib_name: {arch_cpu: {tag: path}}}. @@ -231,15 +226,17 @@ def _read_lsdump_paths(lsdump_paths_file_path, arches, exclude_tags): with open(lsdump_paths_file_path, 'r') as lsdump_paths_file: for line in lsdump_paths_file: - tag, path = (x.strip() for x in line.split(':', 1)) - if not path or tag in exclude_tags: + if not line.strip(): continue + tag, path = (x.strip() for x in line.split(':', 1)) dir_path, filename = os.path.split(path) if not filename.endswith(SOURCE_ABI_DUMP_EXT): continue libname = filename[:-len(SOURCE_ABI_DUMP_EXT)] if not libname: continue + if not lsdump_filter(tag, libname): + continue # dir_path may contain soong config hash. # For example, the following dir_paths are valid. # android_x86_x86_64_shared/012abc/libc.so.lsdump @@ -266,7 +263,7 @@ def _read_lsdump_paths(lsdump_paths_file_path, arches, exclude_tags): return lsdump_paths -def read_lsdump_paths(build_target, arches, exclude_tags, build): +def read_lsdump_paths(build_target, arches, lsdump_filter, build): """Build lsdump_paths.txt and read the paths.""" lsdump_paths_file_path = get_lsdump_paths_file_path(build_target) lsdump_paths_file_abspath = os.path.join(AOSP_DIR, lsdump_paths_file_path) @@ -274,7 +271,7 @@ def read_lsdump_paths(build_target, arches, exclude_tags, build): if os.path.lexists(lsdump_paths_file_abspath): os.unlink(lsdump_paths_file_abspath) make_targets(build_target, [lsdump_paths_file_path]) - return _read_lsdump_paths(lsdump_paths_file_abspath, arches, exclude_tags) + return _read_lsdump_paths(lsdump_paths_file_abspath, arches, lsdump_filter) def find_lib_lsdumps(lsdump_paths, libs, arch): |