• 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 os
17import sys
18
19sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
20from loader import subsystem_scan  # noqa: E402
21from scripts.util.file_utils import write_json_file  # noqa: E402
22
23
24def _output_subsystem_configs(output_dir, subsystem_configs):
25    build_config_file_name = "subsystem_build_config.json"
26    build_config_file = os.path.join(output_dir, 'subsystem_info',
27                                     build_config_file_name)
28    write_json_file(build_config_file, subsystem_configs)
29
30    src_output_file_name = "src_subsystem_info.json"
31    no_src_output_file_name = "no_src_subsystem_info.json"
32
33    src_subsystem = {}
34    for key, val in subsystem_configs.get('subsystem').items():
35        src_subsystem[key] = val.get('path')
36    src_output_file = os.path.join(output_dir, 'subsystem_info',
37                                   src_output_file_name)
38    write_json_file(src_output_file, src_subsystem)
39
40    no_src_output_file = os.path.join(output_dir, 'subsystem_info',
41                                      no_src_output_file_name)
42    write_json_file(no_src_output_file,
43                    subsystem_configs.get('no_src_subsystem'))
44
45
46def get_subsystem_info(subsystem_config_file, example_subsystem_file,
47                       source_root_dir, config_output_path, os_level):
48    if not subsystem_config_file:
49        subsystem_config_file = 'build/subsystem_config.json'
50
51    subsystem_configs = {}
52    output_dir_realpath = os.path.join(source_root_dir, config_output_path)
53    subsystem_configs = subsystem_scan.scan(subsystem_config_file,
54                                            example_subsystem_file,
55                                            source_root_dir)
56
57    _output_subsystem_configs(output_dir_realpath, subsystem_configs)
58    return subsystem_configs.get('subsystem')
59