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 EXPORTED_HEADER_DIRS
16from test import make_and_copy_reference_dumps
17
18FILE_EXTENSIONS = ['h', 'hpp', 'hxx', 'cpp', 'cc', 'c']
19
20
21def main():
22    patt = re.compile(
23        '^.*\\.(?:' +
24        '|'.join('(?:' + re.escape(ext) + ')' for ext in FILE_EXTENSIONS) +
25        ')$')
26    input_dir_prefix_len = len(INPUT_DIR) + 1
27    for base, dirnames, filenames in os.walk(INPUT_DIR):
28        for filename in filenames:
29            if not patt.match(filename):
30                print('ignore:', filename)
31                continue
32
33            input_path = os.path.join(base, filename)
34            input_rel_path = input_path[input_dir_prefix_len:]
35            output_path = os.path.join(EXPECTED_DIR, input_rel_path)
36
37            print('generating', output_path, '...')
38            os.makedirs(os.path.dirname(output_path), exist_ok=True)
39            run_header_abi_dumper(input_path, output_path,
40                                  export_include_dirs=EXPORTED_HEADER_DIRS)
41
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