• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
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 argparse
18import os
19
20sys.path.append(
21    os.path.dirname(os.path.dirname(os.path.dirname(
22        os.path.abspath(__file__)))))
23from scripts.util.file_utils import read_json_file, write_json_file  # noqa: E402
24from scripts.util import build_utils  # noqa: E402
25
26
27def merge_subsystem(src_install_info_file, binary_install_info_file):
28    src_install_info = read_json_file(src_install_info_file)
29    if src_install_info is None:
30        raise Exception("read src install info file '{}' failed.".format(
31            src_install_info_file))
32
33    binary_install_info = None
34    if os.path.exists(binary_install_info_file):
35        binary_install_info = read_json_file(binary_install_info_file)
36        if binary_install_info is None:
37            raise Exception("read binary install file '{}' failed.".format(
38                binary_install_info_file))
39    else:
40        print("binary install info file '{}' no exist.".format(
41            binary_install_info_file))
42
43    merge_result = {}
44    for _subsystem_info in src_install_info:
45        part_name = _subsystem_info.get('part_name')
46        _subsystem_info['is_source'] = True
47        merge_result[part_name] = _subsystem_info
48    if binary_install_info:
49        for _subsystem_info in binary_install_info:
50            part_name = _subsystem_info.get('part_name')
51            _subsystem_info['is_source'] = False
52            merge_result[part_name] = _subsystem_info
53    return merge_result
54
55
56def main():
57    parser = argparse.ArgumentParser()
58    parser.add_argument('--src-install-info-file', required=True)
59    parser.add_argument('--binary-install-info-file', required=True)
60    parser.add_argument('--all-subsystem-info-file', required=True)
61    parser.add_argument('--depfile', required=False)
62    args = parser.parse_args()
63
64    all_subsystem_info = merge_subsystem(args.src_install_info_file,
65                                         args.binary_install_info_file)
66    write_json_file(args.all_subsystem_info_file, all_subsystem_info)
67
68    if args.depfile:
69        _dep_files = []
70        _dep_files.append(args.src_install_info_file)
71        _dep_files.append(args.binary_install_info_file)
72        build_utils.write_depfile(args.depfile,
73                                  args.all_subsystem_info_file,
74                                  _dep_files,
75                                  add_pydeps=False)
76    return 0
77
78
79if __name__ == '__main__':
80    sys.exit(main())
81