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 16import os 17import re 18import sys 19import platform 20import string 21import shutil 22import json 23 24XML_PATH="build/config/target_config/<chip>/hdb_config/database_cfg/mk_hdb_xml.json" 25 26def recursive_copy_overwrite(src, dest, ignore=None): 27 if os.path.isdir(src): 28 if not os.path.isdir(dest): 29 os.makedirs(dest) 30 files = os.listdir(src) 31 if ignore is not None: 32 ignored = ignore(src, files) 33 else: 34 ignored = set() 35 for f in files: 36 if f not in ignored: 37 recursive_copy_overwrite(os.path.join(src, f), os.path.join(dest, f), ignore) 38 else: 39 shutil.copyfile(src, dest) 40 41def xml_ignore(path, names): 42 ignored_names = [] 43 for name in names: 44 if name.endswith('mss_prim_db.xml'): 45 ignored_names.append(name) 46 return set(ignored_names) 47 48def process_pre_generated_db_xml(): 49 global G_PARAMS 50 root = sys.argv[1] 51 chip = sys.argv[2] 52 in_path = XML_PATH 53 in_path = in_path.replace('<chip>', chip) 54 55 db_conf = None 56 conf = os.path.join(root, in_path) 57 with open(conf, 'r') as f: 58 db_conf = json.load(f) 59 60 if ("HDB_XML_PRE_GENERATED_DIR" not in db_conf): 61 print("HDB_XML_PRE_GENERATED_DIR NOT in json") 62 return 63 64 G_PARAMS = {} 65 G_PARAMS['BUILD_TEMP_PATH'] = os.path.join(root, db_conf["BUILD_TEMP_PATH"]) 66 G_PARAMS['HDB_XML_PRE_GENERATED_DIR'] = db_conf["HDB_XML_PRE_GENERATED_DIR"] 67 68 src_dir = [] 69 src_dir = G_PARAMS['HDB_XML_PRE_GENERATED_DIR'] 70 dst_dir = G_PARAMS['BUILD_TEMP_PATH'].strip() 71 72 for dir in src_dir: 73 full_dir = os.path.join(root, dir) 74 if(os.path.exists(full_dir)): 75 recursive_copy_overwrite(full_dir, dst_dir, xml_ignore) 76 77# main 78if __name__ == "__main__": 79 process_pre_generated_db_xml() 80