• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# Copyright (c) 2021 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
16from io import RawIOBase
17import sys
18import os
19import argparse
20
21sys.path.append(
22    os.path.dirname(os.path.dirname(os.path.dirname(
23        os.path.abspath(__file__)))))
24from scripts.util import build_utils  # noqa: E402
25from scripts.util.file_utils import read_json_file, write_json_file  # noqa: E402, E501
26
27
28def _get_system_capability(targets_build_config: list):
29    _syscap_info = {}
30    _syscap_config = {}
31    for _bc_file in targets_build_config:
32        if not os.path.exists(_bc_file):
33            continue
34        _ndk_config_infos = read_json_file(_bc_file)
35        if _ndk_config_infos is None:
36            raise Exception("read file '{}' failed.".format(_bc_file))
37        _ndk_config_info = _ndk_config_infos[0]
38        _target_label = _ndk_config_info.get('label')
39        _bc_syscap = _ndk_config_info.get('system_capability')
40        if not _bc_syscap or not _target_label:
41            continue
42        _lib_name = _ndk_config_info.get('lib_name')
43        _syscap_info[_lib_name] = _bc_syscap
44        _bc_syscap_headers = _ndk_config_info.get("system_capability_headers")
45        if _bc_syscap_headers:
46            if _bc_syscap not in _syscap_config:
47                _syscap_config[_bc_syscap] = []
48            _syscap_config[_bc_syscap] += _bc_syscap_headers
49    return _syscap_info, _syscap_config
50
51
52def run(args):
53    _syscap_info, _syscap_config = _get_system_capability(args.targets_build_config)
54    write_json_file(args.system_capability_file, _syscap_info)
55    write_json_file(args.system_capability_header_config, _syscap_config)
56
57    if args.depfile:
58        _dep_files = []
59        for _bc_file in args.targets_build_config:
60            if os.path.exists(_bc_file):
61                _dep_files.append(_bc_file)
62        list.sort(_dep_files)
63        build_utils.write_depfile(args.depfile,
64                                  args.system_capability_file,
65                                  _dep_files,
66                                  add_pydeps=False)
67
68
69def main(argv):
70    parser = argparse.ArgumentParser()
71    parser.add_argument('--targets-build-config', nargs='+', required=True)
72    parser.add_argument('--system-capability-file', required=True)
73    parser.add_argument('--system-capability-header-config', required=True)
74    parser.add_argument('--depfile', required=False)
75    args = parser.parse_args(argv)
76    return run(args)
77
78
79if __name__ == '__main__':
80    sys.exit(main(sys.argv[1:]))
81