iar_gen.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/python3
  2. import os
  3. import xml.dom.minidom as XML
  4. # Read base configuration
  5. base = ""
  6. with open("iar_template.ipcf") as f:
  7. base = f.read()
  8. # Enumerate all device/host examples
  9. dir_1 = os.listdir("../examples")
  10. for dir_2 in dir_1:
  11. if os.path.isdir("../examples/{}".format(dir_2)):
  12. print(dir_2)
  13. examples = os.listdir("../examples/{}".format(dir_2))
  14. for example in examples:
  15. if os.path.isdir("../examples/{}/{}".format(dir_2, example)):
  16. print("../examples/{}/{}".format(dir_2, example))
  17. conf = XML.parseString(base)
  18. files = conf.getElementsByTagName("files")[0]
  19. inc = conf.getElementsByTagName("includePath")[0]
  20. # Add bsp inc
  21. path = conf.createElement('path')
  22. path_txt = conf.createTextNode("$TUSB_DIR$/hw")
  23. path.appendChild(path_txt)
  24. inc.appendChild(path)
  25. # Add board.c/.h
  26. grp = conf.createElement('group')
  27. grp.setAttribute("name", "bsp")
  28. path = conf.createElement('path')
  29. path_txt = conf.createTextNode("$TUSB_DIR$/hw/bsp/board.c")
  30. path.appendChild(path_txt)
  31. grp.appendChild(path)
  32. files.appendChild(grp)
  33. # Add example's .c/.h
  34. grp = conf.createElement('group')
  35. grp.setAttribute("name", "example")
  36. for file in os.listdir("../examples/{}/{}/src".format(dir_2, example)):
  37. if file.endswith(".c") or file.endswith(".h"):
  38. path = conf.createElement('path')
  39. path.setAttribute("copyTo", "$PROJ_DIR$/{}".format(file))
  40. path_txt = conf.createTextNode("$TUSB_DIR$/examples/{0}/{1}/src/{2}".format(dir_2, example, file))
  41. path.appendChild(path_txt)
  42. grp.appendChild(path)
  43. files.appendChild(grp)
  44. cfg_str = conf.toprettyxml()
  45. cfg_str = '\n'.join([s for s in cfg_str.splitlines() if s.strip()])
  46. #print(cfg_str)
  47. with open("../examples/{0}/{1}/iar_{1}.ipcf".format(dir_2, example), 'w') as f:
  48. f.write(cfg_str)