github.com/microsoft/moc@v0.17.1/gen.sh (about) 1 #!/bin/bash 2 # Copyright (c) Microsoft Corporation. 3 # Licensed under the Apache v2.0 license. 4 5 # Script that handles regenerating protobuf files. 6 7 # Make sure the script exits on first failure and returns the 8 # proper exit code to the shell. 9 set -e 10 11 while getopts "c" flag 12 do 13 case "${flag}" in 14 c) checkGeneratedFiles=1;; 15 esac 16 done 17 18 # Get script's directory. 19 SCRIPT=$(readlink -f "$0") 20 SCRIPTPATH=$(dirname "$SCRIPT") 21 cd $SCRIPTPATH 22 23 # Create directory for build files. 24 mkdir -p ./bld/gen 25 26 PROTOC_VER=3.11.4 27 PROTOC_FILE=protoc-$PROTOC_VER-linux-x86_64.zip 28 PROTOC_FILE_PATH=bld/$PROTOC_FILE 29 30 # Check if protoc tool has already been downloaded. 31 if [ ! -f $PROTOC_FILE_PATH ]; then 32 # Download protoc tool. 33 (cd bld && curl -OL https://github.com/google/protobuf/releases/download/v$PROTOC_VER/$PROTOC_FILE) 34 fi 35 36 # Unzip protoc tool. 37 unzip -o $PROTOC_FILE_PATH -d bld/protoc 38 39 GOPATH=$(go env GOPATH) 40 41 ( 42 export PATH=$GOPATH/bin:$SCRIPTPATH/bld/protoc/bin:$SCRIPTPATH/bld/protoc/include:$PATH 43 44 # Generate the .go files from the .proto files. 45 cd rpc 46 /bin/bash ./gen_proto.sh 47 ) 48 49 # Copy generated .go files into repo. 50 cp -rf ./bld/gen/github.com/microsoft/moc/rpc/* rpc/ 51 52 # Cleanup. 53 rm -rf ./bld/gen/ 54 go mod tidy 55 56 if [[ $checkGeneratedFiles ]]; then 57 # Check if any files have changed. 58 changed=$(git status --short) 59 if [[ $changed ]]; then 60 # Report warning. 61 printf "\n\n##vso[task.logissue type=warning]Generated files are different:\n\n" 62 63 # Log the diff. 64 git --no-pager diff 65 fi 66 fi