regen.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash -e
  2. #
  3. # This script fetches and rebuilds the "well-known types" protocol buffers.
  4. # To run this you will need protoc and goprotobuf installed;
  5. # see https://github.com/golang/protobuf for instructions.
  6. # You also need Go and Git installed.
  7. PKG=github.com/golang/protobuf/ptypes
  8. UPSTREAM=https://github.com/google/protobuf
  9. UPSTREAM_SUBDIR=src/google/protobuf
  10. PROTO_FILES=(any duration empty struct timestamp wrappers)
  11. function die() {
  12. echo 1>&2 $*
  13. exit 1
  14. }
  15. # Sanity check that the right tools are accessible.
  16. for tool in go git protoc protoc-gen-go; do
  17. q=$(which $tool) || die "didn't find $tool"
  18. echo 1>&2 "$tool: $q"
  19. done
  20. tmpdir=$(mktemp -d -t regen-wkt.XXXXXX)
  21. trap 'rm -rf $tmpdir' EXIT
  22. echo -n 1>&2 "finding package dir... "
  23. pkgdir=$(go list -f '{{.Dir}}' $PKG)
  24. echo 1>&2 $pkgdir
  25. base=$(echo $pkgdir | sed "s,/$PKG\$,,")
  26. echo 1>&2 "base: $base"
  27. cd "$base"
  28. echo 1>&2 "fetching latest protos... "
  29. git clone -q $UPSTREAM $tmpdir
  30. for file in ${PROTO_FILES[@]}; do
  31. echo 1>&2 "* $file"
  32. protoc --go_out=. -I$tmpdir/src $tmpdir/src/google/protobuf/$file.proto || die
  33. cp $tmpdir/src/google/protobuf/$file.proto $PKG/$file
  34. done
  35. echo 1>&2 "All OK"