1#!/usr/bin/env python3 2 3import os 4import re 5import sys 6 7import_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) 8import_path = os.path.abspath(os.path.join(import_path, 'utils')) 9sys.path.insert(1, import_path) 10 11from utils import run_header_abi_dumper 12from utils import copy_reference_dump_content 13from module import Module 14 15SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) 16INPUT_DIR = os.path.join(SCRIPT_DIR, 'input') 17EXPECTED_DIR = os.path.join(SCRIPT_DIR, 'expected') 18REFERENCE_DUMP_DIR = os.path.join(SCRIPT_DIR, 'reference_dumps') 19FILE_EXTENSIONS = ['h', 'hpp', 'hxx', 'cpp', 'cc', 'c'] 20 21def make_and_copy_reference_dumps(module, default_cflags=[], 22 reference_dump_dir=REFERENCE_DUMP_DIR): 23 lsdump_content = module.make_lsdump(default_cflags) 24 return copy_reference_dump_content(module.get_name(), lsdump_content, 25 reference_dump_dir, '', 26 module.get_arch()) 27 28def main(): 29 patt = re.compile( 30 '^.*\\.(?:' + \ 31 '|'.join('(?:' + re.escape(ext) + ')' for ext in FILE_EXTENSIONS) + \ 32 ')$') 33 input_dir_prefix_len = len(INPUT_DIR) + 1 34 for base, dirnames, filenames in os.walk(INPUT_DIR): 35 for filename in filenames: 36 if not patt.match(filename): 37 print('ignore:', filename) 38 continue 39 40 input_path = os.path.join(base, filename) 41 input_rel_path = input_path[input_dir_prefix_len:] 42 output_path = os.path.join(EXPECTED_DIR, input_rel_path) 43 44 print('generating', output_path, '...') 45 output_content = run_header_abi_dumper(input_path, True) 46 47 os.makedirs(os.path.dirname(output_path), exist_ok=True) 48 with open(output_path, 'w') as f: 49 f.write(output_content) 50 modules = Module.get_test_modules() 51 for module in modules: 52 make_and_copy_reference_dumps(module) 53 54 return 0 55 56if __name__ == '__main__': 57 sys.exit(main()) 58