1#!/usr/bin/env python3 2# coding=utf-8 3# Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16# Description: projects rom targets rom_bin compare, just befor rom fixed \n 17# 18# History: \n 19# 2023-03-22, Create file. \n 20import sys 21import os 22import json 23from build_utils import root_path, compare_bin, output_root 24 25def replace_file_path(file_path, chip): 26 file_path = file_path.replace('<out_root>', output_root) 27 file_path = file_path.replace('<chip>', chip) 28 return file_path 29 30def compare(chip): 31 chip_config_path = os.path.join(root_path, 'build', 'config', 'target_config', chip) 32 target_compare_config = os.path.join(chip_config_path, 'compare', 'compare.json') 33 if not os.path.exists(target_compare_config): 34 return 35 with open(target_compare_config, 'r') as fp: 36 temp = fp.read() 37 configs = json.loads(temp) 38 for config in configs: 39 file_name = config['name'] 40 basefile = replace_file_path(os.path.join(config["targets"][0], file_name), chip) 41 for targets in config["targets"][1:]: 42 target_filee = replace_file_path(os.path.join(targets, file_name), chip) 43 if not compare_bin(basefile, target_filee): 44 return False 45 return True 46 47if __name__ == "__main__": 48 if len(sys.argv) > 2: 49 print("Compare Param Error") 50 sys.exit(1) 51 if compare(sys.argv[1]): 52 sys.exit(0) 53 sys.exit(1)