meson_update_sources.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python3
  2. from os import walk
  3. from outpututils import rewriteIfChanged
  4. def scanSources(baseDir):
  5. files = []
  6. dirs = []
  7. for dirPath, dirNames, fileNames in walk(baseDir):
  8. assert dirPath.startswith(baseDir)
  9. prefix = dirPath[len(baseDir):]
  10. if prefix:
  11. if not (prefix == 'unittest' or prefix.endswith('__pycache__')):
  12. dirs.append(prefix)
  13. prefix += '/'
  14. else:
  15. dirs.append('.')
  16. files += (
  17. prefix + name
  18. for name in fileNames
  19. if name.endswith('.cc')
  20. )
  21. return files, dirs
  22. def mesonSources():
  23. files, dirs = scanSources('src/')
  24. testSources = []
  25. yield "sources = files("
  26. for name in sorted(files):
  27. if name.startswith('unittest/'):
  28. testSources.append(name)
  29. elif not (name == 'main.cc'
  30. or name.endswith('Test.cc')
  31. or name.endswith('_test.cc')
  32. ):
  33. yield " '%s'," % name
  34. yield " )"
  35. yield ""
  36. yield "main_sources = files("
  37. yield " 'main.cc',"
  38. yield " )"
  39. yield ""
  40. yield "test_sources = files("
  41. for name in testSources:
  42. yield " '%s'," % name
  43. yield " )"
  44. yield ""
  45. yield "incdirs = include_directories("
  46. for name in dirs:
  47. yield " '%s'," % name
  48. yield " )"
  49. if __name__ == '__main__':
  50. rewriteIfChanged('src/meson.build', mesonSources())