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 21 22part_infos = "part_infos" 23subsystem_infos = "subsystem_infos" 24 25 26def create_testfwk_info_file(component_info_file, abs_fold, file_name): 27 if not os.path.exists(abs_fold): 28 os.makedirs(abs_fold) 29 file_path = os.path.join(abs_fold, file_name) 30 data = get_testfwk_info(component_info_file) 31 dict_product = json.dumps(data) 32 with open(file_path, 'w') as testfwk_info_file: 33 json.dump(json.loads(dict_product), testfwk_info_file) 34 testfwk_info_file.close() 35 return file_path 36 37 38def get_testfwk_info(platform_json_file): 39 platform_name = platform_json_file[(platform_json_file.rfind("/") + 1):] 40 platform_name = platform_name[0: platform_name.rfind(".")] 41 data = { 42 platform_name: { 43 subsystem_infos: { 44 45 }, 46 part_infos: { 47 48 } 49 } 50 } 51 with open(platform_json_file, 'r') as platform_file: 52 dict_component_infos = json.load(platform_file) 53 list_subsystems = dict_component_infos["subsystems"] 54 set_components_name = [] 55 for subsystem in list_subsystems: 56 subsystem_name = subsystem["subsystem"] 57 list_components_name = [] 58 list_components = subsystem["components"] 59 for component in list_components: 60 component_name = component["component"] 61 list_components_name.append(component_name) 62 if component_name not in set_components_name: 63 set_components_name.append(component_name) 64 data[platform_name][subsystem_infos][subsystem_name] = \ 65 list_components_name 66 for component_name in set_components_name: 67 data[platform_name][part_infos][component_name] = \ 68 {"part_name": component_name, "build_out_dir": "."} 69 return data 70 71 72if __name__ == "__main__": 73 arg_parser = argparse.ArgumentParser() 74 arg_parser.add_argument('--component-info-file', required=True) 75 arg_parser.add_argument('--output-json-fold', required=True) 76 arg_parser.add_argument('--output-json-file-name', required=True) 77 arg_parser.add_argument('--output-module-list-files-fold', required=True) 78 79 args = arg_parser.parse_args() 80 81 create_testfwk_info_file(args.component_info_file, \ 82 args.output_json_fold, args.output_json_file_name)