build 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python
  2. import os
  3. import argparse
  4. def main():
  5. parser = argparse.ArgumentParser()
  6. parser.add_argument('-g', '--golang', help='build proto to golang output', action='store_true')
  7. parser.add_argument('-p', '--python', help='build proto to python output', action='store_true')
  8. parser.add_argument('-c', '--clean', help='clean build outputs', action='store_true')
  9. args = parser.parse_args()
  10. if not args.golang and not args.python and not args.clean:
  11. args.golang = True
  12. cleaned = []
  13. for cur, dirs, files in os.walk('.'):
  14. if cur[2:8] == 'google':
  15. continue
  16. if cur[2:6] == '.git':
  17. continue
  18. for file in files:
  19. f, ext = os.path.splitext(file)
  20. if ext != '.proto':
  21. continue
  22. if args.golang:
  23. print('building ', file, ' golang ...')
  24. os.system('protoc -I. --go_opt=paths=source_relative --go_out=. {}'.format(os.path.join(cur,file)))
  25. if file[:3] == 'rpc':
  26. os.system('protoc -I. --go-grpc_opt=paths=source_relative --go-grpc_out=. {}'.format(os.path.join(cur, file)))
  27. if args.python:
  28. print('building ', file, ' python ...')
  29. os.system('protoc -I. --python_out=. {}'.format(os.path.join(cur, file)))
  30. if args.clean and cur not in cleaned:
  31. print('removing ', cur, '...')
  32. os.system('rm {0}/*.pb.go {0}/*_pb2.py'.format(cur))
  33. cleaned.append(cur)
  34. if args.golang or args.python:
  35. print('done. check if any errors.')
  36. if __name__ == '__main__':
  37. main()