cpp_flatc_wrapper.py 820 B

123456789101112131415161718192021222324252627282930
  1. import os
  2. import subprocess
  3. import sys
  4. def main():
  5. cmd = sys.argv[1:]
  6. h_file = None
  7. try:
  8. index = cmd.index('-o')
  9. h_file = cmd[index + 1]
  10. cmd[index + 1] = os.path.dirname(h_file)
  11. except (ValueError, IndexError):
  12. pass
  13. p = subprocess.run(cmd, capture_output=True, text=True)
  14. if p.returncode:
  15. if p.stdout:
  16. sys.stderr.write('stdout:\n{}\n'.format(p.stdout))
  17. if p.stderr:
  18. sys.stderr.write('stderr:\n{}\n'.format(p.stderr))
  19. sys.exit(p.returncode)
  20. if h_file and h_file.endswith(('.fbs.h', '.fbs64.h')):
  21. cpp_file = '{}.cpp'.format(h_file[:-2])
  22. with open(cpp_file, 'w') as f:
  23. f.write('#include "{}"\n'.format(os.path.basename(h_file)))
  24. sys.exit(0)
  25. if __name__ == '__main__':
  26. main()