15f9996aaSopenharmony_ci#!/usr/bin/env python 25f9996aaSopenharmony_ci# -*- coding: utf-8 -*- 35f9996aaSopenharmony_ci# Copyright (c) 2021 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 sys 175f9996aaSopenharmony_ciimport argparse 185f9996aaSopenharmony_ciimport os 195f9996aaSopenharmony_ci 205f9996aaSopenharmony_cisys.path.append( 215f9996aaSopenharmony_ci os.path.dirname(os.path.dirname(os.path.dirname( 225f9996aaSopenharmony_ci os.path.abspath(__file__))))) 235f9996aaSopenharmony_cifrom scripts.util.file_utils import read_json_file, write_json_file # noqa: E402 245f9996aaSopenharmony_ci 255f9996aaSopenharmony_ci 265f9996aaSopenharmony_cidef subsystem_list(all_subsystem_info_file: str, curr_subsystem_name_list_file: str): 275f9996aaSopenharmony_ci curr_subsystem_list = [] 285f9996aaSopenharmony_ci all_subsystem_info = read_json_file(all_subsystem_info_file) 295f9996aaSopenharmony_ci if all_subsystem_info is None: 305f9996aaSopenharmony_ci raise Exception( 315f9996aaSopenharmony_ci "read file '{}' failed.".format(all_subsystem_info_file)) 325f9996aaSopenharmony_ci curr_subsystem_name_list = read_json_file(curr_subsystem_name_list_file) 335f9996aaSopenharmony_ci if curr_subsystem_name_list is None: 345f9996aaSopenharmony_ci raise Exception( 355f9996aaSopenharmony_ci "read file '{}' failed.".format(curr_subsystem_name_list_file)) 365f9996aaSopenharmony_ci for _subsystem_name in curr_subsystem_name_list: 375f9996aaSopenharmony_ci if _subsystem_name not in all_subsystem_info: 385f9996aaSopenharmony_ci continue 395f9996aaSopenharmony_ci else: 405f9996aaSopenharmony_ci curr_subsystem_list.append(all_subsystem_info.get(_subsystem_name)) 415f9996aaSopenharmony_ci return curr_subsystem_list 425f9996aaSopenharmony_ci 435f9996aaSopenharmony_ci 445f9996aaSopenharmony_cidef main(): 455f9996aaSopenharmony_ci parser = argparse.ArgumentParser() 465f9996aaSopenharmony_ci parser.add_argument('--target-platform-parts', required=True) 475f9996aaSopenharmony_ci parser.add_argument('--parts-install-info-file', required=True) 485f9996aaSopenharmony_ci parser.add_argument('--current-platform', required=True) 495f9996aaSopenharmony_ci args = parser.parse_args() 505f9996aaSopenharmony_ci 515f9996aaSopenharmony_ci curr_subsystem_list = subsystem_list(args.all_subsystem_info_file, 525f9996aaSopenharmony_ci args.target_platform_subsystem) 535f9996aaSopenharmony_ci platform_out_dir = os.path.dirname(args.system_install_info_file) 545f9996aaSopenharmony_ci if not os.path.exists(platform_out_dir): 555f9996aaSopenharmony_ci os.makedirs(platform_out_dir, exist_ok=True) 565f9996aaSopenharmony_ci write_json_file(args.system_install_info_file, curr_subsystem_list) 575f9996aaSopenharmony_ci return 0 585f9996aaSopenharmony_ci 595f9996aaSopenharmony_ci 605f9996aaSopenharmony_ciif __name__ == '__main__': 615f9996aaSopenharmony_ci sys.exit(main()) 62