• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright (c) 2023 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import optparse
17import os
18import sys
19import subprocess
20
21sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
22from scripts.util import build_utils  # noqa: E402
23
24def parse_args(args):
25    args = build_utils.expand_file_args(args)
26
27    parser = optparse.OptionParser()
28    build_utils.add_depfile_option(parser)
29    parser.add_option('--output', help='generated ndk stub file')
30    parser.add_option('--headers',
31                      action='append',
32                      help='base directory of ndk common files')
33
34    options, _ = parser.parse_args(args)
35
36    return options
37
38def check_ndk_header(headers: list, output: str):
39    cmd_list=[]
40    cmd_list.append('clang')
41    cmd_list.append('-I sdk-native/os-irrelevant/sysroot/')
42    cmd_list.append('-std=c99')
43    for file in headers:
44        command = cmd_list + [file]
45        result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
46        if result.returncode != 0:
47            with open(r'Error.txt', 'a', encoding='utf-8') as fs:
48                fs.write(f'Error: {result.stderr.decode()}')
49
50    build_utils.touch(output)
51
52
53def main(args):
54    options = parse_args(args)
55    build_utils.call_and_write_depfile_if_stale(lambda: check_ndk_header(options.headers, options.output),
56                                                options,
57                                                output_paths=([options.output]),
58                                                input_strings=args,
59                                                force=False,
60                                                add_pydeps=False)
61
62if __name__ == '__main__':
63    sys.exit(main(sys.argv[1:]))
64