Skip to content

Commit af6bc49

Browse files
committed
Improve regenerate.sh to use the correct proto compiler version
1 parent b78c0eb commit af6bc49

File tree

2 files changed

+80
-15
lines changed

2 files changed

+80
-15
lines changed

regenerate.sh

Lines changed: 79 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,94 @@ trap finish EXIT
2424

2525
export GOBIN=${WORKDIR}/bin
2626
export PATH=${GOBIN}:${PATH}
27-
mkdir -p ${GOBIN}
27+
mkdir -p "${GOBIN}"
2828

2929
echo "remove existing generated files"
3030
# grpc_testing_not_regenerate/*.pb.go is not re-generated,
3131
# see grpc_testing_not_regenerate/README.md for details.
32-
rm -f $(find . -name '*.pb.go' | grep -v 'grpc_testing_not_regenerate')
32+
find . -name '*.pb.go' | grep -v 'grpc_testing_not_regenerate' | xargs rm -f
3333

3434
echo "go install google.golang.org/protobuf/cmd/protoc-gen-go"
3535
(cd test/tools && go install google.golang.org/protobuf/cmd/protoc-gen-go)
3636

37-
echo "go install cmd/protoc-gen-go-grpc"
38-
(cd cmd/protoc-gen-go-grpc && go install .)
37+
echo "go install cmd/protoc-gen-go-grpc"
38+
(cd cmd/protoc-gen-go-grpc && go install .)
39+
40+
echo "git clone https://github.com/grpc/grpc-proto"
41+
git clone --quiet https://github.com/grpc/grpc-proto "${WORKDIR}"/grpc-proto
42+
43+
echo "git clone https://github.com/protocolbuffers/protobuf"
44+
git clone --quiet https://github.com/protocolbuffers/protobuf "${WORKDIR}"/protobuf
45+
46+
# Pull in code.proto as a proto dependency
47+
mkdir -p "${WORKDIR}"/googleapis/google/rpc
48+
echo "curl https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/code.proto"
49+
curl --silent https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/code.proto > "${WORKDIR}"/googleapis/google/rpc/code.proto
50+
51+
# Install protoc
52+
echo "Install protoc"
53+
. ./vet.sh # Source vet.sh to access its environment variables
54+
PROTOC_VERSION=${PROTOBUF_VERSION}
55+
echo "Protobuf version: ${PROTOC_VERSION}"
56+
# Function to download for macOS using Homebrew
57+
download_macos() {
58+
echo "Attempting to install libprotoc ${PROTOC_VERSION} using Homebrew (macOS)..."
59+
brew search libprotoc >/dev/null 2>&1 # Check if Homebrew has the formula
60+
if [[ $? -eq 0 ]]; then
61+
brew install protobuf@${PROTOC_VERSION}
62+
if [[ $? -eq 0 ]]; then
63+
echo "libprotoc ${PROTOC_VERSION} successfully installed on macOS"
64+
else
65+
echo "Error installing libprotoc on macOS"
66+
fi
67+
else
68+
echo "Could not find libprotoc ${PROTOC_VERSION} formula in Homebrew. Please consider manual installation."
69+
fi
70+
}
71+
72+
# Function to download pre-built binaries for Linux
73+
download_linux() {
74+
echo "Attempting to download pre-built libprotoc ${PROTOC_VERSION} binary (Linux)..."
75+
76+
# Determine architecture
77+
if [[ $(uname -m) == "x86_64" ]]; then
78+
ARCH="x86_64"
79+
elif [[ $(uname -m) == "aarch64" ]]; then
80+
ARCH="aarch_64"
81+
else
82+
echo "Unsupported architecture. Please consider manual installation."
83+
return
84+
fi
85+
86+
# Download URL (adjust if a newer release is available)
87+
DOWNLOAD_URL="https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-$ARCH.zip"
88+
89+
echo "Download URL: ${DOWNLOAD_URL}"
90+
91+
# Download and unzip
92+
curl -LO $DOWNLOAD_URL
93+
echo "Downloaded"
94+
unzip "protoc-${PROTOC_VERSION}-linux-$ARCH.zip" -d ${WORKDIR}
95+
echo "libprotoc ${PROTOC_VERSION} installed in ${WORKDIR} (Linux)"
96+
export PATH="$PATH:$GOBIN"
97+
}
3998

