sdk_dist.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import os
  2. import sys
  3. import shutil
  4. cwd_path = os.getcwd()
  5. sys.path.append(os.path.join(os.path.dirname(cwd_path), 'rt-thread', 'tools'))
  6. # BSP dist function
  7. def dist_do_building(BSP_ROOT, dist_dir):
  8. from mkdist import bsp_copy_files
  9. import rtconfig
  10. print("=> copy ch32 bsp library")
  11. library_dir = os.path.join(dist_dir, 'Libraries')
  12. library_path = os.path.join(os.path.dirname(BSP_ROOT), 'Libraries')
  13. bsp_copy_files(os.path.join(library_path, rtconfig.BSP_LIBRARY_TYPE),
  14. os.path.join(library_dir, rtconfig.BSP_LIBRARY_TYPE))
  15. print("=> copy bsp drivers")
  16. bsp_copy_files(os.path.join(library_path, 'ch32_drivers'), os.path.join(library_dir, 'ch32_drivers'))
  17. shutil.copyfile(os.path.join(library_path, 'Kconfig'), os.path.join(library_dir, 'Kconfig'))
  18. # change RTT_ROOT in Kconfig
  19. if not os.path.isfile(os.path.join(dist_dir, 'Kconfig')):
  20. return
  21. with open(os.path.join(dist_dir, 'Kconfig'), 'r') as f:
  22. data = f.readlines()
  23. with open(os.path.join(dist_dir, 'Kconfig'), 'w') as f:
  24. found = 0
  25. for line in data:
  26. if line.find('RTT_ROOT') != -1:
  27. found = 1
  28. if line.find('../Libraries') != -1 and found:
  29. position = line.find('../Libraries')
  30. line = line[0:position] + 'Libraries/Kconfig"\n'
  31. found = 0
  32. f.write(line)