1#!/usr/bin/env python 2#coding=utf-8 3 4# 5# Copyright (c) 2022 Huawei Device Co., Ltd. 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18 19from elf_file_mgr import ElfFileMgr 20 21 22def __create_arg_parser(): 23 import argparse 24 25 parser = argparse.ArgumentParser(description='Check architecture information from compiled output files.') 26 27 parser.add_argument('-i', '--input', 28 help='input asset files root directory', required=True) 29 30 parser.add_argument('-r', '--rules', action='append', 31 help='rules directory', required=False) 32 33 parser.add_argument('-n', '--no-fail', 34 help='force to pass all rules', required=False) 35 36 return parser 37 38 39def _deps_guard_module(out_path, args=None): 40 mgr = ElfFileMgr(out_path) 41 mgr.scan_all_files() 42 43 from rules_checker import check_all_rules 44 45 passed = check_all_rules(mgr, args) 46 if passed: 47 print("All rules passed") 48 return 49 50 raise Exception("ERROR: deps_guard failed.") 51 52 53def _startup_guard_module(out_path, target_cpu, args): 54 import sys 55 import os 56 for path in sys.path: 57 if path.endswith("developtools/integration_verification/tools/deps_guard"): 58 sys.path.append(os.path.join( 59 path, "../startup_guard")) 60 break 61 62 from startup_guard import startup_guard 63 64 startup_guard(out_path, target_cpu, args) 65 66 67def deps_guard(out_path, target_cpu, args=None): 68 _deps_guard_module(out_path, args) 69 _startup_guard_module(out_path, target_cpu, args) 70 71 72if __name__ == '__main__': 73 74 parser = __create_arg_parser() 75 args = parser.parse_args() 76 77 _deps_guard_module(args.input, args) 78