You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
988 B

  1. #!/usr/bin/sh
  2. set -eo pipefail
  3. # This script appends the "option go_package" proto option to the file located at $FNAME.
  4. # This option specifies what the package will be named when imported by other packages.
  5. # This option is not directly included in the proto files to allow the files to more easily
  6. # be hosted in github.com/tendermint/spec and shared between other repos.
  7. # If the option is already specified in the file, it will be replaced using the
  8. # arguments passed to this script.
  9. FNAME="${1:?missing required .proto filename}"
  10. MODNAME=$(echo $2| sed 's/\//\\\//g')
  11. PACKAGE="$(dirname $FNAME | sed 's/^\.\/\(.*\)/\1/g' | sed 's/\//\\\//g')"
  12. if [[ ! -z "$3" ]]; then
  13. PACKAGE="$(echo $3 | sed 's/\//\\\//g')"
  14. fi
  15. if ! grep -q 'option\s\+go_package\s\+=\s\+.*;' $FNAME; then
  16. sed -i "s/\(package tendermint.*\)/\1\n\noption go_package = \"$MODNAME\/$PACKAGE\";/g" $FNAME
  17. else
  18. sed -i "s/option\s\+go_package\s\+=\s\+.*;/option go_package = \"$MODNAME\/$PACKAGE\";/g" $FNAME
  19. fi