• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
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 os
18import argparse
19
20import file_utils
21import dependence_analysis
22
23
24def gen_module_deps(deps_data: dict):
25    part_allowlist = ['unittest', 'moduletest', 'systemtest']
26    label_to_alias = {}
27    for _module_alias, _info in deps_data.items():
28        _module_label = _info.get('module_label').split('(')[0]
29        label_to_alias[_module_label] = _module_alias
30
31    modeule_deps_data = {}
32    for _module_alias, _info in deps_data.items():
33        deps_module_list = []
34        _part_name = _info.get('part_name')
35        if _part_name in part_allowlist:
36            continue
37        _deps_label_list = _info.get('deps')
38        for _deps_label in _deps_label_list:
39            _alias = label_to_alias.get(_deps_label)
40            if _alias is None:
41                continue
42            deps_module_list.append(_alias)
43        _external_deps_list = _info.get('external_deps')
44        for _ext_deps in _external_deps_list:
45            deps_module_list.append(_ext_deps)
46
47        deps_value = modeule_deps_data.get(_module_alias, [])
48        deps_value.extend(deps_module_list)
49        modeule_deps_data[_module_alias] = list(set(deps_value))
50    return modeule_deps_data
51
52
53def run(deps_files_path: str, output_path: str):
54    all_deps_data = dependence_analysis.get_all_deps_data(deps_files_path)
55    all_deps_data_file = os.path.join(output_path, 'all_deps_data.json')
56    file_utils.write_json_file(all_deps_data_file, all_deps_data)
57
58    module_deps_data = gen_module_deps(all_deps_data)
59    module_deps_data_file = os.path.join(output_path, 'module_deps_info.json')
60    file_utils.write_json_file(module_deps_data_file, module_deps_data)
61
62
63def main(argv):
64    parser = argparse.ArgumentParser()
65    parser.add_argument('--deps-files-path', required=True)
66    args = parser.parse_args(argv)
67
68    if not os.path.exists(args.deps_files_path):
69        raise Exception("'{}' doesn't exist.".format(args.deps_files_path))
70    output_path = os.path.join(os.path.dirname(args.deps_files_path),
71                               'module_deps_info')
72    print("------Generate module dependency info------")
73    run(args.deps_files_path, output_path)
74    print('module deps data output to {}'.format(output_path))
75
76
77if __name__ == '__main__':
78    sys.exit(main(sys.argv[1:]))
79