1 #!/usr/bin/env python3 2 3 import os 4 import re 5 import sys 6 7 import_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) 8 import_path = os.path.abspath(os.path.join(import_path, 'utils')) 9 sys.path.insert(1, import_path) 10 11 from utils import run_header_abi_dumper 12 from module import Module 13 from test import INPUT_DIR 14 from test import EXPECTED_DIR 15 from test import make_and_copy_reference_dumps 16 17 FILE_EXTENSIONS = ['h', 'hpp', 'hxx', 'cpp', 'cc', 'c'] 18 19 20 def 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 49 if __name__ == '__main__': 50 sys.exit(main()) 51