• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Copyright (c) 2020 Huawei Device Co., Ltd.
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18import argparse
19import json
20import os
21import stat
22
23part_infos = "part_infos"
24subsystem_infos = "subsystem_infos"
25
26
27def create_testfwk_info_file(component_info_file, abs_fold, file_name):
28    if not os.path.exists(abs_fold):
29        os.makedirs(abs_fold, exist_ok=True)
30    file_path = os.path.join(abs_fold, file_name)
31    data = get_testfwk_info(component_info_file)
32    dict_product = json.dumps(data)
33
34    with os.fdopen(os.open(file_path,
35                           os.O_RDWR | os.O_CREAT, stat.S_IWUSR | stat.S_IRUSR),
36                   'w', encoding='utf-8') as testfwk_info_file:
37        json.dump(json.loads(dict_product), testfwk_info_file)
38        testfwk_info_file.close()
39    return file_path
40
41
42def get_testfwk_info(platform_json_file):
43    platform_name = platform_json_file[(platform_json_file.rfind("/") + 1):]
44    platform_name = platform_name[0: platform_name.rfind(".")]
45    data = {
46        platform_name: {
47            subsystem_infos: {
48
49            },
50            part_infos: {
51
52            }
53        }
54    }
55    with open(platform_json_file, 'r') as platform_file:
56        dict_component_infos = json.load(platform_file)
57        list_subsystems = dict_component_infos["subsystems"]
58        set_components_name = []
59        for subsystem in list_subsystems:
60            subsystem_name = subsystem["subsystem"]
61            list_components_name = []
62            list_components = subsystem["components"]
63            for component in list_components:
64                component_name = component["component"]
65                list_components_name.append(component_name)
66                if component_name not in set_components_name:
67                    set_components_name.append(component_name)
68            data[platform_name][subsystem_infos][subsystem_name] = \
69                list_components_name
70        for component_name in set_components_name:
71            data[platform_name][part_infos][component_name] = \
72                {"part_name": component_name, "build_out_dir": "."}
73    return data
74
75
76if __name__ == "__main__":
77    arg_parser = argparse.ArgumentParser()
78    arg_parser.add_argument('--component-info-file', required=True)
79    arg_parser.add_argument('--output-json-fold', required=True)
80    arg_parser.add_argument('--output-json-file-name', required=True)
81    arg_parser.add_argument('--output-module-list-files-fold', required=True)
82
83    args = arg_parser.parse_args()
84
85    create_testfwk_info_file(args.component_info_file, \
86        args.output_json_fold, args.output_json_file_name)