40-
echo "git clone https://github.com/grpc/grpc-proto"
41-
git clone --quiet https://github.com/grpc/grpc-proto ${WORKDIR}/grpc-proto
99+
# Detect the Operating System
100+
OS=$(uname -s)
42101

43-
echo "git clone https://github.com/protocolbuffers/protobuf"
44-
git clone --quiet https://github.com/protocolbuffers/protobuf ${WORKDIR}/protobuf
102+
case $OS in
103+
"Darwin") download_macos ;;
104+
"Linux") download_linux ;;
105+
*) echo "Unsupported operating system. Please consider manual installation." ;;
106+
esac
45107

46-
# Pull in code.proto as a proto dependency
47-
mkdir -p ${WORKDIR}/googleapis/google/rpc
48-
echo "curl https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/code.proto"
49-
curl --silent https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/code.proto > ${WORKDIR}/googleapis/google/rpc/code.proto
108+
PROTOC_PATH="/usr/local/bin"
109+
if [[ ":$PATH:" != *":$PROTOC_PATH:"* ]]; then
110+
export PATH="$PATH:$PROTOC_PATH"
111+
echo "protoc added to your PATH. You might need to open a new terminal"
112+
else
113+
echo "protoc already appears to be on your PATH"
114+
fi
50115

51116
mkdir -p ${WORKDIR}/out
52117

@@ -93,7 +158,7 @@ Mgrpc/testing/empty.proto=google.golang.org/grpc/interop/grpc_testing
93158

94159
for src in ${SOURCES[@]}; do
95160
echo "protoc ${src}"
96-
protoc --go_out=${OPTS}:${WORKDIR}/out --go-grpc_out=${OPTS}:${WORKDIR}/out \
161+
protoc --go_out=${OPTS}:"${WORKDIR}"/out --go-grpc_out=${OPTS}:${WORKDIR}/out \
97162
-I"." \
98163
-I${WORKDIR}/grpc-proto \
99164
-I${WORKDIR}/googleapis \
@@ -103,7 +168,7 @@ done
103168

104169
for src in ${LEGACY_SOURCES[@]}; do
105170
echo "protoc ${src}"
106-
protoc --go_out=${OPTS}:${WORKDIR}/out --go-grpc_out=${OPTS},require_unimplemented_servers=false:${WORKDIR}/out \
171+
protoc --go_out=${OPTS}:"${WORKDIR}"/out --go-grpc_out=${OPTS},require_unimplemented_servers=false:${WORKDIR}/out \
107172
-I"." \
108173
-I${WORKDIR}/grpc-proto \
109174
-I${WORKDIR}/googleapis \

vet.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ trap cleanup EXIT
3131
PATH="${HOME}/go/bin:${GOROOT}/bin:${PATH}"
3232
go version
3333

34+
export PROTOBUF_VERSION=25.2 # a.k.a. v4.22.0 in pb.go files.
3435
if [[ "$1" = "-install" ]]; then
3536
# Install the pinned versions as defined in module tools.
3637
pushd ./test/tools
@@ -41,7 +42,6 @@ if [[ "$1" = "-install" ]]; then
4142
popd
4243
if [[ -z "${VET_SKIP_PROTO}" ]]; then
4344
if [[ "${GITHUB_ACTIONS}" = "true" ]]; then
44-
PROTOBUF_VERSION=25.2 # a.k.a. v4.22.0 in pb.go files.
4545
PROTOC_FILENAME=protoc-${PROTOBUF_VERSION}-linux-x86_64.zip
4646
pushd /home/runner/go
4747
wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/${PROTOC_FILENAME}

0 commit comments

Comments
 (0)