OSDN Git Service

new repo
[bytom/vapor.git] / vendor / google.golang.org / genproto / regen.sh
1 #!/bin/bash
2 #
3 # Copyright 2016 Google Inc.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # This script rebuilds the generated code for the protocol buffers.
18 # To run this you will need protoc and goprotobuf installed;
19 # see https://github.com/golang/protobuf for instructions.
20 # You also need Go and Git installed.
21
22 set -e
23
24 PKG=google.golang.org/genproto
25 PROTO_REPO=https://github.com/google/protobuf
26 PROTO_SUBDIR=src/google/protobuf
27 API_REPO=https://github.com/googleapis/googleapis
28
29 function die() {
30   echo 1>&2 $*
31   exit 1
32 }
33
34 # Sanity check that the right tools are accessible.
35 for tool in go git protoc protoc-gen-go; do
36   q=$(which $tool) || die "didn't find $tool"
37   echo 1>&2 "$tool: $q"
38 done
39
40 root=$(go list -f '{{.Root}}' $PKG/... | head -n1)
41 if [ -z "$root" ]; then
42   die "cannot find root of $PKG"
43 fi
44
45 remove_dirs=
46 trap 'rm -rf $remove_dirs' EXIT
47
48 if [ -z "$PROTOBUF" ]; then
49   proto_repo_dir=$(mktemp -d -t regen-cds-proto.XXXXXX)
50   git clone -q $PROTO_REPO $proto_repo_dir &
51   remove_dirs="$proto_repo_dir"
52   # The protoc include directory is actually the "src" directory of the repo.
53   protodir="$proto_repo_dir/src"
54 else
55   protodir="$PROTOBUF/src"
56 fi
57
58 if [ -z "$GOOGLEAPIS" ]; then
59   apidir=$(mktemp -d -t regen-cds-api.XXXXXX)
60   git clone -q $API_REPO $apidir &
61   remove_dirs="$remove_dirs $apidir"
62 else
63   apidir="$GOOGLEAPIS"
64 fi
65
66 wait
67
68 # Nuke everything, we'll generate them back
69 rm -r googleapis/ protobuf/
70
71 go run regen.go -go_out "$root/src" -pkg_prefix "$PKG" "$apidir" "$protodir"
72
73 # Sanity check the build.
74 echo 1>&2 "Checking that the libraries build..."
75 go build -v ./...
76
77 echo 1>&2 "All done!"