blob: 26b6cc930ea7aa24b1bfee341eedc86eed4361c7 [file] [log] [blame]
Austin Schuh40c16522018-10-28 20:27:54 -07001#!/bin/bash
2
3if [ $# -ne 2 ]; then
4 cat <<EOF
5Usage: $0 <TARGET> <VERSION_NUMBER>
6
7TARGET: protoc | protoc-gen-javalite
8
9Example:
10 $ $0 protoc 3.0.0
11 $ $0 protoc-gen-javalite 3.0.0
12
13This script will download pre-built protoc or protoc plugin binaries from maven
14repository and create .zip packages suitable to be included in the github
15release page. If the target is protoc, well-known type .proto files will also be
16included. Each invocation will create 7 zip packages:
17 dist/<TARGET>-<VERSION_NUMBER>-win32.zip
18 dist/<TARGET>-<VERSION_NUMBER>-osx-x86_32.zip
19 dist/<TARGET>-<VERSION_NUMBER>-osx-x86_64.zip
20 dist/<TARGET>-<VERSION_NUMBER>-linux-x86_32.zip
21 dist/<TARGET>-<VERSION_NUMBER>-linux-x86_64.zip
22 dist/<TARGET>-<VERSION_NUMBER>-linux-aarch_64.zip
23 dist/<TARGET>-<VERSION_NUMBER>-linux-ppcle_64.zip
24EOF
25 exit 1
26fi
27
28TARGET=$1
29VERSION_NUMBER=$2
30
31# <zip file name> <binary file name> pairs.
32declare -a FILE_NAMES=( \
33 win32.zip windows-x86_32.exe \
34 osx-x86_32.zip osx-x86_32.exe \
35 osx-x86_64.zip osx-x86_64.exe \
36 linux-x86_32.zip linux-x86_32.exe \
37 linux-x86_64.zip linux-x86_64.exe \
38 linux-aarch_64.zip linux-aarch_64.exe \
39 linux-ppcle_64.zip linux-ppcle_64.exe \
40)
41
42# List of all well-known types to be included.
43declare -a WELL_KNOWN_TYPES=( \
44 google/protobuf/descriptor.proto \
45 google/protobuf/any.proto \
46 google/protobuf/api.proto \
47 google/protobuf/duration.proto \
48 google/protobuf/empty.proto \
49 google/protobuf/field_mask.proto \
50 google/protobuf/source_context.proto \
51 google/protobuf/struct.proto \
52 google/protobuf/timestamp.proto \
53 google/protobuf/type.proto \
54 google/protobuf/wrappers.proto \
55 google/protobuf/compiler/plugin.proto \
56)
57
58set -e
59
60# A temporary working directory to put all files.
61DIR=$(mktemp -d)
62
63# Copy over well-known types.
64mkdir -p ${DIR}/include/google/protobuf/compiler
65for PROTO in ${WELL_KNOWN_TYPES[@]}; do
66 cp -f ../src/${PROTO} ${DIR}/include/${PROTO}
67done
68
69# Create a readme file.
70cat <<EOF > ${DIR}/readme.txt
71Protocol Buffers - Google's data interchange format
72Copyright 2008 Google Inc.
73https://developers.google.com/protocol-buffers/
74
75This package contains a precompiled binary version of the protocol buffer
76compiler (protoc). This binary is intended for users who want to use Protocol
77Buffers in languages other than C++ but do not want to compile protoc
78themselves. To install, simply place this binary somewhere in your PATH.
79
80If you intend to use the included well known types then don't forget to
81copy the contents of the 'include' directory somewhere as well, for example
82into '/usr/local/include/'.
83
84Please refer to our official github site for more installation instructions:
85 https://github.com/google/protobuf
86EOF
87
88mkdir -p dist
89mkdir -p ${DIR}/bin
90# Create a zip file for each binary.
91for((i=0;i<${#FILE_NAMES[@]};i+=2));do
92 ZIP_NAME=${FILE_NAMES[$i]}
93 if [ ${ZIP_NAME:0:3} = "win" ]; then
94 BINARY="$TARGET.exe"
95 else
96 BINARY="$TARGET"
97 fi
98 BINARY_NAME=${FILE_NAMES[$(($i+1))]}
99 BINARY_URL=http://repo1.maven.org/maven2/com/google/protobuf/$TARGET/${VERSION_NUMBER}/$TARGET-${VERSION_NUMBER}-${BINARY_NAME}
100 if ! wget ${BINARY_URL} -O ${DIR}/bin/$BINARY &> /dev/null; then
101 echo "[ERROR] Failed to download ${BINARY_URL}" >&2
102 echo "[ERROR] Skipped $TARGET-${VERSION_NAME}-${ZIP_NAME}" >&2
103 continue
104 fi
105 TARGET_ZIP_FILE=`pwd`/dist/$TARGET-${VERSION_NUMBER}-${ZIP_NAME}
106 pushd $DIR &> /dev/null
107 chmod +x bin/$BINARY
108 if [ "$TARGET" = "protoc" ]; then
109 zip -r ${TARGET_ZIP_FILE} include bin readme.txt &> /dev/null
110 else
111 zip -r ${TARGET_ZIP_FILE} bin &> /dev/null
112 fi
113 rm bin/$BINARY
114 popd &> /dev/null
115 echo "[INFO] Successfully created ${TARGET_ZIP_FILE}"
116done