1#!/usr/bin/env python3 2 3import tempfile 4import os 5import subprocess 6 7SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) 8AOSP_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, *['..'] * 5)) 9 10BUILTIN_HEADERS_DIR = ( 11 os.path.join(AOSP_DIR, 'bionic', 'libc', 'include'), 12 os.path.join(AOSP_DIR, 'external', 'libcxx', 'include'), 13 os.path.join(AOSP_DIR, 'prebuilts', 'sdk', 'renderscript', 'clang-include'), 14) 15 16EXPORTED_HEADERS_DIR = ( 17 os.path.join(AOSP_DIR, 'development', 'vndk', 'tools', 'header-checker', 18 'tests'), 19) 20 21def run_header_checker(input_path, cflags=[]): 22 with tempfile.TemporaryDirectory() as tmp: 23 output_name = os.path.join(tmp, os.path.basename(input_path)) + '.dump' 24 cmd = ['header-abi-dumper', '-o', output_name, input_path,] 25 for d in EXPORTED_HEADERS_DIR: 26 cmd += ['-I', d] 27 cmd+= ['--'] 28 for d in BUILTIN_HEADERS_DIR: 29 cmd += ['-isystem', d] 30 cmd += cflags 31 subprocess.check_call(cmd) 32 with open(output_name, 'r') as f: 33 return f.read().replace(SCRIPT_DIR, '.') 34