cscope.py 973 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import os
  2. def _get_src(project):
  3. li = []
  4. for group in project:
  5. for f in group['src']:
  6. li.append(os.path.normpath(f.rfile().abspath))
  7. return li
  8. def _get_header_dir(dirp):
  9. li = []
  10. for root, dirs, files in os.walk(dirp):
  11. for d in dirs:
  12. fpath = os.path.join(root, d)
  13. li.extend(_get_header_dir(fpath))
  14. for f in files:
  15. if f[-2:] == '.h':
  16. fpath = os.path.join(root, f)
  17. li.append(os.path.normpath(fpath))
  18. return li
  19. def _get_header(project):
  20. li = []
  21. for g in project:
  22. for d in g.get('CPPPATH', []):
  23. li.extend(_get_header_dir(d))
  24. return li
  25. def CscopeDatabase(project):
  26. files = set(_get_src(project) + _get_header(project))
  27. with open('cscope.files', 'w') as db:
  28. db.write('-k\n-q\n')
  29. db.write('\n'.join(files))
  30. db.flush() # let cscope see the full content
  31. os.system('cscope -b')