• 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
23import stat
24
25FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL
26MODES = stat.S_IWUSR | stat.S_IRUSR
27
28
29def _init_sys_config():
30    sys.localcoverage_path = os.path.join(current_path, "..")
31    sys.path.insert(0, sys.localcoverage_path)
32
33
34def gen_parts_info_json(folder_list, output_json_path, target_cpu):
35    """
36    根据部件信息,生成字典至json文件中
37    """
38    if len(folder_list) != 0:
39        data_dict = {}
40        for folder_str in folder_list:
41            data_dict[folder_str] = f"innerkits/ohos-{target_cpu}/{folder_str}"
42        output_json_path = os.path.join(output_json_path, "kits_modules_info.json")
43        json_str = json.dumps(data_dict, indent=2)
44        if os.path.exists(output_json_path):
45            os.remove(output_json_path)
46        with os.fdopen(os.open(output_json_path, FLAGS, MODES), 'w') as json_file:
47            json_file.write(json_str)
48    else:
49        print("part_name list information is null")
50
51
52def get_parts_list(path):
53    """
54    #获取out/ohos-arm-release/innerkits/ohos-arm内部接口文件夹名称列表
55    """
56    if os.path.exists(path):
57        folder_list = os.listdir(path)
58    else:
59        print("The folder: %s does not exist" % path)
60        folder_list = []
61    return folder_list
62
63
64if __name__ == "__main__":
65    current_path = os.getcwd()
66    _init_sys_config()
67    from local_coverage.utils import get_product_name, coverage_command, get_target_cpu
68
69    root_path = current_path.split("/test/testfwk/developer_test")[0]
70    product_name = get_product_name(root_path)
71    cpu_type = get_target_cpu(root_path)
72    part_info_path = os.path.join(
73        root_path, "out", product_name, "innerkits/ohos-%s" % cpu_type
74    )
75    json_path = os.path.join(
76        root_path, "out", product_name, "packages/phone/innerkits/ohos-%s" % cpu_type
77    )
78    coverage_command("mkdir -p %s" % json_path)
79    part_list = get_parts_list(part_info_path)
80    gen_parts_info_json(part_list, json_path, cpu_type)
81