• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
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
16import sys
17import argparse
18import os
19
20sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
21from scripts.util.file_utils import read_json_file, write_json_file  # noqa: E402 E501
22
23
24# read subsystem module, generate subsystem install list and deps list.
25def gen_output_file(part_name, origin_part_name, all_modules_file,
26                    sdk_modules_info_file, install_modules_file,
27                    dep_modules_file, output_host_file,
28                    current_toolchain, host_toolchain):
29    # read subsystem module info
30    all_module_info = read_json_file(all_modules_file)
31    if all_module_info is None:
32        raise Exception(
33            "read part '{}' modules info failed.".format(part_name))
34
35    # merge sdk install modules, may be repeat
36    if os.path.exists(sdk_modules_info_file):
37        sdk_modules_info = read_json_file(sdk_modules_info_file)
38        if sdk_modules_info is not None:
39            all_module_info.extend(sdk_modules_info)
40
41    # thirdparty subsystem part module list
42    thirdparty_module_list = []
43
44    # driver/interface part moudle list
45    hdi_module_list = []
46
47    # driver/interface and thirdparty subsystem part module list
48    external_module_list = []
49
50    # Generate a list of modules by part
51    modules_info_dict = {}
52    modules_def = {}  # remove duplicates
53    for info in all_module_info:
54        module_def = info.get('module_def')
55        if module_def in modules_def:
56            continue
57
58        modules_def[module_def] = ''
59        thirdparty = info.get('subsystem_name')
60        if thirdparty == 'thirdparty':
61            thirdparty_module_list.append(info)
62            external_module_list.append(info)
63        if str(module_def).startswith("//drivers/interface"):
64            hdi_module_list.append(info)
65            external_module_list.append(info)
66        _module_part_name = info.get('part_name')
67        if _module_part_name not in modules_info_dict:
68            modules_info_dict[_module_part_name] = []
69        modules_info_dict[_module_part_name] += [info]
70
71    # Current part module list
72    part_module_list = []
73    if origin_part_name in modules_info_dict:
74        part_module_list = modules_info_dict.pop(origin_part_name)
75
76    # Current part dependent module list
77    part_install_modules = []
78    part_no_install_modules = []
79    part_host_modules = []
80    for install_module in part_module_list:
81        toolchain = install_module.get('toolchain')
82        if toolchain == '' or toolchain == current_toolchain:
83            part_install_modules.append(install_module)
84        else:
85            if toolchain == host_toolchain:
86                part_host_modules.append(install_module)
87            part_no_install_modules.append(install_module)
88
89    for install_module in external_module_list:
90        toolchain = install_module.get('toolchain')
91        if toolchain == host_toolchain:
92            part_host_modules.append(install_module)
93
94    # Depended thirdparty modules and driver/interface modules
95    # are installed by default
96    # rather than configured in product config.
97    part_install_modules.extend(thirdparty_module_list)
98    part_install_modules.extend(hdi_module_list)
99    # write install modules file
100    write_json_file(install_modules_file, part_install_modules)
101
102    # add no install modules to dict, example: host target
103    modules_info_dict[part_name] = part_no_install_modules
104    # write dep modules file
105    write_json_file(dep_modules_file, modules_info_dict)
106    write_json_file(output_host_file, part_host_modules)
107
108
109def main():
110    parser = argparse.ArgumentParser()
111    parser.add_argument('--part-name', required=True)
112    parser.add_argument('--origin-part-name', required=True)
113    parser.add_argument('--input-file', help='', required=True)
114    parser.add_argument('--sdk-modules-info-file', help='', required=True)
115    parser.add_argument('--output-install-file', help='', required=True)
116    parser.add_argument('--output-deps-file', help='', required=True)
117    parser.add_argument('--output-host-file', help='', required=True)
118    parser.add_argument('--current-toolchain', help='', required=True)
119    parser.add_argument('--host-toolchain', help='', required=True)
120    parser.add_argument('--depfile', required=False)
121    args = parser.parse_args()
122    gen_output_file(args.part_name, args.origin_part_name, args.input_file,
123                    args.sdk_modules_info_file, args.output_install_file,
124                    args.output_deps_file, args.output_host_file,
125                    args.current_toolchain, args.host_toolchain)
126    return 0
127
128
129if __name__ == '__main__':
130    sys.exit(main())
131