1#!/usr/bin/env python3 2 3import os 4import re 5import sys 6 7from utils import run_header_checker 8 9SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) 10INPUT_DIR = os.path.join(SCRIPT_DIR, 'input') 11EXPECTED_DIR = os.path.join(SCRIPT_DIR, 'expected') 12 13DEFAULT_CFLAGS = ['-x', 'c++', '-std=c++11'] 14 15FILE_EXTENSIONS = ['h', 'hpp', 'hxx', 'cpp', 'cc', 'c'] 16 17def main(): 18 patt = re.compile( 19 '^.*\\.(?:' + \ 20 '|'.join('(?:' + re.escape(ext) + ')' for ext in FILE_EXTENSIONS) + \ 21 ')$') 22 23 input_dir_prefix_len = len(INPUT_DIR) + 1 24 for base, dirnames, filenames in os.walk(INPUT_DIR): 25 for filename in filenames: 26 if not patt.match(filename): 27 print('ignore:', filename) 28 continue 29 30 input_path = os.path.join(base, filename) 31 input_rel_path = input_path[input_dir_prefix_len:] 32 output_path = os.path.join(EXPECTED_DIR, input_rel_path) 33 34 print('generating', output_path, '...') 35 output_content = run_header_checker(input_path, DEFAULT_CFLAGS) 36 37 os.makedirs(os.path.dirname(output_path), exist_ok=True) 38 with open(output_path, 'w') as f: 39 f.write(output_content) 40 return 0 41 42if __name__ == '__main__': 43 sys.exit(main()) 44