• 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 get_platform_parts(current_platform: str, platforms_parts_file: str):
28    all_platforms_parts = read_json_file(platforms_parts_file)
29    if all_platforms_parts is None:
30        raise Exception("read file '{}' failed.".format(all_platforms_parts))
31    platform_parts = all_platforms_parts.get(current_platform)
32    return platform_parts
33
34
35def platform_parts(all_parts_info_file: str, current_platform_parts: dict):
36    _parts_list = []
37    all_parts_info = read_json_file(all_parts_info_file)
38    if all_parts_info is None:
39        raise Exception("read file '{}' failed.".format(all_parts_info_file))
40
41    for part_name in current_platform_parts.keys():
42        if part_name not in all_parts_info:
43            raise Exception(
44                "required part '{}' doesn't exist.".format(part_name))
45        _parts_list.append(all_parts_info.get(part_name))
46    return _parts_list
47
48
49def main():
50    parser = argparse.ArgumentParser()
51    parser.add_argument('--all-parts-info-file', required=True)
52    parser.add_argument('--platforms-parts-file', required=True)
53    parser.add_argument('--system-install-info-file', required=True)
54    parser.add_argument('--current-platform', required=True)
55    parser.add_argument('--depfile', required=False)
56    args = parser.parse_args()
57
58    current_platform_parts = get_platform_parts(args.current_platform,
59                                                args.platforms_parts_file)
60
61    _parts_list = platform_parts(args.all_parts_info_file,
62                                 current_platform_parts)
63
64    platform_out_dir = os.path.dirname(args.system_install_info_file)
65    if not os.path.exists(platform_out_dir):
66        os.makedirs(platform_out_dir, exist_ok=True)
67    write_json_file(args.system_install_info_file, _parts_list)
68
69    if args.depfile:
70        _dep_files = []
71        _dep_files.append(args.all_parts_info_file)
72        _dep_files.append(args.platforms_parts_file)
73        build_utils.write_depfile(args.depfile,
74                                 args.system_install_info_file,
75                                 _dep_files,
76                                 add_pydeps=False)
77    return 0
78
79
80if __name__ == '__main__':
81    sys.exit(main())
82