protoc 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python3
  2. import sys
  3. import os
  4. import os.path
  5. from nanopb_generator import invoke_protoc
  6. if __name__ == '__main__':
  7. # Add argument so that protoc-gen-nanopb gets found
  8. print("Getting path to protoc-gen-nanopb")
  9. if getattr(sys, 'frozen', False):
  10. mypath = os.path.dirname(sys.executable) # For pyInstaller
  11. else:
  12. mypath = os.path.dirname(__file__)
  13. print("Looking for executable file name")
  14. if os.path.isfile(os.path.join(mypath, "protoc-gen-nanopb.exe")):
  15. protoc_gen_nanopb = os.path.join(mypath, "protoc-gen-nanopb.exe")
  16. elif os.name == 'nt':
  17. protoc_gen_nanopb = os.path.join(mypath, "protoc-gen-nanopb.bat")
  18. else:
  19. protoc_gen_nanopb = os.path.join(mypath, "protoc-gen-nanopb")
  20. print("Found executable file name: " + protoc_gen_nanopb)
  21. args = sys.argv[1:]
  22. if os.path.isfile(protoc_gen_nanopb):
  23. args = ['--plugin=protoc-gen-nanopb=%s' % protoc_gen_nanopb] + args
  24. # print the command line that we are about to execute
  25. print("invoking protoc with parameters: ".join(args))
  26. status = invoke_protoc(['protoc'] + args)
  27. sys.exit(status)