• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# coding=utf-8
3
4#
5# Copyright (c) 2023 Huawei Device Co., Ltd.
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19
20import os
21import json
22import sys
23
24
25def _init_sys_config():
26    sys.localcoverage_path = os.path.join(current_path, "..")
27    sys.path.insert(0, sys.localcoverage_path)
28
29
30def gen_parts_info_json(folder_list, output_json_path, target_cpu):
31    """
32    根据部件信息,生成字典至json文件中
33    """
34    if len(folder_list) != 0:
35        data_dict = {}
36        for folder_str in folder_list:
37            data_dict[folder_str] = f"innerkits/ohos-{target_cpu}/{folder_str}"
38        output_json_path = os.path.join(output_json_path, "kits_modules_info.json")
39        json_str = json.dumps(data_dict, indent=2)
40        with open(output_json_path, "w") as json_file:
41            json_file.write(json_str)
42    else:
43        print("part_name list information is null")
44
45
46def get_parts_list(path):
47    """
48    #获取out/ohos-arm-release/innerkits/ohos-arm内部接口文件夹名称列表
49    """
50    if os.path.exists(path):
51        folder_list = os.listdir(path)
52    else:
53        print("The folder: %s does not exist" % path)
54        folder_list = []
55    return folder_list
56
57
58if __name__ == "__main__":
59    current_path = os.getcwd()
60    _init_sys_config()
61    from localCoverage.utils import get_product_name, coverage_command, get_target_cpu
62
63    root_path = current_path.split("/test/testfwk/developer_test")[0]
64    product_name = get_product_name(root_path)
65    cpu_type = get_target_cpu(root_path)
66    part_info_path = os.path.join(
67        root_path, "out", product_name, "innerkits/ohos-%s" % cpu_type
68    )
69    json_path = os.path.join(
70        root_path, "out", product_name, "packages/phone/innerkits/ohos-%s" % cpu_type
71    )
72    coverage_command("mkdir -p %s" % json_path)
73    part_list = get_parts_list(part_info_path)
74    gen_parts_info_json(part_list, json_path, cpu_type)
75