wizard.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #! /usr/bin/env python
  2. #coding=utf-8
  3. """
  4. wizard.py - a script to generate SConscript in RT-Thread RTOS.
  5. `wizard --component name' to generate SConscript for name component.
  6. `wizard --bridge' to generate SConscript as a bridge to connect each
  7. SConscript script file of sub-directory.
  8. """
  9. import sys
  10. SConscript_com = '''# RT-Thread building script for component
  11. from building import *
  12. cwd = GetCurrentDir()
  13. src = Glob('*.c')
  14. CPPPATH = [cwd]
  15. group = DefineGroup('COMPONENT_NAME', src, depend = [''], CPPPATH = CPPPATH)
  16. Return('group')
  17. '''
  18. SConscript_bridge = '''# RT-Thread building script for bridge
  19. import os
  20. cwd = GetCurrentDir()
  21. objs = []
  22. list = os.listdir(cwd)
  23. for d in list:
  24. path = os.path.join(cwd, d)
  25. if os.path.isfile(os.path.join(path, 'SConscript')):
  26. objs = objs + SConscript(os.path.join(d, 'SConscript'))
  27. Return('objs')
  28. '''
  29. def usage():
  30. print 'wizard --component name'
  31. print 'wizard --bridge'
  32. def gen_component(name):
  33. print 'generate SConscript for ' + name
  34. text = SConscript_com.replace('COMPONENT_NAME', name)
  35. f = file('SConscript', 'w')
  36. f.write(text)
  37. f.close()
  38. def gen_bridge():
  39. print 'generate SConscript for bridge'
  40. f = file('SConscript', 'w')
  41. f.write(SConscript_bridge)
  42. f.close()
  43. if __name__ == '__main__':
  44. if len(sys.argv) == 1:
  45. usage()
  46. sys.exit(2)
  47. if sys.argv[1] == '--component':
  48. gen_component(sys.argv[2])
  49. elif sys.argv[1] == '--bridge':
  50. gen_bridge()
  51. else:
  52. usage()