github.com/GoogleCloudPlatform/testgrid@v0.0.174/hack/update-protos.sh (about) 1 #!/usr/bin/env bash 2 # Copyright 2019 The Kubernetes Authors. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 17 set -o errexit 18 set -o nounset 19 set -o pipefail 20 21 if [[ -n "${BUILD_WORKSPACE_DIRECTORY:-}" ]]; then # Running inside bazel 22 echo "Updating protos..." >&2 23 else 24 bazel=$(command -v bazelisk || command -v bazel || true) 25 if [[ -z "$bazel" ]]; then 26 echo "Install bazel at https://bazel.build" >&2 27 exit 1 28 fi 29 ( 30 set -o xtrace 31 "$bazel" run //hack:update-protos 32 ) 33 exit 0 34 fi 35 36 protoc=$1 37 plugin=$2 38 boiler=$3 39 grpc=$4 40 importmap=$5 41 dest=$BUILD_WORKSPACE_DIRECTORY 42 43 if [[ -z "${_virtual_imports:-}" ]]; then 44 export _virtual_imports="$0.runfiles/com_google_protobuf/_virtual_imports" 45 fi 46 47 genproto() { 48 dir=$(dirname "$1") 49 base=$(basename "$1") 50 out=$dest/github.com/GoogleCloudPlatform/testgrid/$dir/${base%.proto}.pb.go 51 final=$dest/$dir/${base%.proto}.pb.go 52 rm -f "$final" "$out" # mac will complain otherwise 53 ( 54 # TODO(fejta): this _virtual_imports piece is super fragile 55 # Add any extra well-known imports to data and then add a new path 56 "$protoc" \ 57 "--plugin=$plugin" \ 58 "--proto_path=$dir" \ 59 "--proto_path=$dest" \ 60 "--proto_path=$_virtual_imports/timestamp_proto" \ 61 "--go_out=${grpc},${importmap}:$dest" \ 62 "$1" 63 ) 64 tmp=$(mktemp) 65 mv "$out" "$tmp" 66 cat "$boiler" "$tmp" > "$final" 67 } 68 69 echo -n "Generating protos: " >&2 70 for p in $(find . -not '(' -path './vendor' -o -path './node_modules' -o -path './external' -prune ')' -name '*.proto'); do 71 echo -n "$p " 72 genproto "$p" 73 done 74 echo 75