1ba991379Sopenharmony_ci#!/usr/bin/env python
2ba991379Sopenharmony_ci#coding=utf-8
3ba991379Sopenharmony_ci
4ba991379Sopenharmony_ci#
5ba991379Sopenharmony_ci# Copyright (c) 2023-2024 Huawei Device Co., Ltd.
6ba991379Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
7ba991379Sopenharmony_ci# you may not use this file except in compliance with the License.
8ba991379Sopenharmony_ci# You may obtain a copy of the License at
9ba991379Sopenharmony_ci#
10ba991379Sopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
11ba991379Sopenharmony_ci#
12ba991379Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
13ba991379Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
14ba991379Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15ba991379Sopenharmony_ci# See the License for the specific language governing permissions and
16ba991379Sopenharmony_ci# limitations under the License.
17ba991379Sopenharmony_ci#
18ba991379Sopenharmony_ci
19ba991379Sopenharmony_cifrom config_parser_mgr import ConfigParserMgr
20ba991379Sopenharmony_ci
21ba991379Sopenharmony_ci
22ba991379Sopenharmony_cidef __create_arg_parser():
23ba991379Sopenharmony_ci    import argparse
24ba991379Sopenharmony_ci    parser = argparse.ArgumentParser(description='Check startup architecture information from compiled output files.')
25ba991379Sopenharmony_ci    parser.add_argument('-i', '--input',
26ba991379Sopenharmony_ci                        help='input config files base directory example "out/rk3568" ', required=True)
27ba991379Sopenharmony_ci    parser.add_argument('-c', '--target_cpu',
28ba991379Sopenharmony_ci                    help='target_cpu cpu type" ', required=True)
29ba991379Sopenharmony_ci    parser.add_argument('-r', '--rules', action='append',
30ba991379Sopenharmony_ci                        help='rules directory', required=False)
31ba991379Sopenharmony_ci    parser.add_argument('-n', '--no_fail',
32ba991379Sopenharmony_ci                        help='force to pass all rules', required=False)
33ba991379Sopenharmony_ci    return parser
34ba991379Sopenharmony_ci
35ba991379Sopenharmony_cidef startup_guard(out_path, target_cpu ,args=None):
36ba991379Sopenharmony_ci    mgr = ConfigParserMgr()
37ba991379Sopenharmony_ci    mgr.load_all_parser(out_path, target_cpu)
38ba991379Sopenharmony_ci
39ba991379Sopenharmony_ci    from startup_checker import check_all_rules
40ba991379Sopenharmony_ci    passed = check_all_rules(mgr, args)
41ba991379Sopenharmony_ci    if passed:
42ba991379Sopenharmony_ci        print("All rules passed")
43ba991379Sopenharmony_ci    else:
44ba991379Sopenharmony_ci        print("Please modify according to README.md")
45ba991379Sopenharmony_ci
46ba991379Sopenharmony_ciif __name__ == '__main__':
47ba991379Sopenharmony_ci    parser = __create_arg_parser()
48ba991379Sopenharmony_ci    args = parser.parse_args()
49ba991379Sopenharmony_ci    startup_guard(args.input, args.target_cpu, args)
50