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 module import Module 13from test import INPUT_DIR 14from test import EXPECTED_DIR 15from test import make_and_copy_reference_dumps 16 17FILE_EXTENSIONS = ['h', 'hpp', 'hxx', 'cpp', 'cc', 'c'] 18 19 20def main(): 21 patt = re.compile( 22 '^.*\\.(?:' + 23 '|'.join('(?:' + re.escape(ext) + ')' for ext in FILE_EXTENSIONS) + 24 ')$') 25 input_dir_prefix_len = len(INPUT_DIR) + 1 26 for base, dirnames, filenames in os.walk(INPUT_DIR): 27 for filename in filenames: 28 if not patt.match(filename): 29 print('ignore:', filename) 30 continue 31 32 input_path = os.path.join(base, filename) 33 input_rel_path = input_path[input_dir_prefix_len:] 34 output_path = os.path.join(EXPECTED_DIR, input_rel_path) 35 36 print('generating', output_path, '...') 37 output_content = run_header_abi_dumper(input_path) 38 39 os.makedirs(os.path.dirname(output_path), exist_ok=True) 40 with open(output_path, 'w') as f: 41 f.write(output_content) 42 modules = Module.get_test_modules() 43 for module in modules: 44 print('Created abi dump at', make_and_copy_reference_dumps(module)) 45 46 return 0 47 48 49if __name__ == '__main__': 50 sys.exit(main()) 51