cpp_flatc_wrapper.py 857 B

12345678910111213141516171819202122232425262728293031
  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.Popen(cmd, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  14. out, err = p.communicate()
  15. if p.returncode:
  16. if out:
  17. sys.stderr.write('stdout:\n{}\n'.format(out))
  18. if err:
  19. sys.stderr.write('stderr:\n{}\n'.format(err))
  20. sys.exit(p.returncode)
  21. if h_file and h_file.endswith(('.fbs.h', '.fbs64.h')):
  22. cpp_file = '{}.cpp'.format(h_file[:-2])
  23. with open(cpp_file, 'w') as f:
  24. f.write('#include "{}"\n'.format(os.path.basename(h_file)))
  25. sys.exit(0)
  26. if __name__ == '__main__':
  27. main()