15f9996aaSopenharmony_ci#!/usr/bin/env python 25f9996aaSopenharmony_ci# -*- coding: utf-8 -*- 35f9996aaSopenharmony_ci# Copyright (c) 2023 Huawei Device Co., Ltd. 45f9996aaSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 55f9996aaSopenharmony_ci# you may not use this file except in compliance with the License. 65f9996aaSopenharmony_ci# You may obtain a copy of the License at 75f9996aaSopenharmony_ci# 85f9996aaSopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 95f9996aaSopenharmony_ci# 105f9996aaSopenharmony_ci# Unless required by applicable law or agreed to in writing, software 115f9996aaSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 125f9996aaSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135f9996aaSopenharmony_ci# See the License for the specific language governing permissions and 145f9996aaSopenharmony_ci# limitations under the License. 155f9996aaSopenharmony_ci 165f9996aaSopenharmony_ciimport os 175f9996aaSopenharmony_ciimport sys 185f9996aaSopenharmony_ci 195f9996aaSopenharmony_cifrom scripts.util.file_utils import write_json_file # noqa: E402 205f9996aaSopenharmony_cifrom . import subsystem_scan # noqa: E402 215f9996aaSopenharmony_cifrom resources.config import Config 225f9996aaSopenharmony_ci 235f9996aaSopenharmony_ci 245f9996aaSopenharmony_cidef _output_subsystem_configs(output_dir, subsystem_configs): 255f9996aaSopenharmony_ci build_config_file_name = "subsystem_build_config.json" 265f9996aaSopenharmony_ci build_config_file = os.path.join(output_dir, 'subsystem_info', 275f9996aaSopenharmony_ci build_config_file_name) 285f9996aaSopenharmony_ci write_json_file(build_config_file, subsystem_configs) 295f9996aaSopenharmony_ci 305f9996aaSopenharmony_ci src_output_file_name = "src_subsystem_info.json" 315f9996aaSopenharmony_ci no_src_output_file_name = "no_src_subsystem_info.json" 325f9996aaSopenharmony_ci 335f9996aaSopenharmony_ci src_subsystem = {} 345f9996aaSopenharmony_ci for key, val in subsystem_configs.get('subsystem').items(): 355f9996aaSopenharmony_ci src_subsystem[key] = val.get('path') 365f9996aaSopenharmony_ci src_output_file = os.path.join(output_dir, 'subsystem_info', 375f9996aaSopenharmony_ci src_output_file_name) 385f9996aaSopenharmony_ci write_json_file(src_output_file, src_subsystem) 395f9996aaSopenharmony_ci 405f9996aaSopenharmony_ci no_src_output_file = os.path.join(output_dir, 'subsystem_info', 415f9996aaSopenharmony_ci no_src_output_file_name) 425f9996aaSopenharmony_ci write_json_file(no_src_output_file, 435f9996aaSopenharmony_ci subsystem_configs.get('no_src_subsystem')) 445f9996aaSopenharmony_ci 455f9996aaSopenharmony_ci 465f9996aaSopenharmony_cidef merge_subsystem_overlay(subsystem_configs, subsystem_config_overlay, key): 475f9996aaSopenharmony_ci subsystem_info = subsystem_configs[key] 485f9996aaSopenharmony_ci overlay_info = subsystem_config_overlay[key] 495f9996aaSopenharmony_ci 505f9996aaSopenharmony_ci for subsystem in overlay_info: 515f9996aaSopenharmony_ci if subsystem in subsystem_info: 525f9996aaSopenharmony_ci overlay_path = subsystem_config_overlay.get('subsystem').get(subsystem)['path'] 535f9996aaSopenharmony_ci for path in overlay_path: 545f9996aaSopenharmony_ci if not (path.find("vendor") != -1 or path.find("device") != -1): 555f9996aaSopenharmony_ci continue 565f9996aaSopenharmony_ci else: 575f9996aaSopenharmony_ci subsystem_configs.get('subsystem').get(subsystem)['path'] += \ 585f9996aaSopenharmony_ci subsystem_config_overlay.get('subsystem').get(subsystem)['path'] 595f9996aaSopenharmony_ci subsystem_configs.get('subsystem').get(subsystem)['build_files'] += \ 605f9996aaSopenharmony_ci subsystem_config_overlay.get('subsystem').get(subsystem)['build_files'] 615f9996aaSopenharmony_ci else: 625f9996aaSopenharmony_ci subsystem_configs[key].setdefault(subsystem, subsystem_config_overlay[key][subsystem]) 635f9996aaSopenharmony_ci 645f9996aaSopenharmony_ci 655f9996aaSopenharmony_cidef get_subsystem_info(subsystem_config_file, example_subsystem_file, 665f9996aaSopenharmony_ci source_root_dir, config_output_path, os_level): 675f9996aaSopenharmony_ci if not subsystem_config_file: 685f9996aaSopenharmony_ci subsystem_config_file = 'build/subsystem_config.json' 695f9996aaSopenharmony_ci 705f9996aaSopenharmony_ci subsystem_configs = {} 715f9996aaSopenharmony_ci output_dir_realpath = os.path.join(source_root_dir, config_output_path) 725f9996aaSopenharmony_ci subsystem_configs = subsystem_scan.scan(subsystem_config_file, 735f9996aaSopenharmony_ci example_subsystem_file, 745f9996aaSopenharmony_ci source_root_dir) 755f9996aaSopenharmony_ci config = Config() 765f9996aaSopenharmony_ci subsystem_config_overlay_file = os.path.join( 775f9996aaSopenharmony_ci config.product_path, "subsystem_config_overlay.json") 785f9996aaSopenharmony_ci if os.path.isfile(subsystem_config_overlay_file): 795f9996aaSopenharmony_ci subsystem_config_overlay = {} 805f9996aaSopenharmony_ci subsystem_config_overlay = subsystem_scan.scan(subsystem_config_overlay_file, 815f9996aaSopenharmony_ci example_subsystem_file, 825f9996aaSopenharmony_ci source_root_dir) 835f9996aaSopenharmony_ci merge_subsystem_overlay(subsystem_configs, subsystem_config_overlay, 'subsystem') 845f9996aaSopenharmony_ci merge_subsystem_overlay(subsystem_configs, subsystem_config_overlay, 'no_src_subsystem') 855f9996aaSopenharmony_ci 865f9996aaSopenharmony_ci _output_subsystem_configs(output_dir_realpath, subsystem_configs) 875f9996aaSopenharmony_ci return subsystem_configs.get('subsystem') 88