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 argparse 175f9996aaSopenharmony_ciimport os 185f9996aaSopenharmony_ciimport sys 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 # noqa: E402 245f9996aaSopenharmony_ci 255f9996aaSopenharmony_ci 265f9996aaSopenharmony_cidef check(args) -> list: 275f9996aaSopenharmony_ci depfiles = [] 285f9996aaSopenharmony_ci # ignore test related parts 295f9996aaSopenharmony_ci part_allow_set = {'libc-test', 'libc-test-lib', 'libc-gtest-lib'} 305f9996aaSopenharmony_ci if args.part_name in part_allow_set: 315f9996aaSopenharmony_ci return depfiles 325f9996aaSopenharmony_ci 335f9996aaSopenharmony_ci compile_standard_allow_file = args.compile_standard_allow_file 345f9996aaSopenharmony_ci compile_standard_allow_info = read_json_file(compile_standard_allow_file) 355f9996aaSopenharmony_ci bundle_file_allow_list = compile_standard_allow_info.get("gn_part_or_subsystem_error", []) 365f9996aaSopenharmony_ci part_subsystem_info_file = 'build_configs/parts_info/part_subsystem.json' 375f9996aaSopenharmony_ci data = read_json_file(part_subsystem_info_file) 385f9996aaSopenharmony_ci if data is None: 395f9996aaSopenharmony_ci raise Exception( 405f9996aaSopenharmony_ci "read file '{}' failed.".format(part_subsystem_info_file)) 415f9996aaSopenharmony_ci depfiles.append(part_subsystem_info_file) 425f9996aaSopenharmony_ci 435f9996aaSopenharmony_ci subsystems_name = data.get(args.part_name) 445f9996aaSopenharmony_ci if subsystems_name is None or subsystems_name == '' or subsystems_name != args.subsystem_name: 455f9996aaSopenharmony_ci message = f"subsystem name or part name is incorrect, " \ 465f9996aaSopenharmony_ci f"target is {args.target_path}, subsystem name is {args.subsystem_name}, " \ 475f9996aaSopenharmony_ci f"part name is {args.part_name}" 485f9996aaSopenharmony_ci if args.target_path in bundle_file_allow_list: 495f9996aaSopenharmony_ci print(f"[0/0] warning: {message}") 505f9996aaSopenharmony_ci else: 515f9996aaSopenharmony_ci raise Exception(message) 525f9996aaSopenharmony_ci 535f9996aaSopenharmony_ci return depfiles 545f9996aaSopenharmony_ci 555f9996aaSopenharmony_ci 565f9996aaSopenharmony_cidef main(): 575f9996aaSopenharmony_ci parser = argparse.ArgumentParser() 585f9996aaSopenharmony_ci parser.add_argument('--part-name', required=True) 595f9996aaSopenharmony_ci parser.add_argument('--subsystem-name', required=True) 605f9996aaSopenharmony_ci parser.add_argument('--target-path', required=True) 615f9996aaSopenharmony_ci args = parser.parse_args() 625f9996aaSopenharmony_ci 635f9996aaSopenharmony_ci check(args) 645f9996aaSopenharmony_ci 655f9996aaSopenharmony_ci return 0 665f9996aaSopenharmony_ci 675f9996aaSopenharmony_ciif __name__ == '__main__': 685f9996aaSopenharmony_ci sys.exit(main()) 69