sdk_dist.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import os
  2. import re
  3. import sys
  4. import shutil
  5. cwd_path = os.getcwd()
  6. sys.path.append(os.path.join(os.path.dirname(cwd_path), 'rt-thread', 'tools'))
  7. def bsp_update_kconfig_library(dist_dir):
  8. # change RTT_ROOT in Kconfig
  9. if not os.path.isfile(os.path.join(dist_dir, 'Kconfig')):
  10. return
  11. with open(os.path.join(dist_dir, 'Kconfig'), 'r') as f:
  12. data = f.readlines()
  13. with open(os.path.join(dist_dir, 'Kconfig'), 'w') as f:
  14. for line in data:
  15. if line.find('source') != -1 and line.find('../libraries') != -1:
  16. line = line.replace('../libraries', 'libraries')
  17. f.write(line)
  18. # BSP dist function
  19. def dist_do_building(BSP_ROOT, dist_dir):
  20. from mkdist import bsp_copy_files
  21. import rtconfig
  22. print("=> copy ht32 bsp library")
  23. library_dir = os.path.join(dist_dir, 'libraries')
  24. library_path = os.path.join(os.path.dirname(BSP_ROOT), 'libraries')
  25. bsp_copy_files(os.path.join(library_path, rtconfig.BSP_LIBRARY_TYPE), os.path.join(library_dir, rtconfig.BSP_LIBRARY_TYPE))
  26. print("=> copy bsp drivers")
  27. bsp_copy_files(os.path.join(library_path, 'ht32_drivers'), os.path.join(library_dir, 'ht32_drivers'))
  28. shutil.copyfile(os.path.join(library_path, 'Kconfig'), os.path.join(library_dir, 'Kconfig'))
  29. bsp_update_kconfig_library(dist_dir)
  30. def get_source(ic_model, file_path, system_path, base_path):
  31. source_path = []
  32. files_list = []
  33. readafter = 0
  34. if not os.path.isfile(file_path):
  35. return
  36. with open(file_path, 'r') as file:
  37. # content = file.read()
  38. for line in file:
  39. if readafter == 2 and line.find('>') != -1:
  40. break
  41. if readafter == 2:
  42. files_list.append(line.strip())
  43. if line.find(ic_model) != -1:
  44. readafter = 1
  45. if readafter == 1 and line.find('<') != -1:
  46. readafter = 2
  47. for line in files_list:
  48. if line.find('system') != -1:
  49. source_path.append(os.path.join(system_path, line.strip()))
  50. else:
  51. source_path.append(os.path.join(base_path, line.strip()))
  52. return source_path