import optparse
import os
import sys
import subprocess
import stat
sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
from scripts.util import build_utils
def parse_args(args):
args = build_utils.expand_file_args(args)
parser = optparse.OptionParser()
build_utils.add_depfile_option(parser)
parser.add_option('--output', help='generated ndk stub file')
parser.add_option('--headers',
action='append',
help='base directory of ndk common files')
options, _ = parser.parse_args(args)
return options
def check_ndk_header(headers: list, output: str):
cmd_list = []
cmd_list.append('clang')
cmd_list.append('-I sdk-native/os-irrelevant/sysroot/')
cmd_list.append('-std=c99')
for file in headers:
command = cmd_list + [file]
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode != 0:
with os.fdopen(os.open(r'Error.txt',
os.O_WRONLY | os.O_CREAT | os.O_APPEND,
mode=stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH ),
'a', encoding='utf-8') as fs:
fs.write(f'Error: {result.stderr.decode()}')
build_utils.touch(output)
def main(args):
options = parse_args(args)
build_utils.call_and_write_depfile_if_stale(lambda: check_ndk_header(options.headers, options.output),
options,
output_paths=([options.output]),
input_strings=args,
force=False,
add_pydeps=False)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))