1import os 2import sys 3import shutil 4cwd_path = os.getcwd() 5sys.path.append(os.path.join(os.path.dirname(cwd_path), 'rt-thread', 'tools')) 6 7def dist_modify_relative_path(board_kconfig_path): 8 # Read in the file 9 with open(board_kconfig_path, 'r') as file : 10 filedata = file.read() 11 12 # Replace the target string 13 filedata = filedata.replace('$BSP_DIR/../libraries', './libraries') 14 15 # Write the file out again 16 with open(board_kconfig_path, 'w') as file: 17 file.write(filedata) 18 19# BSP dist function 20def dist_do_building(BSP_ROOT, dist_dir): 21 from mkdist import bsp_copy_files 22 import rtconfig 23 24 library_path = os.path.join(os.path.dirname(BSP_ROOT), 'libraries') 25 library_dir = os.path.join(dist_dir, 'libraries') 26 27 print('=> copy nuvoton bsp drivers') 28 bsp_copy_files(os.path.join(library_path, rtconfig.BSP_LIBRARY_TYPE), 29 os.path.join(library_dir, rtconfig.BSP_LIBRARY_TYPE)) 30 31 print('=> copy nu_packages') 32 bsp_copy_files(os.path.join(library_path, 'nu_packages'), 33 os.path.join(library_dir, 'nu_packages')) 34 35 print('=> copy Kconfig') 36 shutil.copyfile(os.path.join(library_path, 'Kconfig'), os.path.join(library_dir, 'Kconfig')) 37 38 print('=> Modify libraries relative path in board/Kconfig ') 39 dist_modify_relative_path(os.path.join(dist_dir, 'board', 'Kconfig'))