buildbot.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import os
  2. import sys
  3. def usage():
  4. print('%s all -- build all bsp' % os.path.basename(sys.argv[0]))
  5. print('%s clean -- clean all bsp' % os.path.basename(sys.argv[0]))
  6. print('%s project -- update all prject files' % os.path.basename(sys.argv[0]))
  7. BSP_ROOT = os.path.join("..", "bsp")
  8. if len(sys.argv) != 2:
  9. usage()
  10. sys.exit(0)
  11. def update_project_file(project_dir):
  12. if os.path.isfile(os.path.join(project_dir, 'template.Uv2')):
  13. print('prepare MDK3 project file on ' + project_dir)
  14. command = ' --target=mdk -s'
  15. os.system('scons --directory=' + project_dir + command + ' > 1.txt')
  16. if os.path.isfile(os.path.join(project_dir, 'template.uvproj')):
  17. print('prepare MDK4 project file on ' + project_dir)
  18. command = ' --target=mdk4 -s'
  19. os.system('scons --directory=' + project_dir + command + ' > 1.txt')
  20. if os.path.isfile(os.path.join(project_dir, 'template.uvprojx')):
  21. print('prepare MDK5 project file on ' + project_dir)
  22. command = ' --target=mdk5 -s'
  23. os.system('scons --directory=' + project_dir + command + ' > 1.txt')
  24. if os.path.isfile(os.path.join(project_dir, 'template.ewp')):
  25. print('prepare IAR project file on ' + project_dir)
  26. command = ' --target=iar -s'
  27. os.system('scons --directory=' + project_dir + command + ' > 1.txt')
  28. def update_all_project_files(root_path):
  29. # current path is dir
  30. if os.path.isdir(root_path):
  31. projects = os.listdir(root_path)
  32. # is a project path?
  33. if "SConscript" in projects:
  34. try:
  35. if "win32" in sys.platform:
  36. retval = os.getcwd()
  37. os.chdir(root_path)
  38. os.system("menuconfig --silent")
  39. os.chdir(retval)
  40. else:
  41. os.system('scons --pyconfig-silent -C {0}'.format(root_path)) # update rtconfig.h and .config
  42. update_project_file(root_path)
  43. except Exception as e:
  44. print("error message: {}".format(e))
  45. sys.exit(-1)
  46. else:
  47. for i in projects:
  48. new_root_path = os.path.join(root_path, i)
  49. update_all_project_files(new_root_path)
  50. # get command options
  51. command = ''
  52. if sys.argv[1] == 'all':
  53. command = ' '
  54. elif sys.argv[1] == 'clean':
  55. command = ' -c'
  56. elif sys.argv[1] == 'project':
  57. update_all_project_files(BSP_ROOT)
  58. sys.exit(0)
  59. else:
  60. usage()
  61. sys.exit(0)
  62. projects = os.listdir(BSP_ROOT)
  63. for item in projects:
  64. project_dir = os.path.join(BSP_ROOT, item)
  65. if os.path.isfile(os.path.join(project_dir, 'SConstruct')):
  66. if os.system('scons --directory=' + project_dir + command) != 0:
  67. print('build failed!!')
  68. break